CMSFormTemplateSelector.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. MWF.xApplication.cms.ColumnManager = MWF.xApplication.cms.ColumnManager || {};
  2. if( !MWF.xApplication.cms.ColumnManager.LP ){
  3. MWF.requireApp("cms.ColumnManager", "lp."+o2.language, null, false);
  4. }
  5. MWF.xApplication.cms.ColumnManager.CMSFormTemplateSelector = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options:{
  9. "style": "default"
  10. },
  11. initialize: function(app, options){
  12. this.setOptions(options);
  13. this.path = "../x_component_cms_ColumnManager/widget/";
  14. this.cssPath = "../x_component_cms_ColumnManager/widget/$CMSFormTemplateSelector/"+this.options.style+"/css.wcss";
  15. this._loadCss(true);
  16. this.restActions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.ColumnManager.Actions.RestActions()
  17. this.app = app;
  18. this.formTemplateList = null;
  19. this.defalutFormTemplateList = null;
  20. },
  21. load: function(e){
  22. var _self = this;
  23. this.createTemplateMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  24. this.createTemplateAreaNode = new Element("div", {"styles": this.css.createFormTemplateAreaNode}).inject(this.app.content);
  25. this.createTemplateAreaNode.fade("in");
  26. this.createTemplateTitleNode = new Element("div", {"styles": this.css.createTemplateFormTitleNode, "text": this.app.lp.createSelectTemplate}).inject(this.createTemplateAreaNode);
  27. this.createTemplateCategoryCloseNode = new Element("div.createTemplateCategoryCloseNode", {"styles": this.css.createTemplateCategoryCloseNode }).inject(this.createTemplateTitleNode);
  28. this.createTemplateCategoryNode = new Element("div", {"styles": this.css.createTemplateFormCategoryNode}).inject(this.createTemplateAreaNode);
  29. this.createTemplateCategoryTitleNode = new Element("div", {"styles": this.css.createTemplateFormCategoryTitleNode, "text": this.app.lp.templateCategory}).inject(this.createTemplateCategoryNode);
  30. this.createTemplateContentNode = new Element("div", {"styles": this.css.createTemplateFormContentNode}).inject(this.createTemplateAreaNode);
  31. this.createTemplateCategoryAllNode = new Element("div", {"styles": this.css.createTemplateFormCategoryItemNode, "text": this.app.lp.all}).inject(this.createTemplateCategoryNode);
  32. this.createTemplateCategoryAllNode.addEvent("click", function(){
  33. _self.loadAllTemplates();
  34. });
  35. this.restActions.listFormTemplateCategory(function(json){
  36. json.data.each(function(d){
  37. var createTemplateCategoryItemNode = new Element("div", {
  38. "styles": this.css.createTemplateFormCategoryItemNode, "text": d.name+"("+ d.count+")",
  39. "value": d.name
  40. }).inject(this.createTemplateCategoryNode);
  41. createTemplateCategoryItemNode.addEvent("click", function(){
  42. _self.createTemplateContentNode.empty();
  43. _self.createTemplateCategoryNode.getElements("div").each(function(node, i){
  44. if (i>0) node.setStyles(_self.css.createTemplateFormCategoryItemNode);
  45. });
  46. this.setStyles(_self.css.createTemplateFormCategoryItemNode_current);
  47. _self.loadTemplates(this.get("value"));
  48. });
  49. }.bind(this));
  50. }.bind(this));
  51. this.resizeFun = this.resize.bind(this);
  52. this.resizeFun();
  53. this.app.addEvent("resize", this.resizeFun);
  54. this.loadAllTemplates();
  55. this.createTemplateCategoryCloseNode.addEvent("click", function(){
  56. this.app.removeEvent("resize", this.resizeFun);
  57. this.createTemplateAreaNode.destroy();
  58. this.createTemplateMaskNode.destroy();
  59. }.bind(this));
  60. this.createTemplateMaskNode.addEvent("click", function(){
  61. this.app.removeEvent("resize", this.resizeFun);
  62. this.createTemplateAreaNode.destroy();
  63. this.createTemplateMaskNode.destroy();
  64. }.bind(this));
  65. },
  66. resize: function(){
  67. var size = this.app.content.getSize();
  68. var y = (size.y*0.1)/2;
  69. var x = (size.x*0.1)/2;
  70. if (y<0) y=0;
  71. if (x<0) x=0;
  72. this.createTemplateAreaNode.setStyles({
  73. "top": ""+y+"px",
  74. "left": ""+x+"px"
  75. });
  76. y = size.y*0.9-this.createTemplateCategoryNode.getSize().y-70;
  77. this.createTemplateContentNode.setStyle("height", ""+y+"px");
  78. },
  79. loadAllTemplates : function(){
  80. this.createTemplateContentNode.empty();
  81. this.createTemplateCategoryNode.getElements("div").each(function(node, i){
  82. if (i>0) node.setStyles(this.css.createTemplateFormCategoryItemNode);
  83. }.bind(this));
  84. this.createTemplateCategoryAllNode.setStyles(this.css.createTemplateFormCategoryItemNode_current);
  85. this.loadDefaultTemplate();
  86. this.loadTemplates();
  87. },
  88. getDefaultFormTemplateList: function(callback){
  89. if (this.defalutFormTemplateList){
  90. if (callback) callback();
  91. }else{
  92. var url = "../x_component_cms_FormDesigner/Module/Form/template/templates.json";
  93. MWF.getJSON(url, function(json){
  94. this.defalutFormTemplateList = json;
  95. if (callback) callback();
  96. }.bind(this));
  97. }
  98. },
  99. getFormTemplateList: function(callback){
  100. if (this.formTemplateList){
  101. if (callback) callback();
  102. }else{
  103. this.restActions.listFormTemplate(function(json){
  104. this.formTemplateList = json.data;
  105. if (callback) callback();
  106. }.bind(this));
  107. }
  108. },
  109. loadDefaultTemplate: function(){
  110. var _self = this;
  111. this.getDefaultFormTemplateList(function(){
  112. this.defalutFormTemplateList.each(function(template){
  113. var templateNode = new Element("div", {"styles": this.css.formTemplateNode}).inject(_self.createTemplateContentNode);
  114. var templateIconNode = new Element("div", {"styles": this.css.formTemplateIconNode}).inject(templateNode);
  115. var templateTitleNode = new Element("div", {"styles": this.css.formTemplateTitleNode, "text": template.title}).inject(templateNode);
  116. templateNode.store("template", template.name);
  117. templateNode.store("templateTitle", template.title);
  118. var templateIconImgNode = new Element("img", {"styles": this.css.formTemplateIconImgNode}).inject(templateIconNode);
  119. templateIconImgNode.set("src", "../x_component_cms_FormDesigner/Module/Form/template/"+template.icon);
  120. templateNode.addEvents({
  121. "mouseover": function(){this.setStyles(_self.css.formTemplateNode_over)},
  122. "mouseout": function(){this.setStyles(_self.css.formTemplateNode)},
  123. "mousedown": function(){this.setStyles(_self.css.formTemplateNode_down)},
  124. "mouseup": function(){this.setStyles(_self.css.formTemplateNode_over)},
  125. "click": function(e){
  126. debugger;
  127. // createDefaultForm(e, this.retrieve("template"));
  128. _self.fireEvent("selectDefaultForm", [this.retrieve("template"), this.retrieve("templateTitle")]);
  129. _self.app.removeEvent("resize", _self.resizeFun);
  130. _self.createTemplateAreaNode.destroy();
  131. _self.createTemplateMaskNode.destroy();
  132. }
  133. });
  134. }.bind(this))
  135. }.bind(this));
  136. },
  137. loadTemplates: function(category){
  138. var _self = this;
  139. this.getFormTemplateList(function(){
  140. Object.each(this.formTemplateList, function(v, k){
  141. var flag = (category) ? (k==category) : true;
  142. if (flag){
  143. v.each(function(template){
  144. var templateNode = new Element("div", {"styles": this.css.formTemplateNode}).inject(this.createTemplateContentNode);
  145. var templateIconNode = new Element("div", {"styles": this.css.formTemplatePreviewNode}).inject(templateNode);
  146. var templateTitleNode = new Element("div", {"styles": this.css.formTemplateTitleNode, "text": template.name}).inject(templateNode);
  147. templateNode.store("template", template.id);
  148. templateNode.store("templateTitle", template.name);
  149. templateIconNode.set("html", template.outline);
  150. var templateActionNode = new Element("img", {"styles": this.css.formTemplateActionNode}).inject(templateIconNode);
  151. templateActionNode.addEvent("click", function(e){
  152. var thisNode = this.getParent().getParent();
  153. var id = thisNode.retrieve("template");
  154. _self.app.confirm("wram", e, _self.app.lp.form.deleteFormTemplateTitle, _self.app.lp.form.deleteFormTemplate, 300, 120, function(){
  155. _self.restActions.deleteFormTemplate(id, function(json){
  156. //thisNode.destroy();
  157. _self.app.removeEvent("resize", _self.resizeFun);
  158. _self.createTemplateAreaNode.destroy();
  159. _self.createTemplateMaskNode.destroy();
  160. _self.load(e)
  161. }.bind(this));
  162. this.close();
  163. }, function(){
  164. this.close();
  165. });
  166. e.stopPropagation();
  167. });
  168. //templateIconImgNode.set("src", "../x_component_process_FormDesigner/Module/Form/template/"+template.icon);
  169. templateNode.addEvents({
  170. "mouseover": function(){
  171. this.setStyles(_self.css.formTemplateNode_over);
  172. if (templateActionNode) templateActionNode.setStyle("display", "block");
  173. },
  174. "mouseout": function(){
  175. this.setStyles(_self.css.formTemplateNode);
  176. if (templateActionNode) templateActionNode.setStyle("display", "none");
  177. },
  178. "mousedown": function(){this.setStyles(_self.css.formTemplateNode_down)},
  179. "mouseup": function(){this.setStyles(_self.css.formTemplateNode_over)},
  180. "click": function(e){
  181. debugger;
  182. // _self.createForm(e, this.retrieve("template"));
  183. _self.fireEvent("selectForm", [this.retrieve("template"), this.retrieve("templateTitle")]);
  184. _self.app.removeEvent("resize", _self.resizeFun);
  185. _self.createTemplateAreaNode.destroy();
  186. _self.createTemplateMaskNode.destroy();
  187. }
  188. });
  189. }.bind(this));
  190. }
  191. }.bind(this));
  192. }.bind(this));
  193. }
  194. });