Form.js 36 KB

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