Dictionary.js 10 KB

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