CMSFormField.js 8.1 KB

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