Form.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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( MWF["CMSFC"+json.type] ){
  158. var module = new MWF["CMSFC"+json.type](this);
  159. module.load(json, dom, parent);
  160. return module;
  161. }else{
  162. var module = new MWF["CMSFCDiv"](this);
  163. module.load(json, dom, parent);
  164. return module;
  165. }
  166. },
  167. createModule: function(className, e){
  168. //var classPre = MWF.CMSFD.RedesignModules.indexOf( className.toLowerCase() ) != -1 ? "CMSFC" : "FC";
  169. var classPre = "CMSFC";
  170. this.getTemplateData(className, function(data){
  171. var moduleData = Object.clone(data);
  172. var newTool = new MWF[classPre+className](this);
  173. newTool.create(moduleData, e);
  174. }.bind(this));
  175. },
  176. getTemplateData: function(className, callback, async){
  177. if (this.dataTemplate[className]){
  178. if (callback) callback(this.dataTemplate[className]);
  179. }else{
  180. var path = MWF.CMSFD.ResetTemplateModules.indexOf( className.toLowerCase() ) != -1 ? "x_component_cms_FormDesigner" : "x_component_process_FormDesigner";
  181. var templateUrl = "../"+path+"/Module/"+className+"/template.json";
  182. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  183. this.dataTemplate[className] = responseJSON;
  184. if (callback) callback(responseJSON);
  185. }.bind(this), async);
  186. }
  187. },
  188. showProperty: function(){
  189. if (!this.property){
  190. this.property = new MWF.xApplication.cms.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  191. "path": this.options.propertyPath,
  192. "onPostLoad": function(){
  193. this.property.show();
  194. }.bind(this)
  195. });
  196. this.property.load();
  197. }else{
  198. this.property.show();
  199. }
  200. },
  201. save: function(callback){
  202. this.designer.saveForm();
  203. //this._getFormData();
  204. //this.designer.actions.saveForm(this.data, function(responseJSON){
  205. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  206. //
  207. // //this.json.id = responseJSON.data;
  208. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  209. // this.treeNode.setTitle(this.json.id);
  210. // this.node.set("id", this.json.id);
  211. //
  212. // if (callback) callback();
  213. // //this.reload(responseJSON.data);
  214. //}.bind(this));
  215. },
  216. implode: function(){
  217. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  218. MWF.CMSFormImport.create("O2", this);
  219. }.bind(this));
  220. },
  221. implodeHTML: function(){
  222. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  223. MWF.CMSFormImport.create("html", this, {"type": "process"});
  224. }.bind(this));
  225. },
  226. implodeOffice: function(){
  227. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  228. MWF.CMSFormImport.create("office", this);
  229. }.bind(this));
  230. },
  231. setPropertiesOrStyles: function(name){
  232. if (name=="styles"){
  233. this.setCustomStyles();
  234. }
  235. if (name=="properties"){
  236. this.node.setProperties(this.json.properties);
  237. }
  238. },
  239. setCustomStyles: function(){
  240. var border = this.node.getStyle("border");
  241. this.node.clearStyles();
  242. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  243. var y = this.container.getStyle("height");
  244. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  245. this.node.setStyle("min-height", ""+y+"px");
  246. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  247. this.node.setStyle("border", border);
  248. Object.each(this.json.styles, function(value, key){
  249. var reg = /^border\w*/ig;
  250. if (!key.test(reg)){
  251. this.node.setStyle(key, value);
  252. }
  253. }.bind(this));
  254. },
  255. //_setEditStyle: function(name, obj, oldValue){
  256. // if (name=="name"){
  257. // var title = this.json.name || this.json.id;
  258. // this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  259. // }
  260. // if (name=="id"){
  261. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  262. // this.treeNode.setTitle(this.json.id);
  263. // this.node.set("id", this.json.id);
  264. // }
  265. // if (name=="formStyleType"){
  266. // this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  267. // if (oldValue) {
  268. // var oldTemplateStyles = this.stylesList[oldValue];
  269. // if (oldTemplateStyles){
  270. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  271. // }
  272. // }
  273. // if (this.templateStyles){
  274. // if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  275. // }
  276. // this.setAllStyles();
  277. //
  278. // this.moduleList.each(function(module){
  279. // if (oldTemplateStyles){
  280. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  281. // }
  282. // module.setStyleTemplate();
  283. // module.setAllStyles();
  284. // }.bind(this));
  285. // }
  286. // if (name==="css"){
  287. // this.reloadCss();
  288. // }
  289. // this._setEditStyle_custom(name, obj, oldValue);
  290. //},
  291. _setEditStyle: function(name, obj, oldValue){
  292. if (name=="name"){
  293. var title = this.json.name || this.json.id;
  294. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  295. }
  296. if (name=="id"){
  297. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  298. this.treeNode.setTitle(this.json.id);
  299. this.node.set("id", this.json.id);
  300. }
  301. if (name=="formStyleType"){
  302. var file = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].file : null;
  303. var extendFile = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].extendFile : null;
  304. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  305. //this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  306. this.templateStyles = templateStyles;
  307. var oldFile, oldExtendFile;
  308. if( oldValue && this.stylesList[oldValue] ){
  309. oldFile = this.stylesList[oldValue].file;
  310. oldExtendFile = this.stylesList[oldValue].extendFile;
  311. }
  312. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  313. //if (oldValue) {
  314. // var oldTemplateStyles = this.stylesList[oldValue];
  315. // if (oldTemplateStyles){
  316. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  317. // }
  318. //}
  319. this.json.styleConfig = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  320. if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  321. if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  322. this.setAllStyles();
  323. this.moduleList.each(function(module){
  324. if (oldTemplateStyles[module.moduleName]){
  325. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  326. }
  327. module.setStyleTemplate();
  328. module.setAllStyles();
  329. }.bind(this));
  330. }.bind(this))
  331. }.bind(this))
  332. }
  333. if (name==="css"){
  334. this.reloadCss();
  335. }
  336. this._setEditStyle_custom(name, obj, oldValue);
  337. },
  338. parseCSS: function(css){
  339. var rex = /(url\(.*\))/g;
  340. var match;
  341. while ((match = rex.exec(css)) !== null) {
  342. var pic = match[0];
  343. var len = pic.length;
  344. var s = pic.substring(pic.length-2, pic.length-1);
  345. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  346. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  347. pic = pic.substring(n0, pic.length-n1);
  348. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  349. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  350. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  351. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  352. pic = pic.replace("/x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  353. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  354. pic = pic.replace("x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  355. }
  356. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  357. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  358. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  359. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  360. }
  361. }
  362. pic = "url('"+pic+"')";
  363. var len2 = pic.length;
  364. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  365. rex.lastIndex = rex.lastIndex + (len2-len);
  366. }
  367. return css;
  368. },
  369. preview: function(){
  370. MWF.xDesktop.requireApp("cms.FormDesigner", "Preview", function(){
  371. if (this.options.mode=="Mobile"){
  372. this.previewBox = new MWF.xApplication.cms.FormDesigner.Preview(this, {"size": {"x": "340", "y": 580}});
  373. }else{
  374. this.previewBox = new MWF.xApplication.cms.FormDesigner.Preview(this);
  375. }
  376. this.previewBox.load();
  377. }.bind(this));
  378. }
  379. });