Form.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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. },
  12. initialize: function(designer, container, options){
  13. this.setOptions(options);
  14. this.path = "/x_component_process_FormDesigner/Module/Form/";
  15. this.cssPath = "/x_component_process_FormDesigner/Module/Form/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.container = null;
  18. this.form = this;
  19. this.moduleType = "form";
  20. this.moduleList = [];
  21. this.moduleNodeList = [];
  22. this.moduleContainerNodeList = [];
  23. this.moduleElementNodeList = [];
  24. this.moduleComponentNodeList = [];
  25. // this.moduleContainerList = [];
  26. this.dataTemplate = {};
  27. this.designer = designer;
  28. this.container = container;
  29. this.selectedModules = [];
  30. },
  31. reload: function(data){
  32. this.moduleList.each(function(module){
  33. if (module.property){
  34. module.property.destroy();
  35. }
  36. }.bind(this));
  37. if (this.property) this.property.destroy();
  38. this.property = null;
  39. this.moduleList = [];
  40. this.moduleNodeList = [];
  41. this.moduleContainerNodeList = [];
  42. this.moduleElementNodeList = [];
  43. this.moduleComponentNodeList = [];
  44. this.dataTemplate = {};
  45. this.selectedModules = [];
  46. this.container.empty();
  47. if (this.treeNode){
  48. this.domTree.empty();
  49. this.domTree.node.destroy();
  50. this.domTree = null;
  51. this.treeNode = null;
  52. }
  53. this.currentSelectedModule = null;
  54. this.propertyMultiTd = null;
  55. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  56. this.load(data);
  57. this.selected();
  58. },
  59. load : function(data){
  60. this.data = data;
  61. this.json = data.json;
  62. this.html = data.html;
  63. this.json.mode = this.options.mode;
  64. if (!this.json.css) this.json.css = {"code":""};
  65. this.isNewForm = (this.json.id) ? false : true;
  66. if (this.isNewForm) this.checkUUID();
  67. if(this.designer.application) this.data.json.applicationName = this.designer.application.name;
  68. if(this.designer.application) this.data.json.application = this.designer.application.id;
  69. this.container.set("html", this.html);
  70. this.loadStylesList(function(){
  71. var oldStyleValue = "";
  72. if ((!this.json.formStyleType) || !this.stylesList[this.json.formStyleType]) this.json.formStyleType="blue-simple";
  73. if (this.options.mode=="Mobile"){
  74. if (this.json.formStyleType != "defaultMobile"){
  75. oldStyleValue = this.json.formStyleType;
  76. this.json.formStyleType = "defaultMobile";
  77. }
  78. }
  79. this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  80. this.loadDomModules();
  81. if (this.json.formStyleType){
  82. if (this.stylesList[this.json.formStyleType]){
  83. if (this.stylesList[this.json.formStyleType]["form"]){
  84. this.setTemplateStyles(this.stylesList[this.json.formStyleType]["form"]);
  85. }
  86. }
  87. }
  88. this.setCustomStyles();
  89. this.node.setProperties(this.json.properties);
  90. this.setNodeEvents();
  91. if (this.options.mode=="Mobile"){
  92. if (oldStyleValue) this._setEditStyle("formStyleType", null, oldStyleValue);
  93. }
  94. this.selected();
  95. this.autoSave();
  96. this.designer.addEvent("queryClose", function(){
  97. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  98. }.bind(this));
  99. }.bind(this));
  100. },
  101. removeStyles: function(from, to){
  102. if (this.json[to]){
  103. Object.each(from, function(style, key){
  104. if (this.json[to][key] && this.json[to][key]==style){
  105. delete this.json[to][key];
  106. }
  107. }.bind(this));
  108. }
  109. },
  110. copyStyles: function(from, to){
  111. if (!this.json[to]) this.json[to] = {};
  112. Object.each(from, function(style, key){
  113. if (!this.json[to][key]) this.json[to][key] = style;
  114. }.bind(this));
  115. },
  116. clearTemplateStyles: function(styles){
  117. if (styles){
  118. if (styles.styles) this.removeStyles(styles.styles, "styles");
  119. if (styles.properties) this.removeStyles(styles.properties, "properties");
  120. }
  121. },
  122. setTemplateStyles: function(styles){
  123. if (styles.styles) this.copyStyles(styles.styles, "styles");
  124. if (styles.properties) this.copyStyles(styles.properties, "properties");
  125. },
  126. loadStylesList: function(callback){
  127. //var stylesUrl = "/x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "mobileStyles": "styles")+".json";
  128. var stylesUrl = "/x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  129. MWF.getJSON(stylesUrl,{
  130. "onSuccess": function(responseJSON){
  131. this.stylesList= responseJSON;
  132. if (callback) callback(this.stylesList);
  133. }.bind(this),
  134. "onRequestFailure": function(){
  135. this.stylesList = {};
  136. if (callback) callback(this.stylesList);
  137. }.bind(this),
  138. "onError": function(){
  139. this.stylesList = {};
  140. if (callback) callback(this.stylesList);
  141. }.bind(this)
  142. }
  143. );
  144. },
  145. autoSave: function(){
  146. this.autoSaveCheckNode = this.designer.formToolbarNode.getElement("#MWFFormAutoSaveCheck");
  147. if (this.autoSaveCheckNode){
  148. this.autoSaveTimerID = window.setInterval(function(){
  149. if (this.autoSaveCheckNode.get("checked")){
  150. this.save();
  151. }
  152. }.bind(this), 60000);
  153. }
  154. },
  155. checkUUID: function(){
  156. this.designer.actions.getUUID(function(id){
  157. this.json.id = id;
  158. }.bind(this));
  159. },
  160. loadDomModules: function(){
  161. this.node = this.container.getFirst();
  162. this.node.set("id", this.json.id);
  163. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  164. this.node.store("module", this);
  165. var id = this.json.id.replace(/\-/g, "");
  166. this.node.addClass("css"+id);
  167. this.reloadCss();
  168. var y = this.container.getStyle("height");
  169. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  170. this.node.setStyle("min-height", ""+y+"px");
  171. this.designer.addEvent("resize", function(){
  172. var y = this.container.getStyle("height");
  173. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  174. this.node.setStyle("min-height", ""+y+"px");
  175. }.bind(this));
  176. this.loadDomTree();
  177. },
  178. loadDomTree: function(){
  179. MWF.require("MWF.widget.Tree", function(){
  180. this.domTree = new MWF.widget.Tree(this.designer.propertyDomArea, {"style": "domtree"});
  181. this.domTree.load();
  182. this.createFormTreeNode();
  183. this.parseModules(this, this.node);
  184. }.bind(this));
  185. },
  186. createFormTreeNode: function(){
  187. var text = "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ";
  188. var o = {
  189. "expand": true,
  190. "title": this.json.id,
  191. "text": "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ",
  192. "icon": (this.options.mode=="Mobile") ? "mobile.png": "pc.png"
  193. };
  194. o.action = function(){
  195. if (this.module) this.module.selected();
  196. };
  197. this.treeNode = this.domTree.appendChild(o);
  198. this.treeNode.setText(text);
  199. this.treeNode.module = this;
  200. },
  201. parseModules: function(parent, dom){
  202. var subDom = dom.getFirst();
  203. while (subDom){
  204. if (subDom.get("MWFtype")){
  205. // var module = subDom.retrieve("module");
  206. // alert(subDom.get("id")+": "+module);
  207. // if (!module){
  208. var json = this.getDomjson(subDom);
  209. module = this.loadModule(json, subDom, parent);
  210. // }
  211. // if (module.moduleType=="container") this.parseModules(module, subDom);
  212. // }else{
  213. // this.parseModules(parent, subDom);
  214. }
  215. // else if (subDom.getFirst()){
  216. // subDom = subDom.getFirst();
  217. // this.parseModules(parent, subDom);
  218. // }else{
  219. // subDom = subDom.getNext();
  220. // }
  221. subDom = subDom.getNext();
  222. }
  223. },
  224. getDomjson: function(dom){
  225. var mwfType = dom.get("MWFtype");
  226. switch (mwfType) {
  227. case "form":
  228. return this.json;
  229. case "":
  230. return null;
  231. default:
  232. var id = dom.get("id");
  233. if (id){
  234. return this.json.moduleList[id];
  235. }else{
  236. return null;
  237. }
  238. }
  239. },
  240. loadModule: function(json, dom, parent){
  241. if( MWF["FC"+json.type] ){
  242. var module = new MWF["FC"+json.type](this);
  243. module.load(json, dom, parent);
  244. //this.moduleList.push(module);
  245. return module;
  246. }else{
  247. var module = new MWF["FCDiv"](this);
  248. module.load(json, dom, parent);
  249. //this.moduleList.push(module);
  250. return module;
  251. }
  252. },
  253. setNodeEvents: function(){
  254. this.node.addEvent("click", function(e){
  255. this.selected();
  256. }.bind(this));
  257. },
  258. createModule: function(className, e){
  259. this.getTemplateData(className, function(data){
  260. var moduleData = Object.clone(data);
  261. var newTool = new MWF["FC"+className](this);
  262. newTool.create(moduleData, e);
  263. }.bind(this));
  264. },
  265. getTemplateData: function(className, callback , async){
  266. if (this.dataTemplate[className]){
  267. if (callback) callback(this.dataTemplate[className]);
  268. }else{
  269. var templateUrl = "/x_component_process_FormDesigner/Module/"+className+"/template.json";
  270. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  271. this.dataTemplate[className] = responseJSON;
  272. if (callback) callback(responseJSON);
  273. }.bind(this), async);
  274. }
  275. },
  276. selected: function(){
  277. if (this.currentSelectedModule){
  278. if (this.currentSelectedModule==this){
  279. return true;
  280. }else{
  281. this.currentSelectedModule.unSelected();
  282. }
  283. }
  284. if (this.propertyMultiTd){
  285. this.propertyMultiTd.hide();
  286. this.propertyMultiTd = null;
  287. }
  288. this.unSelectedMulti();
  289. this.currentSelectedModule = this;
  290. if (this.treeNode){
  291. this.treeNode.selectNode();
  292. }
  293. this.showProperty();
  294. // this.isFocus = true;
  295. },
  296. unSelectedMulti: function(){
  297. while (this.selectedModules.length){
  298. this.selectedModules[0].unSelectedMulti();
  299. }
  300. if (this.multimoduleActionsArea) this.multimoduleActionsArea.setStyle("display", "none");
  301. },
  302. unSelectAll: function(){
  303. },
  304. _beginSelectMulti: function(){
  305. if (this.currentSelectedModule) this.currentSelectedModule.unSelected();
  306. this.unSelectedMulti();
  307. this.noSelected = true;
  308. },
  309. _completeSelectMulti: function(){
  310. if (this.selectedModules.length<2){
  311. this.selectedModules[0].selected();
  312. }else{
  313. this._showMultiActions();
  314. }
  315. },
  316. createMultimoduleActionsArea: function(){
  317. this.multimoduleActionsArea = new Element("div", {
  318. styles: {
  319. "display": "none",
  320. // "width": 18*this.options.actions.length,
  321. "position": "absolute",
  322. "background-color": "#F1F1F1",
  323. "padding": "1px",
  324. "padding-right": "0px",
  325. "border": "1px solid #AAA",
  326. "box-shadow": "0px 2px 5px #999",
  327. "z-index": 10001
  328. }
  329. }).inject(this.form.container, "after");
  330. },
  331. _showMultiActions: function(){
  332. if (!this.multimoduleActionsArea) this.createMultimoduleActionsArea();
  333. var firstModule = this._getFirstMultiSelectedModule();
  334. if (firstModule){
  335. // var module = firstModule.module;
  336. var y = firstModule.position.y-25;
  337. var x = firstModule.position.x;
  338. this.multimoduleActionsArea.setPosition({"x": x, "y": y});
  339. this.multimoduleActionsArea.setStyle("display", "block");
  340. }
  341. },
  342. _getFirstMultiSelectedModule: function(){
  343. var firstModule = null;
  344. this.selectedModules.each(function(module){
  345. var position = module.node.getPosition(module.form.node.getOffsetParent());
  346. if (!firstModule){
  347. firstModule = {"module": module, "position": position};
  348. }else{
  349. if (position.y<firstModule.position.y){
  350. firstModule = {"module": module, "position": position};
  351. }else if (position.y==firstModule.position.y){
  352. if (position.x<firstModule.position.x){
  353. firstModule = {"module": module, "position": position};
  354. }
  355. }
  356. }
  357. });
  358. return firstModule;
  359. },
  360. showProperty: function(){
  361. if (!this.property){
  362. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  363. "path": this.options.propertyPath,
  364. "onPostLoad": function(){
  365. this.property.show();
  366. }.bind(this)
  367. });
  368. this.property.load();
  369. }else{
  370. this.property.show();
  371. }
  372. },
  373. hideProperty: function(){
  374. if (this.property) this.property.hide();
  375. },
  376. unSelected: function(){
  377. this.currentSelectedModule = null;
  378. this.hideProperty();
  379. },
  380. _dragIn: function(module){
  381. if (!this.Component) module.inContainer = this;
  382. module.parentContainer = this;
  383. this.node.setStyles({"border": "1px solid #ffa200"});
  384. var copyNode = module._getCopyNode();
  385. copyNode.inject(this.node);
  386. },
  387. _dragOut: function(module){
  388. module.inContainer = null;
  389. module.parentContainer = null;
  390. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  391. this.node.setStyles(this.json.styles);
  392. var copyNode = module._getCopyNode();
  393. copyNode.setStyle("display", "none");
  394. },
  395. _dragDrop: function(module){
  396. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  397. this.node.setStyles(this.json.styles);
  398. },
  399. _clearNoId: function(node){
  400. var subNode = node.getFirst();
  401. while (subNode){
  402. var nextNode = subNode.getNext();
  403. if (subNode.get("MWFType")){
  404. if (!subNode.get("id")){
  405. subNode.destroy();
  406. }else{
  407. if (subNode) this._clearNoId(subNode);
  408. }
  409. }else{
  410. if (subNode) this._clearNoId(subNode);
  411. }
  412. subNode = nextNode;
  413. }
  414. },
  415. _getFormData: function(){
  416. this.fireEvent("queryGetFormData");
  417. var copy = this.node.clone(true, true);
  418. copy.clearStyles(true);
  419. this.fireEvent("postGetFormData");
  420. this._clearNoId(copy);
  421. var html = copy.outerHTML;
  422. copy.destroy();
  423. this.data.json.mode = this.options.mode;
  424. this.data.html = html;
  425. return this.data;
  426. },
  427. preview: function(){
  428. MWF.xDesktop.requireApp("process.FormDesigner", "Preview", function(){
  429. if (this.options.mode=="Mobile"){
  430. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this, {"size": {"x": "400", "y": 580}, "mode": "mobile"});
  431. }else{
  432. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this);
  433. }
  434. this.previewBox.load();
  435. }.bind(this));
  436. },
  437. save: function(callback){
  438. // debugger;
  439. // this.moduleList.each(function(module){
  440. // if (module.moduleName==="subform"){
  441. // module.refreshSubform();
  442. // }
  443. // }.bind(this));
  444. this.designer.saveForm();
  445. //this._getFormData();
  446. //this.designer.actions.saveForm(this.data, function(responseJSON){
  447. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  448. //
  449. // //this.json.id = responseJSON.data;
  450. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  451. // this.treeNode.setTitle(this.json.id);
  452. // this.node.set("id", this.json.id);
  453. //
  454. // if (callback) callback();
  455. // //this.reload(responseJSON.data);
  456. //}.bind(this));
  457. },
  458. explode: function(){
  459. this._getFormData();
  460. MWF.require("MWF.widget.Base64", null, false);
  461. var data = MWF.widget.Base64.encode(JSON.encode(this.data));
  462. MWF.require("MWF.widget.Panel", function(){
  463. var node = new Element("div");
  464. var size = this.designer.formNode.getSize();
  465. var position = this.designer.formNode.getPosition(this.designer.formNode.getOffsetParent());
  466. var textarea = new Element("textarea", {
  467. "styles": {
  468. "border": "1px solid #999",
  469. "width": "770px",
  470. "margin-left": "14px",
  471. "margin-top": "14px",
  472. "height": "580px"
  473. },
  474. "text": JSON.encode(this.data)
  475. }).inject(node);
  476. this.explodePanel = new MWF.widget.Panel(node, {
  477. "style": "form",
  478. "isResize": false,
  479. "isMax": false,
  480. "title": "",
  481. "width": 800,
  482. "height": 660,
  483. "top": position.y,
  484. "left": position.x+3,
  485. "isExpand": false,
  486. "target": this.designer.node
  487. });
  488. this.explodePanel.load();
  489. }.bind(this));
  490. },
  491. implode: function(){
  492. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  493. MWF.FormImport.create("O2", this);
  494. }.bind(this));
  495. // MWF.require("MWF.widget.Panel", function(){
  496. // var node = new Element("div");
  497. // var size = this.designer.formNode.getSize();
  498. // var position = this.designer.formNode.getPosition(this.designer.formNode.getOffsetParent());
  499. //
  500. // var textarea = new Element("textarea", {
  501. // "styles": {
  502. // "border": "1px solid #999",
  503. // "width": "770px",
  504. // "margin-left": "14px",
  505. // "margin-top": "14px",
  506. // "height": "540px"
  507. // }
  508. // }).inject(node);
  509. // var button = new Element("div", {
  510. // "styles": {
  511. // "margin": "10px auto",
  512. // "width": "100px",
  513. // "border-radius": "8px",
  514. // "height": "30px",
  515. // "line-height": "30px",
  516. // "text-align": "center",
  517. // "cursor": "pointer",
  518. // "color": "#ffffff",
  519. // "background-color": "#4c6b87"
  520. // },
  521. // "text": "OK"
  522. // }).inject(node);
  523. // button.addEvent("click", function(e){
  524. // var _self = this;
  525. // this.designer.confirm("warn", e, this.designer.lp.implodeConfirmTitle, this.designer.lp.implodeConfirmText, 300, 120, function(){
  526. // var str = textarea.get("value");
  527. // _self.implodeJsonData(str);
  528. // this.close();
  529. // }, function(){
  530. // this.close();
  531. // });
  532. // }.bind(this));
  533. //
  534. // this.implodePanel = new MWF.widget.Panel(node, {
  535. // "style": "page",
  536. // "isResize": false,
  537. // "isMax": false,
  538. // "title": "",
  539. // "width": 800,
  540. // "height": 660,
  541. // "top": position.y,
  542. // "left": position.x+3,
  543. // "isExpand": false,
  544. // "target": this.designer.node
  545. // });
  546. //
  547. // this.implodePanel.load();
  548. // }.bind(this));
  549. },
  550. // implodeJsonData: function(str){
  551. // if (str){
  552. // //try{
  553. // debugger;
  554. // var data = JSON.decode(str);
  555. // if (data){
  556. // var json = data.json;
  557. // data.id = this.data.id;
  558. // data.isNewPage = this.data.isNewPage;
  559. // json.id = this.json.id;
  560. // json.name = this.json.name;
  561. // json.application = this.json.application;
  562. // json.applicationName = this.json.applicationName;
  563. //
  564. // this.reload(data);
  565. // this.implodePanel.closePanel();
  566. // }else{
  567. // this.designer.notice(this.designer.lp.implodeError, "error");
  568. // }
  569. // // }catch(e){
  570. // // this.designer.notice(this.designer.lp.implodeError, "error");
  571. // // }
  572. // }else{
  573. // this.designer.notice(this.designer.lp.implodeEmpty, "error");
  574. // }
  575. // },
  576. implodeHTML: function(){
  577. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  578. MWF.FormImport.create("html", this);
  579. }.bind(this));
  580. },
  581. implodeOffice: function(){
  582. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  583. MWF.FormImport.create("office", this);
  584. }.bind(this));
  585. },
  586. setPropertiesOrStyles: function(name){
  587. if (name=="styles"){
  588. this.setCustomStyles();
  589. }
  590. if (name=="properties"){
  591. this.node.setProperties(this.json.properties);
  592. }
  593. },
  594. setCustomStyles: function(){
  595. var border = this.node.getStyle("border");
  596. this.node.clearStyles();
  597. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  598. var y = this.container.getStyle("height");
  599. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  600. this.node.setStyle("min-height", ""+y+"px");
  601. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  602. this.node.setStyle("border", border);
  603. Object.each(this.json.styles, function(value, key){
  604. var reg = /^border\w*/ig;
  605. if (!key.test(reg)){
  606. this.node.setStyle(key, value);
  607. }
  608. }.bind(this));
  609. },
  610. _setEditStyle: function(name, obj, oldValue){
  611. if (name=="name"){
  612. var title = this.json.name || this.json.id;
  613. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  614. }
  615. if (name=="id"){
  616. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  617. this.treeNode.setTitle(this.json.id);
  618. this.node.set("id", this.json.id);
  619. }
  620. if (name=="formStyleType"){
  621. this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  622. if (oldValue) {
  623. var oldTemplateStyles = this.stylesList[oldValue];
  624. if (oldTemplateStyles){
  625. if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  626. }
  627. }
  628. if (this.templateStyles){
  629. if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  630. }
  631. this.setAllStyles();
  632. this.moduleList.each(function(module){
  633. if (oldTemplateStyles){
  634. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  635. }
  636. module.setStyleTemplate();
  637. module.setAllStyles();
  638. }.bind(this));
  639. }
  640. if (name==="css"){
  641. this.reloadCss();
  642. }
  643. this._setEditStyle_custom(name, obj, oldValue);
  644. },
  645. reloadCss: function(){
  646. cssText = (this.json.css) ? this.json.css.code : "";
  647. //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement);
  648. var styleNode = $("style"+this.json.id);
  649. if (styleNode) styleNode.destroy();
  650. if (cssText){
  651. var rex = new RegExp("(.+)(?=\\{)", "g");
  652. var match;
  653. var id = this.json.id.replace(/\-/g, "");
  654. while ((match = rex.exec(cssText)) !== null) {
  655. var prefix = ".css" + id + " ";
  656. var rule = prefix + match[0];
  657. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  658. rex.lastIndex = rex.lastIndex + prefix.length;
  659. }
  660. var styleNode = document.createElement("style");
  661. styleNode.setAttribute("type", "text/css");
  662. styleNode.id="style"+this.json.id;
  663. styleNode.inject(this.container, "before");
  664. if(styleNode.styleSheet){
  665. var setFunc = function(){
  666. styleNode.styleSheet.cssText = cssText;
  667. };
  668. if(styleNode.styleSheet.disabled){
  669. setTimeout(setFunc, 10);
  670. }else{
  671. setFunc();
  672. }
  673. }else{
  674. var cssTextNode = document.createTextNode(cssText);
  675. styleNode.appendChild(cssTextNode);
  676. }
  677. }
  678. },
  679. setAllStyles: function(){
  680. this.setPropertiesOrStyles("styles");
  681. this.setPropertiesOrStyles("properties");
  682. this.reloadMaplist();
  683. },
  684. reloadMaplist: function(){
  685. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  686. },
  687. _setEditStyle_custom: function(){
  688. },
  689. saveAsTemplete: function(){
  690. },
  691. checkModuleId: function(id, type, currentSubform){
  692. var fieldConflict = false;
  693. var elementConflict = false;
  694. if (this.json.moduleList[id]){
  695. elementConflict = true;
  696. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(this.json.moduleList[id].type)!=-1){
  697. fieldConflict = true;
  698. }
  699. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  700. }
  701. if (this.subformList){
  702. Object.each(this.subformList, function(subform){
  703. if (!currentSubform || currentSubform!=subform.id){
  704. if (subform.moduleList[id]){
  705. elementConflict = true;
  706. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  707. fieldConflict = true;
  708. }
  709. }
  710. }
  711. }.bind(this));
  712. }
  713. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  714. },
  715. _resetTreeNode: function(){}
  716. // getAllFieldModuleNameList: function(){
  717. // var moduleNameList = [];
  718. // Object.each(this.json.moduleList, function(o, k){
  719. // if (this.options.fields.indexOf(o.type))
  720. // }.bind(this))
  721. // }
  722. });