FormField.js 7.0 KB

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