FormField.js 6.7 KB

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