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