Dictionary.js 12 KB

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