CMSFormField.js 8.0 KB

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