Form.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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", "Currency", "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", "ElTime",
  14. "OOInput", "OODatetime", "OOTextarea", "OOSelect", "OOCheckGroup", "OORadioGroup"
  15. ],
  16. "injectActions" : [
  17. {
  18. "name" : "top",
  19. "styles" : "injectActionTop",
  20. "event" : "click",
  21. "action" : "injectTop",
  22. "title": MWF.APPFD.LP.formAction["insertTop"]
  23. },
  24. {
  25. "name" : "bottom",
  26. "styles" : "injectActionBottom",
  27. "event" : "click",
  28. "action" : "injectBottom",
  29. "title": MWF.APPFD.LP.formAction["insertBottom"]
  30. }
  31. ]
  32. },
  33. initialize: function(designer, container, options){
  34. this.setOptions(options);
  35. this.path = "../x_component_process_FormDesigner/Module/Form/";
  36. this.cssPath = "../x_component_process_FormDesigner/Module/Form/"+this.options.style+"/css.wcss";
  37. this._loadCss();
  38. this.container = null;
  39. this.form = this;
  40. this.moduleType = "form";
  41. this.moduleList = [];
  42. this.moduleNodeList = [];
  43. this.moduleContainerNodeList = [];
  44. this.moduleElementNodeList = [];
  45. this.moduleComponentNodeList = [];
  46. // this.moduleContainerList = [];
  47. this.dataTemplate = {};
  48. this.designer = designer;
  49. this.container = container;
  50. this.selectedModules = [];
  51. },
  52. // 移动端表单加载工具栏
  53. loadMobileActionToos: function() {
  54. if (this.options.mode==="Mobile"){
  55. if (!this.json.defaultTools){
  56. this.json.defaultTools = o2.JSON.get("../x_component_cms_FormDesigner/Module/Form/toolbars.json", null,false);
  57. }
  58. if (!this.json.tools) this.json.tools=[];
  59. }
  60. },
  61. //loadTemplateStyles : function( file, callback ){
  62. // debugger;
  63. // if( !file ){
  64. // if (callback) callback({});
  65. // return;
  66. // }
  67. // this.templateStylesList = this.templateStylesList || {};
  68. // if( this.templateStylesList[file] ){
  69. // if (callback) callback(this.templateStylesList[file]);
  70. // return;
  71. // }
  72. // var stylesUrl = "../x_component_cms_FormDesigner/Module/Form/skin/"+file;
  73. // MWF.getJSON(stylesUrl,{
  74. // "onSuccess": function(responseJSON){
  75. // this.templateStylesList[file] = responseJSON;
  76. // if (callback) callback(responseJSON);
  77. // }.bind(this),
  78. // "onRequestFailure": function(){
  79. // if (callback) callback({});
  80. // }.bind(this),
  81. // "onError": function(){
  82. // if (callback) callback({});
  83. // }.bind(this)
  84. // }
  85. // );
  86. //},
  87. loadTemplateStyleFile : function(file, callback ){
  88. if( !file ){
  89. if (callback) callback({});
  90. return;
  91. }
  92. var stylesUrl = "../x_component_cms_FormDesigner/Module/Form/skin/"+file;
  93. MWF.getJSON(stylesUrl,{
  94. "onSuccess": function(responseJSON){
  95. //this.templateStylesList[file] = responseJSON;
  96. if (callback) callback(responseJSON);
  97. }.bind(this),
  98. "onRequestFailure": function(){
  99. if (callback) callback({});
  100. }.bind(this),
  101. "onError": function(){
  102. if (callback) callback({});
  103. }.bind(this)
  104. }
  105. );
  106. },
  107. loadTemplateExtendStyleFile : function(extendFile, callback ){
  108. if( !extendFile ){
  109. if (callback) callback({});
  110. return;
  111. }
  112. var stylesUrl = "../x_component_cms_FormDesigner/Module/Form/skin/"+extendFile;
  113. MWF.getJSON(stylesUrl,{
  114. "onSuccess": function(responseJSON){
  115. //this.templateStylesList[file] = responseJSON;
  116. if (callback) callback(responseJSON);
  117. }.bind(this),
  118. "onRequestFailure": function(){
  119. if (callback) callback({});
  120. }.bind(this),
  121. "onError": function(){
  122. if (callback) callback({});
  123. }.bind(this)
  124. }
  125. );
  126. },
  127. loadStylesList: function(callback) {
  128. //var stylesUrl = "../x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "mobileStyles": "styles")+".json";
  129. //var stylesUrl = "../x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  130. if (this.stylesList) {
  131. callback(this.stylesList);
  132. } else {
  133. var configUrl = "../x_component_cms_FormDesigner/Module/Form/skin/config.json";
  134. MWF.getJSON(configUrl, {
  135. "onSuccess": function (responseJSON) {
  136. this.stylesList = responseJSON;
  137. if (callback) callback(this.stylesList);
  138. }.bind(this),
  139. "onRequestFailure": function () {
  140. this.stylesList = {};
  141. if (callback) callback(this.stylesList);
  142. }.bind(this),
  143. "onError": function () {
  144. this.stylesList = {};
  145. if (callback) callback(this.stylesList);
  146. }.bind(this)
  147. }
  148. );
  149. }
  150. },
  151. //loadStylesList: function(callback){
  152. //var stylesUrl = "../x_component_cms_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  153. //MWF.getJSON(stylesUrl,{
  154. // "onSuccess": function(responseJSON){
  155. // this.stylesList= responseJSON;
  156. // if (callback) callback(this.stylesList);
  157. // }.bind(this),
  158. // "onRequestFailure": function(){
  159. // this.stylesList = {};
  160. // if (callback) callback(this.stylesList);
  161. // }.bind(this),
  162. // "onError": function(){
  163. // this.stylesList = {};
  164. // if (callback) callback(this.stylesList);
  165. // }.bind(this)
  166. // }
  167. //);
  168. //},
  169. loadModule: function(json, dom, parent){
  170. var module, className;
  171. if( !json ){
  172. className = ( dom.get("MWFType") || "div" ).capitalize();
  173. this.getTemplateData(className, function(data){
  174. var moduleData = Object.clone(data);
  175. moduleData.id = dom.get("id");
  176. this.json.moduleList[dom.get("id")] = moduleData;
  177. module = new MWF["CMSFC"+className](this);
  178. module.load(moduleData, dom, parent);
  179. }.bind(this), false);
  180. return module;
  181. }else if( MWF["CMSFC"+json.type] ){
  182. className = json.type.capitalize();
  183. this.getTemplateData(className, function(data){
  184. var moduleData = Object.clone(data);
  185. Object.merge(moduleData, json);
  186. Object.merge(json, moduleData);
  187. module = new MWF["CMSFC"+json.type](this);
  188. module.load(json, dom, parent);
  189. }.bind(this), false);
  190. return module;
  191. }else{
  192. className = json.type.capitalize();
  193. this.getTemplateData(className, function(data){
  194. var moduleData = Object.clone(data);
  195. Object.merge(moduleData, json);
  196. Object.merge(json, moduleData);
  197. module = new MWF["CMSFCDiv"](this);
  198. module.load(json, dom, parent);
  199. }.bind(this), false);
  200. return module;
  201. }
  202. },
  203. createModule: function(className, e){
  204. //var classPre = MWF.CMSFD.RedesignModules.indexOf( className.toLowerCase() ) != -1 ? "CMSFC" : "FC";
  205. var classPre = "CMSFC";
  206. this.getTemplateData(className, function(data){
  207. var moduleData = Object.clone(data);
  208. var newTool = new MWF[classPre+className](this);
  209. newTool.create(moduleData, e);
  210. }.bind(this));
  211. },
  212. getTemplateData: function(className, callback, async){
  213. if (this.dataTemplate[className]){
  214. if (callback) callback(this.dataTemplate[className]);
  215. }else{
  216. var _className = className.indexOf("Process") === 0 ? className.substr( 7, className.length - 1 ) : className;
  217. var path = MWF.CMSFD.ResetTemplateModules.indexOf( className.toLowerCase() ) != -1 ? "x_component_cms_FormDesigner" : "x_component_process_FormDesigner";
  218. var templateUrl = "../"+path+"/Module/"+_className+"/template.json";
  219. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  220. this.dataTemplate[className] = responseJSON;
  221. if (callback) callback(responseJSON);
  222. }.bind(this), async);
  223. }
  224. },
  225. showProperty: function(callback){
  226. if (!this.property){
  227. this.property = new MWF.xApplication.cms.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  228. "path": this.options.propertyPath,
  229. "onPostLoad": function(){
  230. this.property.show();
  231. if (callback) callback();
  232. }.bind(this)
  233. });
  234. this.property.load();
  235. }else{
  236. this.property.show();
  237. if (callback) callback();
  238. }
  239. },
  240. save: function(callback){
  241. this.designer.saveForm();
  242. //this._getFormData();
  243. //this.designer.actions.saveForm(this.data, function(responseJSON){
  244. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  245. //
  246. // //this.json.id = responseJSON.data;
  247. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  248. // this.treeNode.setTitle(this.json.id);
  249. // this.node.set("id", this.json.id);
  250. //
  251. // if (callback) callback();
  252. // //this.reload(responseJSON.data);
  253. //}.bind(this));
  254. },
  255. implode: function(){
  256. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  257. MWF.CMSFormImport.create("O2", this);
  258. }.bind(this));
  259. },
  260. implodeHTML: function(){
  261. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  262. MWF.CMSFormImport.create("html", this, {"type": "process"});
  263. }.bind(this));
  264. },
  265. implodeOffice: function(){
  266. MWF.xDesktop.requireApp("cms.FormDesigner", "Import", function(){
  267. MWF.CMSFormImport.create("office", this);
  268. }.bind(this));
  269. },
  270. showFormVersion: function(){
  271. this.versionNode = new Element("div");
  272. this.dlg = o2.DL.open({
  273. "title": MWF.CMSFD.LP.version["title"],
  274. "content": this.versionNode,
  275. "offset": {"y": -100},
  276. "isMax": false,
  277. "width": 500,
  278. "height": 300,
  279. "buttonList": [
  280. {
  281. "type": "cancel",
  282. "text": MWF.CMSFD.LP.version["close"],
  283. "action": function(){ this.close(); }
  284. }
  285. ],
  286. "onPostShow": function(){
  287. this.loadVersionList();
  288. }.bind(this),
  289. "onPostClose": function(){
  290. this.dlg = null;
  291. }.bind(this)
  292. });
  293. },
  294. loadVersionList : function(){
  295. var tableHtml = "<table width='100%' cellspacing='0' cellpadding='3' style='margin-top: 1px'><tr>" +
  296. "<th>"+MWF.CMSFD.LP.version["no"]+"</th>" +
  297. "<th>"+MWF.CMSFD.LP.version["person"]+"</th>" +
  298. "<th>"+MWF.CMSFD.LP.version["updateTime"]+"</th>" +
  299. "<th>"+MWF.CMSFD.LP.version["op"]+"</th>" +
  300. "</tr></table>";
  301. this.versionNode.set("html", tableHtml);
  302. this.versionTable = this.versionNode.getElement("table");
  303. o2.Actions.load("x_cms_assemble_control").FormVersionAction.listWithForm(this.form.json.id, function(json){
  304. this.versionList = json.data;
  305. this.versionList.each(function (version,index) {
  306. var node = new Element("tr").inject(this.versionTable);
  307. var html = "<td>"+(index+1)+"</td>" +
  308. "<td>"+version.person+"</td>" +
  309. "<td>"+version.updateTime+"</td>" +
  310. "<td></td>";
  311. node.set("html", html);
  312. var actionNode = new Element("div",{"styles":{
  313. "width": "60px",
  314. "padding": "0px 3px",
  315. "border-radius": "20px",
  316. "cursor" : "pointer",
  317. "color": "#ffffff",
  318. "background-color": "#4A90E2",
  319. "float": "left",
  320. "margin-right": "2px",
  321. "text-align": "center",
  322. "font-weight": "100"
  323. }}).inject(node.getLast("td"));
  324. actionNode.set("text", MWF.CMSFD.LP.version["resume"]);
  325. actionNode.addEvent("click",function (e) {
  326. var _self = this;
  327. this.designer.confirm("warn", e, MWF.CMSFD.LP.version["resumeConfirm"], MWF.CMSFD.LP.version["resumeInfo"], 460, 120, function(){
  328. _self.resumeForm(version);
  329. this.close();
  330. }, function(){
  331. this.close();
  332. });
  333. }.bind(this));
  334. }.bind(this))
  335. }.bind(this));
  336. },
  337. resumeForm : function(version){
  338. o2.Actions.load("x_cms_assemble_control").FormVersionAction.get(version.id, function( json ){
  339. var formData = JSON.parse(json.data.data);
  340. //this.action.FormAction.update(version.form, formData,function( json ){
  341. this.designer.notice(MWF.CMSFD.LP.version["resumeSuccess"]);
  342. var data = JSON.decode(MWF.decodeJsonString(formData.data));
  343. data.isNewForm = false;
  344. this.reload(data);
  345. this.dlg.close();
  346. //}.bind(this), null, false);
  347. }.bind(this), null, false);
  348. },
  349. setPropertiesOrStyles: function(name){
  350. if (name=="styles"){
  351. this.setCustomStyles();
  352. }
  353. if (name=="properties"){
  354. this.node.setProperties(this.json.properties);
  355. }
  356. },
  357. setCustomStyles: function(){
  358. var border = this.node.getStyle("border");
  359. this.node.clearStyles();
  360. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  361. var y = this.container.getStyle("height");
  362. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  363. this.node.setStyle("min-height", ""+y+"px");
  364. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  365. this.node.setStyle("border", border);
  366. Object.each(this.json.styles, function(value, key){
  367. var reg = /^border\w*/ig;
  368. if (!key.test(reg)){
  369. this.node.setStyle(key, value);
  370. }
  371. }.bind(this));
  372. },
  373. //_setEditStyle: function(name, obj, oldValue){
  374. // if (name=="name"){
  375. // var title = this.json.name || this.json.id;
  376. // this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  377. // }
  378. // if (name=="id"){
  379. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  380. // this.treeNode.setTitle(this.json.id);
  381. // this.node.set("id", this.json.id);
  382. // }
  383. // if (name=="formStyleType"){
  384. // this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  385. // if (oldValue) {
  386. // var oldTemplateStyles = this.stylesList[oldValue];
  387. // if (oldTemplateStyles){
  388. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  389. // }
  390. // }
  391. // if (this.templateStyles){
  392. // if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  393. // }
  394. // this.setAllStyles();
  395. //
  396. // this.moduleList.each(function(module){
  397. // if (oldTemplateStyles){
  398. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  399. // }
  400. // module.setStyleTemplate();
  401. // module.setAllStyles();
  402. // }.bind(this));
  403. // }
  404. // if (name==="css"){
  405. // this.reloadCss();
  406. // }
  407. // this._setEditStyle_custom(name, obj, oldValue);
  408. //},
  409. _setEditStyle: function(name, obj, oldValue){
  410. if (name=="name"){
  411. var title = this.json.name || this.json.id;
  412. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  413. }
  414. if (name=="id"){
  415. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  416. this.treeNode.setTitle(this.json.id);
  417. this.node.set("id", this.json.id);
  418. }
  419. if ( name=="formStyleType" ){
  420. var loadOldTemplateStyle = function () {
  421. if( typeOf(oldValue) === "object" && oldValue.type === "script" ){ //如果原来是自定义表单样式
  422. this.loadCustomTemplateStyles( oldValue , function (oldTemplateStyles) {
  423. this.switchTemplateStyles( oldTemplateStyles );
  424. }.bind(this))
  425. }else{
  426. var oldFile, oldExtendFile;
  427. if( typeOf(oldValue) === "object" )oldValue === oldValue.id;
  428. if( oldValue && this.stylesList[oldValue] ){
  429. oldFile = this.stylesList[oldValue].file;
  430. oldExtendFile = this.stylesList[oldValue].extendFile;
  431. }
  432. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  433. this.switchTemplateStyles( oldTemplateStyles );
  434. }.bind(this))
  435. }
  436. }.bind(this);
  437. var formStyleType = this.json.formStyleType;
  438. if( typeOf(formStyleType) === "object" && formStyleType.type === "script" ){
  439. this.loadCustomTemplateStyles( formStyleType , function (templateStyles) {
  440. this.templateStyles = templateStyles;
  441. loadOldTemplateStyle();
  442. this.json.styleConfig = formStyleType;
  443. }.bind(this))
  444. }else{
  445. if( typeOf(formStyleType) === "object" )formStyleType = formStyleType.id;
  446. var file = (this.stylesList && formStyleType) ? this.stylesList[formStyleType].file : null;
  447. var extendFile = (this.stylesList && formStyleType) ? this.stylesList[formStyleType].extendFile : null;
  448. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  449. this.templateStyles = templateStyles;
  450. loadOldTemplateStyle();
  451. this.json.styleConfig = (this.stylesList && formStyleType) ? this.stylesList[formStyleType] : null;
  452. }.bind(this))
  453. }
  454. }
  455. if (name==="css"){
  456. this.reloadCss();
  457. }
  458. this._setEditStyle_custom(name, obj, oldValue);
  459. },
  460. parseCSS: function(css){
  461. var rex = /(url\(.*\))/g;
  462. var match;
  463. while ((match = rex.exec(css)) !== null) {
  464. var pic = match[0];
  465. var len = pic.length;
  466. var s = pic.substring(pic.length-2, pic.length-1);
  467. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  468. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  469. pic = pic.substring(n0, pic.length-n1);
  470. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  471. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  472. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  473. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  474. pic = pic.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  475. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  476. pic = pic.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  477. }
  478. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  479. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  480. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  481. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  482. }
  483. pic = o2.filterUrl(pic);
  484. }
  485. pic = "url('"+pic+"')";
  486. var len2 = pic.length;
  487. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  488. rex.lastIndex = rex.lastIndex + (len2-len);
  489. }
  490. return css;
  491. },
  492. preview: function(){
  493. MWF.xDesktop.requireApp("cms.FormDesigner", "Preview", function(){
  494. if (this.options.mode=="Mobile"){
  495. this.previewBox = new MWF.xApplication.cms.FormDesigner.Preview(this, {"size": {"x": "400", "y": 580}});
  496. }else{
  497. this.previewBox = new MWF.xApplication.cms.FormDesigner.Preview(this);
  498. }
  499. this.previewBox.load();
  500. }.bind(this));
  501. }
  502. });