Dictionary.js 9.8 KB

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