FormField.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Identity", null, false);
  3. MWF.xApplication.Selector.FormField = new Class({
  4. Extends: MWF.xApplication.Selector.Identity,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectField,
  9. "fieldType": "",
  10. "values": [],
  11. "application": "",
  12. "include" : [],
  13. "expand": false,
  14. "forceSearchInItem" : true
  15. },
  16. loadSelectItems: function(addToNext){
  17. if (this.options.application){
  18. this.designerAction.listFormField(this.options.application, function(json){
  19. this.fieldData = json.data;
  20. if (this.options.fieldType){
  21. var array = ( json.data[this.options.fieldType] || [] ).concat( this.options.include );
  22. if ( array && array.length ){
  23. array.each(function(data){
  24. data.id = data.name;
  25. var item = this._newItem(data, this, this.itemAreaNode);
  26. this.items.push( item );
  27. }.bind(this));
  28. }
  29. }else{
  30. Object.each(json.data, function(v, k){
  31. var category = this._newItemCategory({"name": k, "data": v}, this, this.itemAreaNode);
  32. }.bind(this));
  33. }
  34. }.bind(this));
  35. }
  36. },
  37. _scrollEvent: function(y){
  38. return true;
  39. },
  40. _getChildrenItemIds: function(){
  41. return null;
  42. },
  43. _newItemCategory: function(data, selector, item, level){
  44. return new MWF.xApplication.Selector.FormField.ItemCategory(data, selector, item, level)
  45. },
  46. _listItemByKey: function(callback, failure, key){
  47. var data = [];
  48. if (this.options.fieldType){
  49. data = this.fieldData[this.options.fieldType];
  50. }else{
  51. Object.each(this.fieldData, function(v, k){
  52. data = (data.length) ? data.concat(v) : v
  53. }.bind(this));
  54. }
  55. var searchData = [];
  56. data.each(function(d){
  57. if (d.name.toLowerCase().indexOf(key.toLowerCase())!==-1) searchData.push(d);
  58. }.bind(this));
  59. if (callback) callback.apply(this, [{"data": searchData}]);
  60. //if (callback) callback({"data": {"name": key, "id": key}});
  61. },
  62. _getItem: function(callback, failure, id, async){
  63. if (callback) callback.apply(this, [{"data": {"name": id, "id":id}}]);
  64. },
  65. _newItemSelected: function(data, selector, item){
  66. return new MWF.xApplication.Selector.FormField.ItemSelected(data, selector, item)
  67. },
  68. _listItemByPinyin: function(callback, failure, key){
  69. this._listItemByKey(callback, failure, key);
  70. },
  71. _newItem: function(data, selector, container, level){
  72. return new MWF.xApplication.Selector.FormField.Item(data, selector, container, level);
  73. }
  74. });
  75. MWF.xApplication.Selector.FormField.Item = new Class({
  76. Extends: MWF.xApplication.Selector.Identity.Item,
  77. _getShowName: function(){
  78. return this.data.name;
  79. },
  80. _setIcon: function(){
  81. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/processicon.png)");
  82. },
  83. checkSelectedSingle: function(){
  84. var selectedItem = this.selector.options.values.filter(function(item, index){
  85. if (typeOf(item)==="object") return (this.data.name === item.name) ;
  86. if (typeOf(item)==="string") return (this.data.name === item);
  87. return false;
  88. }.bind(this));
  89. if (selectedItem.length){
  90. this.selectedSingle();
  91. }
  92. },
  93. checkSelected: function(){
  94. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  95. return item.data.name === this.data.name;
  96. }.bind(this));
  97. if (selectedItem.length){
  98. //selectedItem[0].item = this;
  99. selectedItem[0].addItem(this);
  100. this.selectedItem = selectedItem[0];
  101. this.setSelected();
  102. }
  103. },
  104. loadSubItem: function(){
  105. return false;
  106. // this.children = new Element("div", {
  107. // "styles": this.selector.css.selectorItemCategoryChildrenNode
  108. // }).inject(this.node, "after");
  109. // this.children.setStyle("display", "block");
  110. //// if (!this.selector.options.expand) this.children.setStyle("display", "none");
  111. //
  112. // this.selector.action.listProcess(function(subJson){
  113. // subJson.data.each(function(subData){
  114. // var category = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  115. // }.bind(this));
  116. // }.bind(this), null, this.data.id);
  117. },
  118. getData: function(callback){
  119. if (callback) callback();
  120. },
  121. });
  122. MWF.xApplication.Selector.FormField.ItemSelected = new Class({
  123. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  124. getData: function(callback){
  125. if (callback) callback();
  126. },
  127. _getShowName: function(){
  128. return this.data.name;
  129. },
  130. _setIcon: function(){
  131. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/processicon.png)");
  132. },
  133. check: function(){
  134. if (this.selector.items.length){
  135. var items = this.selector.items.filter(function(item, index){
  136. return item.data.name === this.data.name;
  137. }.bind(this));
  138. this.items = items;
  139. if (items.length){
  140. items.each(function(item){
  141. item.selectedItem = this;
  142. item.setSelected();
  143. }.bind(this));
  144. }
  145. }
  146. }
  147. });
  148. MWF.xApplication.Selector.FormField.ItemCategory = new Class({
  149. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  150. _setIcon: function(){
  151. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  152. },
  153. loadSub: function(callback){
  154. if (!this.loaded){
  155. var subJson = this.selector.fieldData[this.data.name];
  156. //this.selector.action.listProcess(function(subJson){
  157. subJson.each(function(subData){
  158. //subData.applicationName = this.data.name;
  159. //subData.application = this.data.id;
  160. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  161. this.selector.items.push( category );
  162. }.bind(this));
  163. this.loaded = true;
  164. if (callback) callback();
  165. //}.bind(this), null, this.data.id);
  166. }else{
  167. if (callback) callback();
  168. }
  169. },
  170. _hasChild: function(){
  171. var d = this.selector.fieldData[this.data.name];
  172. return (d && d.length);
  173. }
  174. });