FormField.js 6.8 KB

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