Form.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.require("MWF.widget.Common", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.Form = MWF.FCForm = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_process_FormDesigner/Module/Form/form.html",
  9. "mode": "PC",
  10. "fields": ["Calendar", "Checkbox", "Datagrid", "Datagrid$Title", "Datagrid$Data", "Htmleditor", "Number", "Office", "Orgfield", "org", "Personfield", "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. reload: function(data){
  48. this.moduleList.each(function(module){
  49. if (module.property){
  50. module.property.destroy();
  51. }
  52. }.bind(this));
  53. if (this.property) this.property.destroy();
  54. this.property = null;
  55. this.moduleList = [];
  56. this.moduleNodeList = [];
  57. this.moduleContainerNodeList = [];
  58. this.moduleElementNodeList = [];
  59. this.moduleComponentNodeList = [];
  60. this.dataTemplate = {};
  61. this.selectedModules = [];
  62. this.container.empty();
  63. if (this.treeNode){
  64. this.domTree.empty();
  65. this.domTree.node.destroy();
  66. this.domTree = null;
  67. this.treeNode = null;
  68. }
  69. this.currentSelectedModule = null;
  70. this.propertyMultiTd = null;
  71. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  72. this.load(data);
  73. this.selected();
  74. },
  75. load : function(data){
  76. debugger;
  77. this.data = data;
  78. this.json = data.json;
  79. this.html = data.html;
  80. this.json.mode = this.options.mode;
  81. if (!this.json.css) this.json.css = {"code":""};
  82. if (this.options.mode==="Mobile"){
  83. if (!this.json.defaultTools){
  84. this.json.defaultTools = o2.JSON.get(this.path+"toolbars.json", null,false);
  85. }
  86. if (!this.json.tools) this.json.tools=[];
  87. }
  88. this.isNewForm = (this.json.id) ? false : true;
  89. if (this.isNewForm) this.checkUUID();
  90. if(this.designer.application) this.data.json.applicationName = this.designer.application.name;
  91. if(this.designer.application) this.data.json.application = this.designer.application.id;
  92. this.container.set("html", this.html);
  93. this.loadStylesList(function(){
  94. var oldStyleValue = "";
  95. if ((!this.json.formStyleType) || !this.stylesList[this.json.formStyleType]) this.json.formStyleType="blue-simple";
  96. if (this.options.mode=="Mobile"){
  97. if (this.json.formStyleType != "defaultMobile"){
  98. oldStyleValue = this.json.formStyleType;
  99. this.json.formStyleType = "defaultMobile";
  100. }
  101. }
  102. this.loadTemplateStyles( this.stylesList[this.json.formStyleType].file, this.stylesList[this.json.formStyleType].extendFile, function( templateStyles ){
  103. //this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  104. this.templateStyles = templateStyles;
  105. this.loadDomModules();
  106. if (this.json.formStyleType && this.templateStyles && this.templateStyles["form"]){
  107. this.setTemplateStyles(this.templateStyles["form"]);
  108. }
  109. this.setCustomStyles();
  110. this.node.setProperties(this.json.properties);
  111. this.setNodeEvents();
  112. if (this.options.mode=="Mobile"){
  113. if (oldStyleValue) this._setEditStyle("formStyleType", null, oldStyleValue);
  114. }
  115. this.selected();
  116. this.autoSave();
  117. this.designer.addEvent("queryClose", function(){
  118. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  119. }.bind(this));
  120. }.bind(this));
  121. }.bind(this));
  122. },
  123. removeStyles: function(from, to){
  124. if (this.json[to]){
  125. Object.each(from, function(style, key){
  126. if (this.json[to][key] && this.json[to][key]==style){
  127. delete this.json[to][key];
  128. }
  129. }.bind(this));
  130. }
  131. },
  132. copyStyles: function(from, to){
  133. if (!this.json[to]) this.json[to] = {};
  134. Object.each(from, function(style, key){
  135. if (!this.json[to][key]) this.json[to][key] = style;
  136. }.bind(this));
  137. },
  138. clearTemplateStyles: function(styles){
  139. if (styles){
  140. if (styles.styles) this.removeStyles(styles.styles, "styles");
  141. if (styles.properties) this.removeStyles(styles.properties, "properties");
  142. }
  143. if( this.json.confirmStyle )delete this.json.confirmStyle;
  144. if( this.json.dialogStyle )delete this.json.dialogStyle;
  145. if( this.json.attachmentStyle )delete this.json.attachmentStyle;
  146. if( this.json.hideModuleIcon )delete this.json.hideModuleIcon;
  147. if( this.json.nodeStyleWithhideModuleIcon )delete this.json.nodeStyleWithhideModuleIcon;
  148. if( this.json.confirmIcon )delete this.json.confirmIcon;
  149. if( this.json.submitedDlgUseNotice )delete this.json.submitedDlgUseNotice;
  150. if( this.json.submitedDlgStyle )delete this.json.submitedDlgStyle;
  151. if( this.json.selectorStyle )delete this.json.selectorStyle;
  152. if( this.json.errorStyle )delete this.json.errorStyle;
  153. if( this.json.noticeStyle )delete this.json.noticeStyle;
  154. if( this.json.noticeErrorStyle )delete this.json.noticeErrorStyle;
  155. if( this.json.noticeSuccessStyle )delete this.json.noticeSuccessStyle;
  156. if( this.json.noticeOkStyle )delete this.json.noticeOkStyle;
  157. if( this.json.noticeNoticeStyle )delete this.json.noticeNoticeStyle;
  158. },
  159. setTemplateStyles: function(styles){
  160. if (styles.styles) this.copyStyles(styles.styles, "styles");
  161. if (styles.properties) this.copyStyles(styles.properties, "properties");
  162. //if( styles.confirmStyle )this.json.confirmStyle = styles.confirmStyle;
  163. //if( styles.dialogStyle )this.json.dialogStyle = styles.dialogStyle;
  164. //if( styles.selectorStyle )this.json.selectorStyle = styles.selectorStyle;
  165. },
  166. loadTemplateStyles : function( file, extendFile, callback ){
  167. if( !file ){
  168. if (callback) callback({});
  169. return;
  170. }
  171. this.templateStylesList = this.templateStylesList || {};
  172. if( this.templateStylesList[file] ){
  173. if (callback) callback(this.templateStylesList[file]);
  174. return;
  175. }
  176. this.loadTemplateStyleFile( file, function( json_file ){
  177. this.loadTemplateExtendStyleFile( extendFile, function( json_extend ){
  178. this.templateStylesList[file] = Object.merge( json_file, json_extend );
  179. if (callback) callback(this.templateStylesList[file]);
  180. }.bind(this))
  181. }.bind(this))
  182. },
  183. loadTemplateStyleFile : function(file, callback ){
  184. if( !file ){
  185. if (callback) callback({});
  186. return;
  187. }
  188. var stylesUrl = "/x_component_process_FormDesigner/Module/Form/skin/"+file;
  189. MWF.getJSON(stylesUrl,{
  190. "onSuccess": function(responseJSON){
  191. //this.templateStylesList[file] = responseJSON;
  192. if (callback) callback(responseJSON);
  193. }.bind(this),
  194. "onRequestFailure": function(){
  195. if (callback) callback({});
  196. }.bind(this),
  197. "onError": function(){
  198. if (callback) callback({});
  199. }.bind(this)
  200. }
  201. );
  202. },
  203. loadTemplateExtendStyleFile : function(extendFile, callback ){
  204. if( !extendFile ){
  205. if (callback) callback({});
  206. return;
  207. }
  208. var stylesUrl = "/x_component_process_FormDesigner/Module/Form/skin/"+extendFile;
  209. MWF.getJSON(stylesUrl,{
  210. "onSuccess": function(responseJSON){
  211. //this.templateStylesList[file] = responseJSON;
  212. if (callback) callback(responseJSON);
  213. }.bind(this),
  214. "onRequestFailure": function(){
  215. if (callback) callback({});
  216. }.bind(this),
  217. "onError": function(){
  218. if (callback) callback({});
  219. }.bind(this)
  220. }
  221. );
  222. },
  223. loadStylesList: function(callback){
  224. //var stylesUrl = "/x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "mobileStyles": "styles")+".json";
  225. //var stylesUrl = "/x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  226. var configUrl = "/x_component_process_FormDesigner/Module/Form/skin/config.json";
  227. MWF.getJSON(configUrl,{
  228. "onSuccess": function(responseJSON){
  229. this.stylesList = responseJSON;
  230. if (callback) callback(this.stylesList);
  231. }.bind(this),
  232. "onRequestFailure": function(){
  233. this.stylesList = {};
  234. if (callback) callback(this.stylesList);
  235. }.bind(this),
  236. "onError": function(){
  237. this.stylesList = {};
  238. if (callback) callback(this.stylesList);
  239. }.bind(this)
  240. }
  241. );
  242. },
  243. autoSave: function(){
  244. this.autoSaveCheckNode = this.designer.formToolbarNode.getElement("#MWFFormAutoSaveCheck");
  245. if (this.autoSaveCheckNode){
  246. this.autoSaveTimerID = window.setInterval(function(){
  247. if (this.autoSaveCheckNode.get("checked")){
  248. this.save();
  249. }
  250. }.bind(this), 60000);
  251. }
  252. },
  253. checkUUID: function(){
  254. this.designer.actions.getUUID(function(id){
  255. this.json.id = id;
  256. }.bind(this));
  257. },
  258. loadDomModules: function(){
  259. this.node = this.container.getFirst();
  260. this.node.set("id", this.json.id);
  261. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  262. this.node.store("module", this);
  263. var id = this.json.id.replace(/\-/g, "");
  264. this.node.addClass("css"+id);
  265. this.reloadCss();
  266. var y = this.container.getStyle("height");
  267. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  268. this.node.setStyle("min-height", ""+y+"px");
  269. this.designer.addEvent("resize", function(){
  270. var y = this.container.getStyle("height");
  271. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  272. this.node.setStyle("min-height", ""+y+"px");
  273. }.bind(this));
  274. this.loadDomTree();
  275. },
  276. loadDomTree: function(){
  277. MWF.require("MWF.widget.Tree", function(){
  278. this.domTree = new MWF.widget.Tree(this.designer.propertyDomArea, {"style": "domtree"});
  279. this.domTree.load();
  280. this.createFormTreeNode();
  281. this.parseModules(this, this.node);
  282. }.bind(this));
  283. },
  284. createFormTreeNode: function(){
  285. var text = "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ";
  286. var o = {
  287. "expand": true,
  288. "title": this.json.id,
  289. "text": "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ",
  290. "icon": (this.options.mode=="Mobile") ? "mobile.png": "pc.png"
  291. };
  292. o.action = function(){
  293. if (this.module) this.module.selected();
  294. };
  295. this.treeNode = this.domTree.appendChild(o);
  296. this.treeNode.setText(text);
  297. this.treeNode.module = this;
  298. },
  299. parseModules: function(parent, dom){
  300. var subDom = dom.getFirst();
  301. while (subDom){
  302. if (subDom.get("MWFtype")){
  303. // var module = subDom.retrieve("module");
  304. // alert(subDom.get("id")+": "+module);
  305. // if (!module){
  306. var json = this.getDomjson(subDom);
  307. module = this.loadModule(json, subDom, parent);
  308. // }
  309. // if (module.moduleType=="container") this.parseModules(module, subDom);
  310. // }else{
  311. // this.parseModules(parent, subDom);
  312. }
  313. // else if (subDom.getFirst()){
  314. // subDom = subDom.getFirst();
  315. // this.parseModules(parent, subDom);
  316. // }else{
  317. // subDom = subDom.getNext();
  318. // }
  319. subDom = subDom.getNext();
  320. }
  321. },
  322. getDomjson: function(dom){
  323. var mwfType = dom.get("MWFtype");
  324. switch (mwfType) {
  325. case "form":
  326. return this.json;
  327. case "":
  328. return null;
  329. default:
  330. var id = dom.get("id");
  331. if (id){
  332. return this.json.moduleList[id];
  333. }else{
  334. return null;
  335. }
  336. }
  337. },
  338. loadModule: function(json, dom, parent){
  339. if( !json ){
  340. debugger;
  341. var module;
  342. var className = ( dom.get("MWFType") || "div" ).capitalize();
  343. this.getTemplateData(className, function(data){
  344. var moduleData = Object.clone(data);
  345. moduleData.id = dom.get("id");
  346. this.json.moduleList[dom.get("id")] = moduleData;
  347. module = new MWF["FC"+className](this);
  348. module.load(moduleData, dom, parent);
  349. }.bind(this), false);
  350. return module;
  351. }else if( MWF["FC"+json.type] ){
  352. var module = new MWF["FC"+json.type](this);
  353. module.load(json, dom, parent);
  354. //this.moduleList.push(module);
  355. return module;
  356. }else{
  357. var module = new MWF["FCDiv"](this);
  358. module.load(json, dom, parent);
  359. //this.moduleList.push(module);
  360. return module;
  361. }
  362. },
  363. setNodeEvents: function(){
  364. this.node.addEvent("click", function(e){
  365. this.selected();
  366. }.bind(this));
  367. // this._controlKeyEventFun = function(e){
  368. // if (e.control){
  369. // this.controlMode = true;
  370. // if (this.copyNode) this.copyNode.destroy();
  371. // }else{
  372. // this.controlMode = false;
  373. // // var copyNode = this._getCopyNode(this);
  374. // // copyNode.inject(this.node, "before");
  375. // }
  376. // }.bind(this);
  377. this.designer.content.addEvent("keydown", function(e){
  378. if (this.moveModule){
  379. if (e.control){
  380. this.moveModule._setControlMode(true);
  381. }else{
  382. this.moveModule._setControlMode(false);
  383. }
  384. }
  385. }.bind(this));
  386. this.designer.content.addEvent("keyup", function(e){
  387. if (this.moveModule){
  388. if (e.control){
  389. this.moveModule._setControlMode(true);
  390. }else{
  391. this.moveModule._setControlMode(false);
  392. }
  393. }
  394. }.bind(this));
  395. },
  396. createModuleImmediately: function( className, parentModule, relativeNode, position, selectDisabled, async ){
  397. var module;
  398. this.getTemplateData(className, function(data){
  399. var moduleData = Object.clone(data);
  400. module = new MWF["PC"+className](this);
  401. if( parentModule ){
  402. module.onDragModule = parentModule;
  403. if (!parentModule.Component) module.inContainer = parentModule;
  404. module.parentContainer = parentModule;
  405. module.nextModule = null;
  406. }
  407. module.createImmediately(moduleData, relativeNode, position, selectDisabled);
  408. }.bind(this), async);
  409. return module;
  410. },
  411. createModule: function(className, e){
  412. this.getTemplateData(className, function(data){
  413. var moduleData = Object.clone(data);
  414. var newTool = new MWF["FC"+className](this);
  415. newTool.create(moduleData, e);
  416. }.bind(this));
  417. },
  418. getTemplateData: function(className, callback , async){
  419. if (this.dataTemplate[className]){
  420. if (callback) callback(this.dataTemplate[className]);
  421. }else{
  422. var templateUrl = "/x_component_process_FormDesigner/Module/"+className+"/template.json";
  423. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  424. this.dataTemplate[className] = responseJSON;
  425. if (callback) callback(responseJSON);
  426. }.bind(this), async);
  427. }
  428. },
  429. selected: function(){
  430. if (this.currentSelectedModule){
  431. if (this.currentSelectedModule==this){
  432. return true;
  433. }else{
  434. this.currentSelectedModule.unSelected();
  435. }
  436. }
  437. if (this.propertyMultiTd){
  438. this.propertyMultiTd.hide();
  439. this.propertyMultiTd = null;
  440. }
  441. this.unSelectedMulti();
  442. this.currentSelectedModule = this;
  443. if (this.treeNode){
  444. this.treeNode.selectNode();
  445. }
  446. this.showProperty();
  447. // this.isFocus = true;
  448. },
  449. unSelectedMulti: function(){
  450. while (this.selectedModules.length){
  451. this.selectedModules[0].unSelectedMulti();
  452. }
  453. if (this.multimoduleActionsArea) this.multimoduleActionsArea.setStyle("display", "none");
  454. },
  455. unSelectAll: function(){
  456. },
  457. _beginSelectMulti: function(){
  458. if (this.currentSelectedModule) this.currentSelectedModule.unSelected();
  459. this.unSelectedMulti();
  460. this.noSelected = true;
  461. },
  462. _completeSelectMulti: function(){
  463. if (this.selectedModules.length<2){
  464. this.selectedModules[0].selected();
  465. }else{
  466. this._showMultiActions();
  467. }
  468. },
  469. createMultimoduleActionsArea: function(){
  470. this.multimoduleActionsArea = new Element("div", {
  471. styles: {
  472. "display": "none",
  473. // "width": 18*this.options.actions.length,
  474. "position": "absolute",
  475. "background-color": "#F1F1F1",
  476. "padding": "1px",
  477. "padding-right": "0px",
  478. "border": "1px solid #AAA",
  479. "box-shadow": "0px 2px 5px #999",
  480. "z-index": 10001
  481. }
  482. }).inject(this.form.container, "after");
  483. },
  484. _showMultiActions: function(){
  485. if (!this.multimoduleActionsArea) this.createMultimoduleActionsArea();
  486. var firstModule = this._getFirstMultiSelectedModule();
  487. if (firstModule){
  488. // var module = firstModule.module;
  489. var y = firstModule.position.y-25;
  490. var x = firstModule.position.x;
  491. this.multimoduleActionsArea.setPosition({"x": x, "y": y});
  492. this.multimoduleActionsArea.setStyle("display", "block");
  493. }
  494. },
  495. _getFirstMultiSelectedModule: function(){
  496. var firstModule = null;
  497. this.selectedModules.each(function(module){
  498. var position = module.node.getPosition(module.form.node.getOffsetParent());
  499. if (!firstModule){
  500. firstModule = {"module": module, "position": position};
  501. }else{
  502. if (position.y<firstModule.position.y){
  503. firstModule = {"module": module, "position": position};
  504. }else if (position.y==firstModule.position.y){
  505. if (position.x<firstModule.position.x){
  506. firstModule = {"module": module, "position": position};
  507. }
  508. }
  509. }
  510. });
  511. return firstModule;
  512. },
  513. showProperty: function(){
  514. if (!this.property){
  515. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  516. "path": this.options.propertyPath,
  517. "onPostLoad": function(){
  518. this.property.show();
  519. }.bind(this)
  520. });
  521. this.property.load();
  522. }else{
  523. this.property.show();
  524. }
  525. },
  526. hideProperty: function(){
  527. if (this.property) this.property.hide();
  528. },
  529. unSelected: function(){
  530. this.currentSelectedModule = null;
  531. this.hideProperty();
  532. },
  533. _dragIn: function(module){
  534. if (!this.Component) module.inContainer = this;
  535. module.parentContainer = this;
  536. this.node.setStyles({"border": "1px solid #ffa200"});
  537. var copyNode = module._getCopyNode();
  538. copyNode.inject(this.node);
  539. },
  540. _dragOut: function(module){
  541. module.inContainer = null;
  542. module.parentContainer = null;
  543. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  544. this.node.setStyles(this.json.styles);
  545. var copyNode = module._getCopyNode();
  546. copyNode.setStyle("display", "none");
  547. },
  548. _dragDrop: function(module, flag){
  549. var f = flag || !(new Event(event)).control;
  550. if( f ){
  551. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  552. this.node.setStyles(this.json.styles);
  553. }
  554. //this._hideInjectAction();
  555. },
  556. _showInjectAction : function( module ){
  557. if ( module.moveNode ){
  558. module.moveNode.setStyle("display","none");
  559. }
  560. //debugger;
  561. this.draggingModule = module;
  562. //if( !this.node.getFirst() ){
  563. // this.inject( "top" );
  564. // return;
  565. //}
  566. if( !this.injectActionArea )this._createInjectAction();
  567. this.injectActionArea.setStyle("display","block");
  568. this._setInjectActionAreaPosition();
  569. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  570. duration: 200,
  571. transition: Fx.Transitions.Sine.easeOut
  572. });
  573. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  574. },
  575. _hideInjectAction : function(){
  576. this.draggingModule = null;
  577. if( this.injectActionArea ){
  578. this.injectActionArea.setStyle("display","none");
  579. }
  580. },
  581. _createInjectAction : function(){
  582. var css = this.form.css;
  583. if( !this.injectActionArea ){
  584. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  585. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  586. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  587. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  588. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  589. var injectActions = {};
  590. this.options.injectActions.each( function( action ){
  591. injectActions[ action.name ] = action;
  592. });
  593. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  594. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  595. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  596. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  597. new Element("div", {
  598. styles : css.injectActionCancelNode,
  599. events : {
  600. click : function(){
  601. this.draggingModule._dragCancel();
  602. this._dragDrop( this.node, true );
  603. this._hideInjectAction();
  604. }.bind(this),
  605. mouseover : function(){
  606. this.setStyles( css.injectActionCancelNode_over )
  607. },
  608. mouseout : function(){
  609. this.setStyles( css.injectActionCancelNode )
  610. }
  611. }
  612. }).inject(this.injectActionArea);
  613. }
  614. },
  615. _createInjectActionNode : function( action, relativeNode ){
  616. var actionNode = new Element("div", {
  617. "styles": this.css[action.styles],
  618. "title": action.title
  619. }).inject( this.injectActionArea );
  620. actionNode.addEvent(action.event, function(e){
  621. this[action.action](e);
  622. }.bind(this));
  623. actionNode.addEvents({
  624. "mouseover": function(e){
  625. relativeNode.setStyle("background", "#ddd");
  626. this.draggingModule.copyNode.setStyle("display","");
  627. this.draggingModule.copyNode.inject( this.node, action.name );
  628. }.bind(this),
  629. "mouseout": function(e){
  630. relativeNode.setStyle("background", "transparent");
  631. }.bind(this)
  632. });
  633. relativeNode.set("title",action.title);
  634. relativeNode.addEvent(action.event, function(e){
  635. this[action.action](e);
  636. }.bind(this));
  637. relativeNode.setStyle("cursor","pointer");
  638. relativeNode.addEvents({
  639. "mouseenter": function(e){
  640. relativeNode.setStyle("background", "#ddd");
  641. this.draggingModule.copyNode.setStyle("display","");
  642. this.draggingModule.copyNode.inject( this.node, action.name );
  643. }.bind(this),
  644. "mouseleave": function(e){
  645. relativeNode.setStyle("background", "transparent");
  646. //this.draggingModule.copyNode.setStyle("display","none");
  647. }.bind(this)
  648. });
  649. },
  650. _setInjectActionAreaPosition: function(){
  651. var e = new Event(event);
  652. var formOffset = this.node.getOffsetParent().getPosition();
  653. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  654. var y = e.page.y - formOffset.y - 60;
  655. var x = e.page.x - formOffset.x - 60;
  656. this.injectActionArea.setPosition({"x": x, "y": y});
  657. },
  658. injectBefore : function( e ){
  659. this.inject( "before" )
  660. },
  661. injectAfter : function( e ){
  662. this.inject( "after" )
  663. },
  664. injectTop : function( e ){
  665. this.inject( "top" )
  666. },
  667. injectBottom : function( e ){
  668. this.inject( "bottom" )
  669. },
  670. inject : function( position ){
  671. if ( this.draggingModule.moveNode ){
  672. this.draggingModule.moveNode.setStyle("display","");
  673. }
  674. this.draggingModule._dragComplete( this.node, position );
  675. this._dragDrop( this.node, true );
  676. this._hideInjectAction();
  677. },
  678. _clearNoId: function(node){
  679. var subNode = node.getFirst();
  680. while (subNode){
  681. var nextNode = subNode.getNext();
  682. if (subNode.get("MWFType")){
  683. if (!subNode.get("id")){
  684. subNode.destroy();
  685. }else{
  686. if (subNode) this._clearNoId(subNode);
  687. }
  688. }else{
  689. if (subNode) this._clearNoId(subNode);
  690. }
  691. subNode = nextNode;
  692. }
  693. },
  694. _getFormData: function(callback){
  695. this.fireEvent("queryGetFormData");
  696. var copy = this.node.clone(true, true);
  697. copy.clearStyles(true);
  698. this.fireEvent("postGetFormData");
  699. this._clearNoId(copy);
  700. var html = copy.outerHTML;
  701. //this._clearNoDomModule();
  702. copy.destroy();
  703. this.data.json.mode = this.options.mode;
  704. this.data.html = html;
  705. //@todo 预先整理表单样式
  706. // var tmpFormNode = new Element("div", {
  707. // "opacity": 0
  708. // }).inject(this.designer.content);
  709. // MWF.xDesktop.requireApp("process.Xform2", "Form_", null, false);
  710. // this.appForm = new MWF.APPForm_(tmpFormNode, this.data, {
  711. // "onAfterLoad": function(){
  712. // var preprocessHtml = tmpFormNode.get("html");
  713. // this.data.preprocessHtml = preprocessHtml;
  714. //
  715. // if (callback) callback();
  716. // }.bind(this)
  717. // });
  718. // this.appForm.businessData = {};
  719. // this.appForm.load();
  720. return this.data;
  721. },
  722. _clearNoDomModule : function(){
  723. debugger;
  724. var existModuleList = {};
  725. Object.each( this.moduleList, function( module ){
  726. existModuleList[ module.json.id ] = true;
  727. });
  728. Object.each( this.data.json.moduleList , function( module, key ){
  729. //if( !this.node.getElement( "#" + module.id ) && !existModuleList[ module.id ] ){
  730. if( !existModuleList[ module.id ] ){
  731. delete this.data.json.moduleList[key];
  732. }
  733. }.bind(this));
  734. },
  735. preview: function(){
  736. MWF.xDesktop.requireApp("process.FormDesigner", "Preview", function(){
  737. if (this.options.mode=="Mobile"){
  738. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this, {"size": {"x": "400", "y": 580}, "mode": "mobile"});
  739. }else{
  740. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this);
  741. }
  742. this.previewBox.load();
  743. }.bind(this));
  744. },
  745. save: function(callback){
  746. // debugger;
  747. // this.moduleList.each(function(module){
  748. // if (module.moduleName==="subform"){
  749. // module.refreshSubform();
  750. // }
  751. // }.bind(this));
  752. this.designer.saveForm();
  753. //this._getFormData();
  754. //this.designer.actions.saveForm(this.data, function(responseJSON){
  755. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  756. //
  757. // //this.json.id = responseJSON.data;
  758. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  759. // this.treeNode.setTitle(this.json.id);
  760. // this.node.set("id", this.json.id);
  761. //
  762. // if (callback) callback();
  763. // //this.reload(responseJSON.data);
  764. //}.bind(this));
  765. },
  766. explode: function(){
  767. this._getFormData();
  768. MWF.require("MWF.widget.Base64", null, false);
  769. var data = MWF.widget.Base64.encode(JSON.encode(this.data));
  770. MWF.require("MWF.widget.Panel", function(){
  771. var node = new Element("div");
  772. var size = this.designer.formNode.getSize();
  773. var position = this.designer.formNode.getPosition(this.designer.formNode.getOffsetParent());
  774. var textarea = new Element("textarea", {
  775. "styles": {
  776. "border": "1px solid #999",
  777. "width": "770px",
  778. "margin-left": "14px",
  779. "margin-top": "14px",
  780. "height": "580px"
  781. },
  782. "text": JSON.encode(this.data)
  783. }).inject(node);
  784. this.explodePanel = new MWF.widget.Panel(node, {
  785. "style": "form",
  786. "isResize": false,
  787. "isMax": false,
  788. "title": "",
  789. "width": 800,
  790. "height": 660,
  791. "top": position.y,
  792. "left": position.x+3,
  793. "isExpand": false,
  794. "target": this.designer.node
  795. });
  796. this.explodePanel.load();
  797. }.bind(this));
  798. },
  799. implode: function(){
  800. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  801. MWF.FormImport.create("O2", this);
  802. }.bind(this));
  803. },
  804. // implodeJsonData: function(str){
  805. // if (str){
  806. // //try{
  807. // debugger;
  808. // var data = JSON.decode(str);
  809. // if (data){
  810. // var json = data.json;
  811. // data.id = this.data.id;
  812. // data.isNewPage = this.data.isNewPage;
  813. // json.id = this.json.id;
  814. // json.name = this.json.name;
  815. // json.application = this.json.application;
  816. // json.applicationName = this.json.applicationName;
  817. //
  818. // this.reload(data);
  819. // this.implodePanel.closePanel();
  820. // }else{
  821. // this.designer.notice(this.designer.lp.implodeError, "error");
  822. // }
  823. // // }catch(e){
  824. // // this.designer.notice(this.designer.lp.implodeError, "error");
  825. // // }
  826. // }else{
  827. // this.designer.notice(this.designer.lp.implodeEmpty, "error");
  828. // }
  829. // },
  830. implodeHTML: function(){
  831. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  832. MWF.FormImport.create("html", this, {"type": "process"});
  833. }.bind(this));
  834. },
  835. implodeOffice: function(){
  836. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  837. MWF.FormImport.create("office", this);
  838. }.bind(this));
  839. },
  840. setPropertiesOrStyles: function(name){
  841. if (name=="styles"){
  842. this.setCustomStyles();
  843. }
  844. if (name=="properties"){
  845. this.node.setProperties(this.json.properties);
  846. }
  847. },
  848. setCustomStyles: function(){
  849. var border = this.node.getStyle("border");
  850. this.node.clearStyles();
  851. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  852. var y = this.container.getStyle("height");
  853. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  854. this.node.setStyle("min-height", ""+y+"px");
  855. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  856. this.node.setStyle("border", border);
  857. Object.each(this.json.styles, function(value, key){
  858. var reg = /^border\w*/ig;
  859. if (!key.test(reg)){
  860. this.node.setStyle(key, value);
  861. }
  862. }.bind(this));
  863. },
  864. _setEditStyle: function(name, obj, oldValue){
  865. if (name=="name"){
  866. var title = this.json.name || this.json.id;
  867. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  868. }
  869. if (name=="id"){
  870. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  871. this.treeNode.setTitle(this.json.id);
  872. this.node.set("id", this.json.id);
  873. }
  874. if (name=="formStyleType"){
  875. var file = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].file : null;
  876. var extendFile = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].extendFile : null;
  877. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  878. //this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  879. this.templateStyles = templateStyles;
  880. var oldFile, oldExtendFile;
  881. if( oldValue && this.stylesList[oldValue] ){
  882. oldFile = this.stylesList[oldValue].file;
  883. oldExtendFile = this.stylesList[oldValue].extendFile;
  884. }
  885. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  886. //if (oldValue) {
  887. // var oldTemplateStyles = this.stylesList[oldValue];
  888. // if (oldTemplateStyles){
  889. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  890. // }
  891. //}
  892. this.json.styleConfig = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  893. if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  894. if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  895. this.setAllStyles();
  896. this.moduleList.each(function(module){
  897. if (oldTemplateStyles[module.moduleName]){
  898. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  899. }
  900. module.setStyleTemplate();
  901. module.setAllStyles();
  902. }.bind(this));
  903. }.bind(this))
  904. }.bind(this))
  905. }
  906. if (name==="css"){
  907. this.reloadCss();
  908. }
  909. this._setEditStyle_custom(name, obj, oldValue);
  910. },
  911. parseCSS: function(css){
  912. var rex = /(url\(.*\))/g;
  913. var match;
  914. while ((match = rex.exec(css)) !== null) {
  915. var pic = match[0];
  916. var len = pic.length;
  917. var s = pic.substring(pic.length-2, pic.length-1);
  918. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  919. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  920. pic = pic.substring(n0, pic.length-n1);
  921. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  922. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  923. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  924. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  925. pic = pic.replace("/x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  926. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  927. pic = pic.replace("x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  928. }
  929. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  930. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  931. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  932. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  933. }
  934. }
  935. pic = "url('"+pic+"')";
  936. var len2 = pic.length;
  937. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  938. rex.lastIndex = rex.lastIndex + (len2-len);
  939. }
  940. return css;
  941. },
  942. reloadCss: function(){
  943. cssText = (this.json.css) ? this.json.css.code : "";
  944. //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement);
  945. var styleNode = $("style"+this.json.id);
  946. if (styleNode) styleNode.destroy();
  947. if (cssText){
  948. cssText = this.parseCSS(cssText);
  949. var rex = new RegExp("(.+)(?=\\{)", "g");
  950. var match;
  951. var id = this.json.id.replace(/\-/g, "");
  952. var prefix = ".css" + id + " ";
  953. while ((match = rex.exec(cssText)) !== null) {
  954. // var rule = prefix + match[0];
  955. // cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  956. // rex.lastIndex = rex.lastIndex + prefix.length;
  957. var rulesStr = match[0];
  958. if (rulesStr.indexOf(",")!=-1){
  959. var rules = rulesStr.split(/\s*,\s*/g);
  960. rules = rules.map(function(r){
  961. return prefix + r;
  962. });
  963. var rule = rules.join(", ");
  964. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  965. rex.lastIndex = rex.lastIndex + (prefix.length*rules.length);
  966. }else{
  967. var rule = prefix + match[0];
  968. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  969. rex.lastIndex = rex.lastIndex + prefix.length;
  970. }
  971. }
  972. var styleNode = document.createElement("style");
  973. styleNode.setAttribute("type", "text/css");
  974. styleNode.id="style"+this.json.id;
  975. styleNode.inject(this.container, "before");
  976. if(styleNode.styleSheet){
  977. var setFunc = function(){
  978. styleNode.styleSheet.cssText = cssText;
  979. };
  980. if(styleNode.styleSheet.disabled){
  981. setTimeout(setFunc, 10);
  982. }else{
  983. setFunc();
  984. }
  985. }else{
  986. var cssTextNode = document.createTextNode(cssText);
  987. styleNode.appendChild(cssTextNode);
  988. }
  989. }
  990. },
  991. setAllStyles: function(){
  992. this.setPropertiesOrStyles("styles");
  993. this.setPropertiesOrStyles("properties");
  994. this.reloadMaplist();
  995. },
  996. reloadMaplist: function(){
  997. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  998. },
  999. _setEditStyle_custom: function(){
  1000. },
  1001. saveAsTemplete: function(){
  1002. },
  1003. isModuleExited : function( id ){
  1004. for( var i=0; i<this.moduleList.length; i++ ){
  1005. if(this.moduleList[i].json.id === id)return true;
  1006. }
  1007. return false;
  1008. },
  1009. checkModuleId: function(id, type, currentSubform){
  1010. var fieldConflict = false;
  1011. var elementConflict = false;
  1012. //if (this.json.moduleList[id]){
  1013. if( this.isModuleExited(id) ){
  1014. elementConflict = true;
  1015. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(this.json.moduleList[id].type)!=-1){
  1016. fieldConflict = true;
  1017. }
  1018. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1019. }
  1020. //if (this.subformList){
  1021. // Object.each(this.subformList, function(subform){
  1022. // if (!currentSubform || currentSubform!=subform.id){
  1023. // if (subform.moduleList[id]){
  1024. // elementConflict = true;
  1025. // if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  1026. // fieldConflict = true;
  1027. // }
  1028. // }
  1029. // }
  1030. // }.bind(this));
  1031. //}
  1032. var subformList = this.getAllSubformJsonObject();
  1033. if (subformList){
  1034. Object.each(subformList, function(subform){
  1035. if (!currentSubform || currentSubform!=subform.id){
  1036. if (subform.moduleList[id]){
  1037. elementConflict = true;
  1038. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  1039. fieldConflict = true;
  1040. }
  1041. }
  1042. }
  1043. }.bind(this));
  1044. }
  1045. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1046. },
  1047. _resetTreeNode: function(){},
  1048. clearSubformList : function( level1subformName ){
  1049. if( !this.level1Subformlist )return;
  1050. if( !this.level1Subformlist[level1subformName] )return;
  1051. delete this.level1Subformlist[level1subformName];
  1052. },
  1053. addSubformList : function( level1subformName, addedSubformId ){
  1054. if( !this.level1Subformlist ){
  1055. this.level1Subformlist = {};
  1056. }
  1057. if( !this.level1Subformlist[level1subformName] ){
  1058. this.level1Subformlist[level1subformName] = [];
  1059. }
  1060. this.level1Subformlist[level1subformName].push( addedSubformId );
  1061. },
  1062. isSubformUnique : function( checkedSubformId, level1subformName, deletedSubformId){
  1063. if( !this.level1Subformlist )return true;
  1064. var level1Subformlist = Object.clone( this.level1Subformlist );
  1065. if( deletedSubformId && level1Subformlist[deletedSubformId] )delete level1Subformlist[deletedSubformId];
  1066. for( var key in level1Subformlist ){
  1067. if( key !== level1subformName ){
  1068. if( level1Subformlist[key].contains( checkedSubformId ) ){
  1069. return false;
  1070. }
  1071. }
  1072. }
  1073. return true;
  1074. },
  1075. getAllSubformTiled : function(){
  1076. var _nestToTiled = function( form , array ){
  1077. if ( form.subformModuleList && form.subformModuleList.length){
  1078. Array.each( form.subformModuleList, function( module ){
  1079. array.push( module );
  1080. if( module.subformModule )_nestToTiled( module.subformModule, array );
  1081. }.bind(this))
  1082. }
  1083. };
  1084. var array = [];
  1085. _nestToTiled( this, array );
  1086. return array;
  1087. },
  1088. getAllSubformJsonObject : function(){
  1089. var list = this.getAllSubformTiled();
  1090. var object = {};
  1091. Array.each( list, function( subform ){
  1092. if( subform && subform.json.subformSelected && subform.subformData && subform.subformData.json){
  1093. object[ subform.json.subformSelected ] = subform.subformData.json;
  1094. }
  1095. }.bind(this));
  1096. return object;
  1097. }
  1098. // getAllFieldModuleNameList: function(){
  1099. // var moduleNameList = [];
  1100. // Object.each(this.json.moduleList, function(o, k){
  1101. // if (this.options.fields.indexOf(o.type))
  1102. // }.bind(this))
  1103. // }
  1104. });