Dictionary.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.Dictionary = new Class({
  4. Extends: MWF.xApplication.Selector.Person,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectDictionary,
  9. "values": [],
  10. "names": [],
  11. "appType" : ["process","cms"],
  12. "expand": false,
  13. "forceSearchInItem" : true
  14. },
  15. loadSelectItems: function(addToNext){
  16. var json = {};
  17. this.options.appType.each( function (type) {
  18. var container = new Element("div").inject(this.itemAreaNode);
  19. var action;
  20. if( type === "process" ){
  21. action = o2.Actions.load("x_processplatform_assemble_designer").ApplicationDictAction.listPaging;
  22. }else if( type === "cms" ){
  23. action = o2.Actions.load("x_cms_assemble_control").AppDictDesignAction.listPaging;
  24. }
  25. var json = {};
  26. var array = [];
  27. action(1, 1000, {}, function( dictionaryJson ) {
  28. dictionaryJson.data.each(function (dictionary) {
  29. var appName = dictionary.appName || dictionary.applicationName;
  30. var appId = dictionary.appId || dictionary.application;
  31. var appAlias = dictionary.appAlias || dictionary.applicationAlias;
  32. if (!json[appId]) {
  33. json[appId] = {
  34. name: appName,
  35. applicationName: appName,
  36. appName: appName,
  37. appAlias: appAlias,
  38. application: appId,
  39. appId: appId
  40. };
  41. json[appId].dictionaryList = [];
  42. }
  43. dictionary.appName = appName;
  44. dictionary.appId = appId;
  45. dictionary.appAlias = appAlias;
  46. dictionary.appType = type;
  47. dictionary.type = "dictionary";
  48. json[appId].dictionaryList.push(dictionary)
  49. }.bind(this));
  50. for (var application in json) {
  51. if (json[application].dictionaryList && json[application].dictionaryList.length) {
  52. json[application].dictionaryList.sort(function (a, b) {
  53. return (a.name||"").localeCompare((b.name||""));
  54. });
  55. array.push(json[application]);
  56. }
  57. }
  58. array.sort( function (a, b) {
  59. return (a.name||"").localeCompare((b.name||""));
  60. });
  61. if( this.options.appType.length === 1 ){
  62. array.each( function (data) {
  63. var category = this._newItemCategory(data, this, container);
  64. }.bind(this))
  65. }else{
  66. var category = this._newItemCategory({
  67. name: MWF.xApplication.Selector.LP.appType[type],
  68. id: type,
  69. applicationList: array
  70. }, this, container);
  71. }
  72. }.bind(this))
  73. }.bind(this));
  74. },
  75. _scrollEvent: function(y){
  76. return true;
  77. },
  78. _getChildrenItemIds: function(data){
  79. return data.dictionaryList || [];
  80. },
  81. _newItemCategory: function(data, selector, item, level){
  82. return new MWF.xApplication.Selector.Dictionary.ItemCategory(data, selector, item, level)
  83. },
  84. _listItemByKey: function(callback, failure, key){
  85. return false;
  86. },
  87. _getItem: function(callback, failure, id, async){
  88. this.queryAction.getTable(function(json){
  89. if (callback) callback.apply(this, [json]);
  90. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  91. },
  92. _newItemSelected: function(data, selector, item){
  93. return new MWF.xApplication.Selector.Dictionary.ItemSelected(data, selector, item)
  94. },
  95. _listItemByPinyin: function(callback, failure, key){
  96. return false;
  97. },
  98. _newItem: function(data, selector, container, level){
  99. return new MWF.xApplication.Selector.Dictionary.Item(data, selector, container, level);
  100. }
  101. });
  102. MWF.xApplication.Selector.Dictionary.Item = new Class({
  103. Extends: MWF.xApplication.Selector.Person.Item,
  104. _getShowName: function(){
  105. return this.data.name;
  106. },
  107. _setIcon: function(){
  108. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  109. },
  110. loadSubItem: function(){
  111. return false;
  112. },
  113. checkSelectedSingle: function(){
  114. var selectedItem = this.selector.options.values.filter(function(item, index){
  115. if (typeOf(item)==="object"){
  116. if( this.data.id && item.id ){
  117. return this.data.id === item.id;
  118. }
  119. //return (this.data.id === item.id) || (this.data.name === item.name) ;
  120. }
  121. //if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  122. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  123. return false;
  124. }.bind(this));
  125. if (selectedItem.length){
  126. this.selectedSingle();
  127. }
  128. },
  129. checkSelected: function(){
  130. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  131. if( item.data.id && this.data.id){
  132. return item.data.id === this.data.id;
  133. }
  134. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  135. }.bind(this));
  136. if (selectedItem.length){
  137. //selectedItem[0].item = this;
  138. selectedItem[0].addItem(this);
  139. this.selectedItem = selectedItem[0];
  140. this.setSelected();
  141. }
  142. }
  143. });
  144. MWF.xApplication.Selector.Dictionary.ItemSelected = new Class({
  145. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  146. _getShowName: function(){
  147. return this.data.name;
  148. },
  149. _setIcon: function(){
  150. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  151. },
  152. check: function(){
  153. if (this.selector.items.length){
  154. var items = this.selector.items.filter(function(item, index){
  155. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  156. if( item.data.id && this.data.id){
  157. return item.data.id === this.data.id;
  158. }
  159. }.bind(this));
  160. this.items = items;
  161. if (items.length){
  162. items.each(function(item){
  163. item.selectedItem = this;
  164. item.setSelected();
  165. }.bind(this));
  166. }
  167. }
  168. }
  169. });
  170. MWF.xApplication.Selector.Dictionary.ItemCategory = new Class({
  171. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  172. clickItem: function (callback) {
  173. if (this._hasChild() ) {
  174. var firstLoaded = !this.loaded;
  175. this.loadSub(function () {
  176. if (firstLoaded && this._hasChild() ) {
  177. if (!this.selector.isFlatCategory) {
  178. this.children.setStyles({"display": "block", "height": "auto"});
  179. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  180. this.isExpand = true;
  181. }
  182. // this.checkSelectAll();
  183. } else {
  184. var display = this.children.getStyle("display");
  185. if (display === "none") {
  186. // this.selector.fireEvent("expand", [this] );
  187. this.children.setStyles({"display": "block", "height": "auto"});
  188. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  189. this.isExpand = true;
  190. } else {
  191. // this.selector.fireEvent("collapse", [this] );
  192. this.children.setStyles({"display": "none", "height": "0px"});
  193. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  194. this.isExpand = false;
  195. }
  196. }
  197. if (callback) callback();
  198. }.bind(this));
  199. }
  200. },
  201. loadSub: function (callback) {
  202. if (!this.loaded) {
  203. if( this.data.dictionaryList ){
  204. this.data.dictionaryList.each(function (subItem, index) {
  205. var item = this.selector._newItem(subItem, this.selector, this.children, this.level + 1, this);
  206. this.selector.items.push(item);
  207. if(this.subItems)this.subItems.push( item );
  208. }.bind(this));
  209. }
  210. if ( this.data.applicationList ) {
  211. this.data.applicationList.each(function (subCategory, index) {
  212. var category = this.selector._newItemCategory(subCategory, this.selector, this.children, this.level + 1, this);
  213. this.subCategorys.push( category );
  214. }.bind(this));
  215. }
  216. this.loaded = true;
  217. if (callback) callback();
  218. } else {
  219. if (callback) callback();
  220. }
  221. },
  222. _getShowName: function(){
  223. return this.data.name;
  224. },
  225. _getTtiteText: function () {
  226. return this.data.name;
  227. },
  228. createNode: function(){
  229. this.node = new Element("div", {
  230. "styles": this.selector.css.selectorItemCategory_department
  231. }).inject(this.container);
  232. },
  233. _setIcon: function(){
  234. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  235. },
  236. _hasChild: function(){
  237. return ( this.data.dictionaryList && this.data.dictionaryList.length ) ||
  238. ( this.data.applicationList && this.data.applicationList.length);
  239. },
  240. afterLoad: function(){
  241. if ( this._hasChild() ){
  242. this.clickItem();
  243. }
  244. },
  245. check: function(){}
  246. });