Form.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. MWF.xApplication.cms.FormDesigner.Module = MWF.xApplication.cms.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.Form", null, false);
  3. MWF.xDesktop.requireApp("cms.FormDesigner", "Property", null, false);
  4. MWF.xApplication.cms.FormDesigner.Module.Form = MWF.CMSFCForm = new Class({
  5. Extends: MWF.FCForm,
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_cms_FormDesigner/Module/Form/form.html",
  9. "mode": "PC",
  10. "fields": ["Calendar", "Checkbox", "Datagrid", "Datagrid$Title", "Datagrid$Data", "Htmleditor", "Number", "Office", "Orgfield", "Personfield", "Readerfield", "Authorfield", "Radio", "Select", "Textarea", "Textfield"]
  11. },
  12. initialize: function(designer, container, options){
  13. this.setOptions(options);
  14. this.path = "/x_component_process_FormDesigner/Module/Form/";
  15. this.cssPath = "/x_component_process_FormDesigner/Module/Form/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.container = null;
  18. this.form = this;
  19. this.moduleType = "form";
  20. this.moduleList = [];
  21. this.moduleNodeList = [];
  22. this.moduleContainerNodeList = [];
  23. this.moduleElementNodeList = [];
  24. this.moduleComponentNodeList = [];
  25. // this.moduleContainerList = [];
  26. this.dataTemplate = {};
  27. this.designer = designer;
  28. this.container = container;
  29. this.selectedModules = [];
  30. },
  31. loadStylesList: function(callback){
  32. var stylesUrl = "/x_component_cms_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  33. MWF.getJSON(stylesUrl,{
  34. "onSuccess": function(responseJSON){
  35. this.stylesList= responseJSON;
  36. if (callback) callback(this.stylesList);
  37. }.bind(this),
  38. "onRequestFailure": function(){
  39. this.stylesList = {};
  40. if (callback) callback(this.stylesList);
  41. }.bind(this),
  42. "onError": function(){
  43. this.stylesList = {};
  44. if (callback) callback(this.stylesList);
  45. }.bind(this)
  46. }
  47. );
  48. },
  49. loadModule: function(json, dom, parent){
  50. //var classPre = "CMSFC";
  51. //var module = new MWF[classPre+json.type](this);
  52. //module.load(json, dom, parent);
  53. //return module;
  54. if( MWF["CMSFC"+json.type] ){
  55. var module = new MWF["CMSFC"+json.type](this);
  56. module.load(json, dom, parent);
  57. return module;
  58. }else{
  59. var module = new MWF["CMSFCDiv"](this);
  60. module.load(json, dom, parent);
  61. return module;
  62. }
  63. },
  64. createModule: function(className, e){
  65. //var classPre = MWF.CMSFD.RedesignModules.indexOf( className.toLowerCase() ) != -1 ? "CMSFC" : "FC";
  66. var classPre = "CMSFC";
  67. this.getTemplateData(className, function(data){
  68. var moduleData = Object.clone(data);
  69. var newTool = new MWF[classPre+className](this);
  70. newTool.create(moduleData, e);
  71. }.bind(this));
  72. },
  73. getTemplateData: function(className, callback){
  74. if (this.dataTemplate[className]){
  75. if (callback) callback(this.dataTemplate[className]);
  76. }else{
  77. var path = MWF.CMSFD.ResetTemplateModules.indexOf( className.toLowerCase() ) != -1 ? "x_component_cms_FormDesigner" : "x_component_process_FormDesigner";
  78. var templateUrl = "/"+path+"/Module/"+className+"/template.json";
  79. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  80. this.dataTemplate[className] = responseJSON;
  81. if (callback) callback(responseJSON);
  82. }.bind(this));
  83. }
  84. },
  85. showProperty: function(){
  86. if (!this.property){
  87. this.property = new MWF.xApplication.cms.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  88. "path": this.options.propertyPath,
  89. "onPostLoad": function(){
  90. this.property.show();
  91. }.bind(this)
  92. });
  93. this.property.load();
  94. }else{
  95. this.property.show();
  96. }
  97. },
  98. save: function(callback){
  99. this.designer.saveForm();
  100. //this._getFormData();
  101. //this.designer.actions.saveForm(this.data, function(responseJSON){
  102. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  103. //
  104. // //this.json.id = responseJSON.data;
  105. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  106. // this.treeNode.setTitle(this.json.id);
  107. // this.node.set("id", this.json.id);
  108. //
  109. // if (callback) callback();
  110. // //this.reload(responseJSON.data);
  111. //}.bind(this));
  112. },
  113. preview: function(){
  114. MWF.xDesktop.requireApp("cms.FormDesigner", "Preview", function(){
  115. if (this.options.mode=="Mobile"){
  116. this.previewBox = new MWF.xApplication.cms.FormDesigner.Preview(this, {"size": {"x": "340", "y": 580}});
  117. }else{
  118. this.previewBox = new MWF.xApplication.cms.FormDesigner.Preview(this);
  119. }
  120. this.previewBox.load();
  121. }.bind(this));
  122. }
  123. });