Form.js 40 KB

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