Dictionary.js 10 KB

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