FormField.js 7.1 KB

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