Form.js 15 KB

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