Form.js 38 KB

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