Form.js 40 KB

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