Form.js 16 KB

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