Form.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. "injectActions" : [
  12. {
  13. "name" : "top",
  14. "styles" : "injectActionTop",
  15. "event" : "click",
  16. "action" : "injectTop",
  17. "title": MWF.APPFD.LP.formAction["insertTop"]
  18. },
  19. {
  20. "name" : "bottom",
  21. "styles" : "injectActionBottom",
  22. "event" : "click",
  23. "action" : "injectBottom",
  24. "title": MWF.APPFD.LP.formAction["insertBottom"]
  25. }
  26. ]
  27. },
  28. initialize: function(designer, container, options){
  29. this.setOptions(options);
  30. this.path = "/x_component_process_FormDesigner/Module/Form/";
  31. this.cssPath = "/x_component_process_FormDesigner/Module/Form/"+this.options.style+"/css.wcss";
  32. this._loadCss();
  33. this.container = null;
  34. this.form = this;
  35. this.moduleType = "form";
  36. this.moduleList = [];
  37. this.moduleNodeList = [];
  38. this.moduleContainerNodeList = [];
  39. this.moduleElementNodeList = [];
  40. this.moduleComponentNodeList = [];
  41. // this.moduleContainerList = [];
  42. this.dataTemplate = {};
  43. this.designer = designer;
  44. this.container = container;
  45. this.selectedModules = [];
  46. },
  47. loadTemplateStyles : function( file, callback ){
  48. if( !file ){
  49. if (callback) callback({});
  50. return;
  51. }
  52. this.templateStylesList = this.templateStylesList || {};
  53. if( this.templateStylesList[file] ){
  54. if (callback) callback(this.templateStylesList[file]);
  55. return;
  56. }
  57. var stylesUrl = "/x_component_cms_FormDesigner/Module/Form/skin/"+file;
  58. MWF.getJSON(stylesUrl,{
  59. "onSuccess": function(responseJSON){
  60. this.templateStylesList[file] = responseJSON;
  61. if (callback) callback(responseJSON);
  62. }.bind(this),
  63. "onRequestFailure": function(){
  64. if (callback) callback({});
  65. }.bind(this),
  66. "onError": function(){
  67. if (callback) callback({});
  68. }.bind(this)
  69. }
  70. );
  71. },
  72. loadStylesList: function(callback){
  73. //var stylesUrl = "/x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "mobileStyles": "styles")+".json";
  74. //var stylesUrl = "/x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  75. var configUrl = "/x_component_cms_FormDesigner/Module/Form/skin/config.json";
  76. MWF.getJSON(configUrl,{
  77. "onSuccess": function(responseJSON){
  78. this.stylesList = responseJSON;
  79. if (callback) callback(this.stylesList);
  80. }.bind(this),
  81. "onRequestFailure": function(){
  82. this.stylesList = {};
  83. if (callback) callback(this.stylesList);
  84. }.bind(this),
  85. "onError": function(){
  86. this.stylesList = {};
  87. if (callback) callback(this.stylesList);
  88. }.bind(this)
  89. }
  90. );
  91. },
  92. //loadStylesList: function(callback){
  93. //var stylesUrl = "/x_component_cms_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  94. //MWF.getJSON(stylesUrl,{
  95. // "onSuccess": function(responseJSON){
  96. // this.stylesList= responseJSON;
  97. // if (callback) callback(this.stylesList);
  98. // }.bind(this),
  99. // "onRequestFailure": function(){
  100. // this.stylesList = {};
  101. // if (callback) callback(this.stylesList);
  102. // }.bind(this),
  103. // "onError": function(){
  104. // this.stylesList = {};
  105. // if (callback) callback(this.stylesList);
  106. // }.bind(this)
  107. // }
  108. //);
  109. //},
  110. loadModule: function(json, dom, parent){
  111. //var classPre = "CMSFC";
  112. //var module = new MWF[classPre+json.type](this);
  113. //module.load(json, dom, parent);
  114. //return module;
  115. if( MWF["CMSFC"+json.type] ){
  116. var module = new MWF["CMSFC"+json.type](this);
  117. module.load(json, dom, parent);
  118. return module;
  119. }else{
  120. var module = new MWF["CMSFCDiv"](this);
  121. module.load(json, dom, parent);
  122. return module;
  123. }
  124. },
  125. createModule: function(className, e){
  126. //var classPre = MWF.CMSFD.RedesignModules.indexOf( className.toLowerCase() ) != -1 ? "CMSFC" : "FC";
  127. var classPre = "CMSFC";
  128. this.getTemplateData(className, function(data){
  129. var moduleData = Object.clone(data);
  130. var newTool = new MWF[classPre+className](this);
  131. newTool.create(moduleData, e);
  132. }.bind(this));
  133. },
  134. getTemplateData: function(className, callback, async){
  135. if (this.dataTemplate[className]){
  136. if (callback) callback(this.dataTemplate[className]);
  137. }else{
  138. var path = MWF.CMSFD.ResetTemplateModules.indexOf( className.toLowerCase() ) != -1 ? "x_component_cms_FormDesigner" : "x_component_process_FormDesigner";
  139. var templateUrl = "/"+path+"/Module/"+className+"/template.json";
  140. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  141. this.dataTemplate[className] = responseJSON;
  142. if (callback) callback(responseJSON);
  143. }.bind(this), async);
  144. }
  145. },
  146. showProperty: function(){
  147. if (!this.property){
  148. this.property = new MWF.xApplication.cms.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  149. "path": this.options.propertyPath,
  150. "onPostLoad": function(){
  151. this.property.show();
  152. }.bind(this)
  153. });
  154. this.property.load();
  155. }else{
  156. this.property.show();
  157. }
  158. },
  159. save: function(callback){
  160. this.designer.saveForm();
  161. //this._getFormData();
  162. //this.designer.actions.saveForm(this.data, function(responseJSON){
  163. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  164. //
  165. // //this.json.id = responseJSON.data;
  166. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  167. // this.treeNode.setTitle(this.json.id);
  168. // this.node.set("id", this.json.id);
  169. //
  170. // if (callback) callback();
  171. // //this.reload(responseJSON.data);
  172. //}.bind(this));
  173. },
  174. implode: function(){
  175. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  176. MWF.CMSFormImport.create("O2", this);
  177. }.bind(this));
  178. },
  179. implodeHTML: function(){
  180. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  181. MWF.CMSFormImport.create("html", this, {"type": "process"});
  182. }.bind(this));
  183. },
  184. implodeOffice: function(){
  185. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  186. MWF.CMSFormImport.create("office", this);
  187. }.bind(this));
  188. },
  189. setPropertiesOrStyles: function(name){
  190. if (name=="styles"){
  191. this.setCustomStyles();
  192. }
  193. if (name=="properties"){
  194. this.node.setProperties(this.json.properties);
  195. }
  196. },
  197. setCustomStyles: function(){
  198. var border = this.node.getStyle("border");
  199. this.node.clearStyles();
  200. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  201. var y = this.container.getStyle("height");
  202. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  203. this.node.setStyle("min-height", ""+y+"px");
  204. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  205. this.node.setStyle("border", border);
  206. Object.each(this.json.styles, function(value, key){
  207. var reg = /^border\w*/ig;
  208. if (!key.test(reg)){
  209. this.node.setStyle(key, value);
  210. }
  211. }.bind(this));
  212. },
  213. //_setEditStyle: function(name, obj, oldValue){
  214. // if (name=="name"){
  215. // var title = this.json.name || this.json.id;
  216. // this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  217. // }
  218. // if (name=="id"){
  219. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  220. // this.treeNode.setTitle(this.json.id);
  221. // this.node.set("id", this.json.id);
  222. // }
  223. // if (name=="formStyleType"){
  224. // this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  225. // if (oldValue) {
  226. // var oldTemplateStyles = this.stylesList[oldValue];
  227. // if (oldTemplateStyles){
  228. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  229. // }
  230. // }
  231. // if (this.templateStyles){
  232. // if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  233. // }
  234. // this.setAllStyles();
  235. //
  236. // this.moduleList.each(function(module){
  237. // if (oldTemplateStyles){
  238. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  239. // }
  240. // module.setStyleTemplate();
  241. // module.setAllStyles();
  242. // }.bind(this));
  243. // }
  244. // if (name==="css"){
  245. // this.reloadCss();
  246. // }
  247. // this._setEditStyle_custom(name, obj, oldValue);
  248. //},
  249. _setEditStyle: function(name, obj, oldValue){
  250. if (name=="name"){
  251. var title = this.json.name || this.json.id;
  252. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  253. }
  254. if (name=="id"){
  255. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  256. this.treeNode.setTitle(this.json.id);
  257. this.node.set("id", this.json.id);
  258. }
  259. if (name=="formStyleType"){
  260. var file = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].file : null;
  261. this.loadTemplateStyles( file, function( templateStyles ){
  262. //this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  263. this.templateStyles = templateStyles;
  264. var oldFile;
  265. if( oldValue && this.stylesList[oldValue] ){
  266. oldFile = this.stylesList[oldValue].file;
  267. }
  268. this.loadTemplateStyles( oldFile, function( oldTemplateStyles ){
  269. //if (oldValue) {
  270. // var oldTemplateStyles = this.stylesList[oldValue];
  271. // if (oldTemplateStyles){
  272. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  273. // }
  274. //}
  275. if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  276. if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  277. this.setAllStyles();
  278. this.moduleList.each(function(module){
  279. if (oldTemplateStyles[module.moduleName]){
  280. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  281. }
  282. module.setStyleTemplate();
  283. module.setAllStyles();
  284. }.bind(this));
  285. }.bind(this))
  286. }.bind(this))
  287. }
  288. if (name==="css"){
  289. this.reloadCss();
  290. }
  291. this._setEditStyle_custom(name, obj, oldValue);
  292. },
  293. parseCSS: function(css){
  294. var rex = /(url\(.*\))/g;
  295. var match;
  296. while ((match = rex.exec(css)) !== null) {
  297. var pic = match[0];
  298. var len = pic.length;
  299. var s = pic.substring(pic.length-2, pic.length-1);
  300. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  301. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  302. pic = pic.substring(n0, pic.length-n1);
  303. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  304. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  305. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  306. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  307. pic = pic.replace("/x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  308. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  309. pic = pic.replace("x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  310. }
  311. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  312. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  313. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  314. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  315. }
  316. }
  317. pic = "url('"+pic+"')";
  318. var len2 = pic.length;
  319. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  320. rex.lastIndex = rex.lastIndex + (len2-len);
  321. }
  322. return css;
  323. },
  324. preview: function(){
  325. MWF.xDesktop.requireApp("cms.FormDesigner", "Preview", function(){
  326. if (this.options.mode=="Mobile"){
  327. this.previewBox = new MWF.xApplication.cms.FormDesigner.Preview(this, {"size": {"x": "340", "y": 580}});
  328. }else{
  329. this.previewBox = new MWF.xApplication.cms.FormDesigner.Preview(this);
  330. }
  331. this.previewBox.load();
  332. }.bind(this));
  333. }
  334. });