Form.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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 moduleNodes = [];
  306. var subDom = dom.getFirst();
  307. while (subDom){
  308. if (subDom.get("MWFtype")){
  309. // var module = subDom.retrieve("module");
  310. // alert(subDom.get("id")+": "+module);
  311. // if (!module){
  312. var json = this.getDomjson(subDom);
  313. var moduleNode = subDom;
  314. moduleNodes.push({"dom": moduleNode, "json": json});
  315. //module = this.loadModule(json, subDom, parent);
  316. // }
  317. // if (module.moduleType=="container") this.parseModules(module, subDom);
  318. // }else{
  319. // this.parseModules(parent, subDom);
  320. }
  321. // else if (subDom.getFirst()){
  322. // subDom = subDom.getFirst();
  323. // this.parseModules(parent, subDom);
  324. // }else{
  325. // subDom = subDom.getNext();
  326. // }
  327. subDom = subDom.getNext();
  328. }
  329. moduleNodes.each(function(obj){
  330. module = this.loadModule(obj.json, obj.dom, parent);
  331. }.bind(this));
  332. },
  333. getDomjson: function(dom){
  334. var mwfType = dom.get("MWFtype");
  335. switch (mwfType) {
  336. case "form":
  337. return this.json;
  338. case "":
  339. return null;
  340. default:
  341. var id = dom.get("id");
  342. if (id){
  343. return this.json.moduleList[id];
  344. }else{
  345. return null;
  346. }
  347. }
  348. },
  349. loadModule: function(json, dom, parent){
  350. if( !json ){
  351. var module;
  352. var className = ( dom.get("MWFType") || "div" ).capitalize();
  353. this.getTemplateData(className, function(data){
  354. var moduleData = Object.clone(data);
  355. moduleData.id = dom.get("id");
  356. this.json.moduleList[dom.get("id")] = moduleData;
  357. module = new MWF["FC"+className](this);
  358. module.load(moduleData, dom, parent);
  359. }.bind(this), false);
  360. return module;
  361. }else if( MWF["FC"+json.type] ){
  362. var module;
  363. var className = json.type.capitalize();
  364. this.getTemplateData(className, function(data){
  365. var moduleData = Object.clone(data);
  366. Object.merge(moduleData, json);
  367. Object.merge(json, moduleData);
  368. module = new MWF["FC"+json.type](this);
  369. module.load(json, dom, parent);
  370. }.bind(this), false);
  371. return module;
  372. }else{
  373. var module;
  374. var className = json.type.capitalize();
  375. this.getTemplateData(className, function(data){
  376. var moduleData = Object.clone(data);
  377. Object.merge(moduleData, json);
  378. Object.merge(json, moduleData);
  379. module = new MWF["FCDiv"](this);
  380. module.load(json, dom, parent);
  381. }.bind(this), false);
  382. return module;
  383. }
  384. },
  385. setNodeEvents: function(){
  386. this.node.addEvent("click", function(e){
  387. this.selected();
  388. }.bind(this));
  389. // this._controlKeyEventFun = function(e){
  390. // if (e.control){
  391. // this.controlMode = true;
  392. // if (this.copyNode) this.copyNode.destroy();
  393. // }else{
  394. // this.controlMode = false;
  395. // // var copyNode = this._getCopyNode(this);
  396. // // copyNode.inject(this.node, "before");
  397. // }
  398. // }.bind(this);
  399. this.designer.content.addEvent("keydown", function(e){
  400. if (this.moveModule){
  401. if (e.control){
  402. this.moveModule._setControlMode(true);
  403. }else{
  404. this.moveModule._setControlMode(false);
  405. }
  406. }
  407. }.bind(this));
  408. this.designer.content.addEvent("keyup", function(e){
  409. if (this.moveModule){
  410. if (e.control){
  411. this.moveModule._setControlMode(true);
  412. }else{
  413. this.moveModule._setControlMode(false);
  414. }
  415. }
  416. }.bind(this));
  417. },
  418. createModuleImmediately: function( className, parentModule, relativeNode, position, selectDisabled, async ){
  419. var module;
  420. this.getTemplateData(className, function(data){
  421. var moduleData = Object.clone(data);
  422. module = new MWF["PC"+className](this);
  423. if( parentModule ){
  424. module.onDragModule = parentModule;
  425. if (!parentModule.Component) module.inContainer = parentModule;
  426. module.parentContainer = parentModule;
  427. module.nextModule = null;
  428. }
  429. module.createImmediately(moduleData, relativeNode, position, selectDisabled);
  430. }.bind(this), async);
  431. return module;
  432. },
  433. createModule: function(className, e){
  434. this.getTemplateData(className, function(data){
  435. var moduleData = Object.clone(data);
  436. var newTool = new MWF["FC"+className](this);
  437. newTool.create(moduleData, e);
  438. }.bind(this));
  439. },
  440. getTemplateData: function(className, callback , async){
  441. if (this.dataTemplate[className]){
  442. if (callback) callback(this.dataTemplate[className]);
  443. }else{
  444. var templateUrl = "../x_component_process_FormDesigner/Module/"+className+"/template.json";
  445. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  446. this.dataTemplate[className] = responseJSON;
  447. if (callback) callback(responseJSON);
  448. }.bind(this), async);
  449. }
  450. },
  451. selected: function(){
  452. if (this.currentSelectedModule){
  453. if (this.currentSelectedModule==this){
  454. return true;
  455. }else{
  456. this.currentSelectedModule.unSelected();
  457. }
  458. }
  459. if (this.propertyMultiTd){
  460. this.propertyMultiTd.hide();
  461. this.propertyMultiTd = null;
  462. }
  463. this.unSelectedMulti();
  464. this.currentSelectedModule = this;
  465. if (this.treeNode){
  466. this.treeNode.selectNode();
  467. }
  468. this.showProperty();
  469. // this.isFocus = true;
  470. },
  471. unSelectedMulti: function(){
  472. while (this.selectedModules.length){
  473. this.selectedModules[0].unSelectedMulti();
  474. }
  475. if (this.multimoduleActionsArea) this.multimoduleActionsArea.setStyle("display", "none");
  476. },
  477. unSelectAll: function(){
  478. },
  479. _beginSelectMulti: function(){
  480. if (this.currentSelectedModule) this.currentSelectedModule.unSelected();
  481. this.unSelectedMulti();
  482. this.noSelected = true;
  483. },
  484. _completeSelectMulti: function(){
  485. if (this.selectedModules.length<2){
  486. this.selectedModules[0].selected();
  487. }else{
  488. this._showMultiActions();
  489. }
  490. },
  491. createMultimoduleActionsArea: function(){
  492. this.multimoduleActionsArea = new Element("div", {
  493. styles: {
  494. "display": "none",
  495. // "width": 18*this.options.actions.length,
  496. "position": "absolute",
  497. "background-color": "#F1F1F1",
  498. "padding": "1px",
  499. "padding-right": "0px",
  500. "border": "1px solid #AAA",
  501. "box-shadow": "0px 2px 5px #999",
  502. "z-index": 10001
  503. }
  504. }).inject(this.form.container, "after");
  505. },
  506. _showMultiActions: function(){
  507. if (!this.multimoduleActionsArea) this.createMultimoduleActionsArea();
  508. var firstModule = this._getFirstMultiSelectedModule();
  509. if (firstModule){
  510. // var module = firstModule.module;
  511. var y = firstModule.position.y-25;
  512. var x = firstModule.position.x;
  513. this.multimoduleActionsArea.setPosition({"x": x, "y": y});
  514. this.multimoduleActionsArea.setStyle("display", "block");
  515. }
  516. },
  517. _getFirstMultiSelectedModule: function(){
  518. var firstModule = null;
  519. this.selectedModules.each(function(module){
  520. var position = module.node.getPosition(module.form.node.getOffsetParent());
  521. if (!firstModule){
  522. firstModule = {"module": module, "position": position};
  523. }else{
  524. if (position.y<firstModule.position.y){
  525. firstModule = {"module": module, "position": position};
  526. }else if (position.y==firstModule.position.y){
  527. if (position.x<firstModule.position.x){
  528. firstModule = {"module": module, "position": position};
  529. }
  530. }
  531. }
  532. });
  533. return firstModule;
  534. },
  535. showProperty: function(){
  536. if (!this.property){
  537. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  538. "path": this.options.propertyPath,
  539. "onPostLoad": function(){
  540. this.property.show();
  541. }.bind(this)
  542. });
  543. this.property.load();
  544. }else{
  545. this.property.show();
  546. }
  547. },
  548. hideProperty: function(){
  549. if (this.property) this.property.hide();
  550. },
  551. unSelected: function(){
  552. this.currentSelectedModule = null;
  553. this.hideProperty();
  554. },
  555. _dragIn: function(module){
  556. if (!this.Component) module.inContainer = this;
  557. module.parentContainer = this;
  558. this.node.setStyles({"border": "1px solid #ffa200"});
  559. var copyNode = module._getCopyNode();
  560. copyNode.inject(this.node);
  561. },
  562. _dragOut: function(module){
  563. module.inContainer = null;
  564. module.parentContainer = null;
  565. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  566. this.node.setStyles(this.json.styles);
  567. var copyNode = module._getCopyNode();
  568. copyNode.setStyle("display", "none");
  569. },
  570. _dragDrop: function(module, flag){
  571. var f = flag || !(new Event(event)).control;
  572. if( f ){
  573. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  574. this.node.setStyles(this.json.styles);
  575. }
  576. //this._hideInjectAction();
  577. },
  578. _showInjectAction : function( module ){
  579. if ( module.moveNode ){
  580. module.moveNode.setStyle("display","none");
  581. }
  582. //debugger;
  583. this.draggingModule = module;
  584. //if( !this.node.getFirst() ){
  585. // this.inject( "top" );
  586. // return;
  587. //}
  588. if( !this.injectActionArea )this._createInjectAction();
  589. this.injectActionArea.setStyle("display","block");
  590. this._setInjectActionAreaPosition();
  591. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  592. duration: 200,
  593. transition: Fx.Transitions.Sine.easeOut
  594. });
  595. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  596. },
  597. _hideInjectAction : function(){
  598. this.draggingModule = null;
  599. if( this.injectActionArea ){
  600. this.injectActionArea.setStyle("display","none");
  601. }
  602. },
  603. _createInjectAction : function(){
  604. var css = this.form.css;
  605. if( !this.injectActionArea ){
  606. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  607. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  608. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  609. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  610. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  611. var injectActions = {};
  612. this.options.injectActions.each( function( action ){
  613. injectActions[ action.name ] = action;
  614. });
  615. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  616. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  617. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  618. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  619. new Element("div", {
  620. styles : css.injectActionCancelNode,
  621. events : {
  622. click : function(){
  623. this.draggingModule._dragCancel();
  624. this._dragDrop( this.node, true );
  625. this._hideInjectAction();
  626. }.bind(this),
  627. mouseover : function(){
  628. this.setStyles( css.injectActionCancelNode_over )
  629. },
  630. mouseout : function(){
  631. this.setStyles( css.injectActionCancelNode )
  632. }
  633. }
  634. }).inject(this.injectActionArea);
  635. }
  636. },
  637. _createInjectActionNode : function( action, relativeNode ){
  638. var actionNode = new Element("div", {
  639. "styles": this.css[action.styles],
  640. "title": action.title
  641. }).inject( this.injectActionArea );
  642. actionNode.addEvent(action.event, function(e){
  643. this[action.action](e);
  644. }.bind(this));
  645. actionNode.addEvents({
  646. "mouseover": function(e){
  647. relativeNode.setStyle("background", "#ddd");
  648. this.draggingModule.copyNode.setStyle("display","");
  649. this.draggingModule.copyNode.inject( this.node, action.name );
  650. }.bind(this),
  651. "mouseout": function(e){
  652. relativeNode.setStyle("background", "transparent");
  653. }.bind(this)
  654. });
  655. relativeNode.set("title",action.title);
  656. relativeNode.addEvent(action.event, function(e){
  657. this[action.action](e);
  658. }.bind(this));
  659. relativeNode.setStyle("cursor","pointer");
  660. relativeNode.addEvents({
  661. "mouseenter": function(e){
  662. relativeNode.setStyle("background", "#ddd");
  663. this.draggingModule.copyNode.setStyle("display","");
  664. this.draggingModule.copyNode.inject( this.node, action.name );
  665. }.bind(this),
  666. "mouseleave": function(e){
  667. relativeNode.setStyle("background", "transparent");
  668. //this.draggingModule.copyNode.setStyle("display","none");
  669. }.bind(this)
  670. });
  671. },
  672. _setInjectActionAreaPosition: function(){
  673. var e = new Event(event);
  674. var formOffset = this.node.getOffsetParent().getPosition();
  675. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  676. var y = e.page.y - formOffset.y - 60;
  677. var x = e.page.x - formOffset.x - 60;
  678. this.injectActionArea.setPosition({"x": x, "y": y});
  679. },
  680. injectBefore : function( e ){
  681. this.inject( "before" )
  682. },
  683. injectAfter : function( e ){
  684. this.inject( "after" )
  685. },
  686. injectTop : function( e ){
  687. this.inject( "top" )
  688. },
  689. injectBottom : function( e ){
  690. this.inject( "bottom" )
  691. },
  692. inject : function( position ){
  693. if ( this.draggingModule.moveNode ){
  694. this.draggingModule.moveNode.setStyle("display","");
  695. }
  696. this.draggingModule._dragComplete( this.node, position );
  697. this._dragDrop( this.node, true );
  698. this._hideInjectAction();
  699. },
  700. // _clearSubform: function(node){
  701. // var subNode = node.getFirst();
  702. // while (subNode){
  703. // var nextNode = subNode.getNext();
  704. // if (subNode.get("MWFType")){
  705. // if ( subNode.get("MWFType") === "subform" ){
  706. // subNode.destroy();
  707. // }else{
  708. // if (subNode) this._clearSubform(subNode);
  709. // }
  710. // }else{
  711. // if (subNode) this._clearSubform(subNode);
  712. // }
  713. // subNode = nextNode;
  714. // }
  715. // },
  716. _clearNoId: function(node){
  717. var subNode = node.getFirst();
  718. while (subNode){
  719. var nextNode = subNode.getNext();
  720. if (subNode.get("MWFType")){
  721. if (!subNode.get("id")){
  722. subNode.destroy();
  723. }else{
  724. if (subNode) this._clearNoId(subNode);
  725. }
  726. }else{
  727. if (subNode) this._clearNoId(subNode);
  728. }
  729. subNode = nextNode;
  730. }
  731. },
  732. _copyFormJson: function(initial, final){
  733. var data = final || {};
  734. Object.keys(initial).each(function(k){
  735. var t = typeOf(initial[k]);
  736. switch (t) {
  737. case "object":
  738. var s = JSON.stringify(initial[k], null, "\t");
  739. if (/((?:\:\s*)((\".+\")|(\d+)|(\[.+\])))/.test(s)){
  740. //data[k] = {};
  741. data[k] = this._copyFormJson(initial[k], data[k]);
  742. }
  743. break;
  744. case "boolean":
  745. data[k] = initial[k];
  746. break;
  747. default :
  748. if (initial[k]) data[k] = initial[k];
  749. }
  750. }.bind(this));
  751. return data;
  752. },
  753. _preprocessingModuleData: function(){
  754. //var html = this.node.innerHTML;
  755. this.moduleList.each(function(module){
  756. module._preprocessingModuleData();
  757. });
  758. // return {
  759. // "json": this.data.json,
  760. // "html": this.node.outerHTML
  761. // }
  762. },
  763. _recoveryModuleData: function(){
  764. this.moduleList.each(function(module){
  765. //module._recoveryModuleData();
  766. module.setCustomStyles();
  767. if (module.setCustomInputStyles) module.setCustomInputStyles();
  768. });
  769. },
  770. _getFormData: function(callback){
  771. debugger;
  772. this.fireEvent("queryGetFormData");
  773. this._preprocessingModuleData();
  774. var copy = this.node.clone(true, true);
  775. copy.clearStyles();
  776. this.fireEvent("postGetFormData");
  777. this._clearNoId(copy);
  778. var html = copy.outerHTML;
  779. //this._clearNoDomModule();
  780. copy.destroy();
  781. this.data.json.mode = this.options.mode;
  782. this.data.html = html;
  783. debugger;
  784. var data = this._copyFormJson(this.data);
  785. this._recoveryModuleData();
  786. //@todo 预先整理表单样式
  787. // var tmpFormNode = new Element("div", {
  788. // "opacity": 0
  789. // }).inject(this.designer.content);
  790. // MWF.xDesktop.requireApp("process.Xform2", "Form_", null, false);
  791. // this.appForm = new MWF.APPForm_(tmpFormNode, this.data, {
  792. // "onAfterLoad": function(){
  793. // var preprocessHtml = tmpFormNode.get("html");
  794. // this.data.preprocessHtml = preprocessHtml;
  795. //
  796. // if (callback) callback();
  797. // }.bind(this)
  798. // });
  799. // this.appForm.businessData = {};
  800. // this.appForm.load();
  801. return data;
  802. //return this.data;
  803. },
  804. _clearNoDomModule : function(){
  805. debugger;
  806. var existModuleList = {};
  807. Object.each( this.moduleList, function( module ){
  808. existModuleList[ module.json.id ] = true;
  809. });
  810. Object.each( this.data.json.moduleList , function( module, key ){
  811. //if( !this.node.getElement( "#" + module.id ) && !existModuleList[ module.id ] ){
  812. if( !existModuleList[ module.id ] ){
  813. delete this.data.json.moduleList[key];
  814. }
  815. }.bind(this));
  816. },
  817. preview: function(){
  818. MWF.xDesktop.requireApp("process.FormDesigner", "Preview", function(){
  819. if (this.options.mode=="Mobile"){
  820. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this, {"size": {"x": "400", "y": 580}, "mode": "mobile"});
  821. }else{
  822. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this);
  823. }
  824. this.previewBox.load();
  825. }.bind(this));
  826. },
  827. save: function(callback){
  828. // debugger;
  829. // this.moduleList.each(function(module){
  830. // if (module.moduleName==="subform"){
  831. // module.refreshSubform();
  832. // }
  833. // }.bind(this));
  834. this.designer.saveForm();
  835. //this._getFormData();
  836. //this.designer.actions.saveForm(this.data, function(responseJSON){
  837. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  838. //
  839. // //this.json.id = responseJSON.data;
  840. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  841. // this.treeNode.setTitle(this.json.id);
  842. // this.node.set("id", this.json.id);
  843. //
  844. // if (callback) callback();
  845. // //this.reload(responseJSON.data);
  846. //}.bind(this));
  847. },
  848. explode: function(){
  849. this._getFormData();
  850. MWF.require("MWF.widget.Base64", null, false);
  851. var data = MWF.widget.Base64.encode(JSON.encode(this.data));
  852. MWF.require("MWF.widget.Panel", function(){
  853. var node = new Element("div");
  854. var size = this.designer.formNode.getSize();
  855. var position = this.designer.formNode.getPosition(this.designer.formNode.getOffsetParent());
  856. var textarea = new Element("textarea", {
  857. "styles": {
  858. "border": "1px solid #999",
  859. "width": "770px",
  860. "margin-left": "14px",
  861. "margin-top": "14px",
  862. "height": "580px"
  863. },
  864. "text": JSON.encode(this.data)
  865. }).inject(node);
  866. this.explodePanel = new MWF.widget.Panel(node, {
  867. "style": "form",
  868. "isResize": false,
  869. "isMax": false,
  870. "title": "",
  871. "width": 800,
  872. "height": 660,
  873. "top": position.y,
  874. "left": position.x+3,
  875. "isExpand": false,
  876. "target": this.designer.node
  877. });
  878. this.explodePanel.load();
  879. }.bind(this));
  880. },
  881. implode: function(){
  882. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  883. MWF.FormImport.create("O2", this);
  884. }.bind(this));
  885. },
  886. // implodeJsonData: function(str){
  887. // if (str){
  888. // //try{
  889. // debugger;
  890. // var data = JSON.decode(str);
  891. // if (data){
  892. // var json = data.json;
  893. // data.id = this.data.id;
  894. // data.isNewPage = this.data.isNewPage;
  895. // json.id = this.json.id;
  896. // json.name = this.json.name;
  897. // json.application = this.json.application;
  898. // json.applicationName = this.json.applicationName;
  899. //
  900. // this.reload(data);
  901. // this.implodePanel.closePanel();
  902. // }else{
  903. // this.designer.notice(this.designer.lp.implodeError, "error");
  904. // }
  905. // // }catch(e){
  906. // // this.designer.notice(this.designer.lp.implodeError, "error");
  907. // // }
  908. // }else{
  909. // this.designer.notice(this.designer.lp.implodeEmpty, "error");
  910. // }
  911. // },
  912. implodeHTML: function(){
  913. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  914. MWF.FormImport.create("html", this, {"type": "process"});
  915. }.bind(this));
  916. },
  917. implodeOffice: function(){
  918. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  919. MWF.FormImport.create("office", this);
  920. }.bind(this));
  921. },
  922. showFormVersion: function(){
  923. this.versionNode = new Element("div");
  924. this.dlg = o2.DL.open({
  925. "title": MWF.APPFD.LP.version["title"],
  926. "content": this.versionNode,
  927. "offset": {"y": -100},
  928. "isMax": false,
  929. "width": 500,
  930. "height": 300,
  931. "buttonList": [
  932. {
  933. "type": "cancel",
  934. "text": MWF.APPFD.LP.version["close"],
  935. "action": function(){ this.close(); }
  936. }
  937. ],
  938. "onPostShow": function(){
  939. this.loadVersionList();
  940. }.bind(this),
  941. "onPostClose": function(){
  942. this.dlg = null;
  943. }.bind(this)
  944. });
  945. },
  946. loadVersionList : function(){
  947. var tableHtml = "<table width='100%' cellspacing='0' cellpadding='3' style='margin-top: 1px'><tr>" +
  948. "<th>"+MWF.APPFD.LP.version["no"]+"</th>" +
  949. "<th>"+MWF.APPFD.LP.version["updateTime"]+"</th>" +
  950. "<th>"+MWF.APPFD.LP.version["op"]+"</th>" +
  951. "</tr></table>";
  952. this.versionNode.set("html", tableHtml);
  953. this.versionTable = this.versionNode.getElement("table");
  954. this.action = o2.Actions.load("x_processplatform_assemble_designer");
  955. this.action.FormVersionAction.listWithForm(this.form.json.id, function(json){
  956. this.versionList = json.data;
  957. this.versionList.each(function (version,index) {
  958. var node = new Element("tr").inject(this.versionTable);
  959. var html = "<td>"+(index+1)+"</td>" +
  960. "<td>"+version.updateTime+"</td>" +
  961. "<td></td>";
  962. node.set("html", html);
  963. var actionNode = new Element("div",{"styles":{
  964. "width": "30px",
  965. "padding": "0px 3px",
  966. "border-radius": "20px",
  967. "cursor" : "pointer",
  968. "color": "#ffffff",
  969. "background-color": "#4A90E2",
  970. "float": "left",
  971. "margin-right": "2px",
  972. "text-align": "center",
  973. "font-weight": "100"
  974. }}).inject(node.getLast("td"));
  975. actionNode.set("text", MWF.APPFD.LP.version["resume"]);
  976. actionNode.addEvent("click",function (e) {
  977. var _self = this;
  978. this.designer.confirm("warn", e, MWF.APPFD.LP.version["resumeConfirm"], MWF.APPFD.LP.version["resumeInfo"], 460, 120, function(){
  979. _self.resumeForm(version);
  980. this.close();
  981. }, function(){
  982. this.close();
  983. });
  984. }.bind(this));
  985. }.bind(this))
  986. }.bind(this));
  987. },
  988. resumeForm : function(version){
  989. this.action.FormVersionAction.get(version.id, function( json ){
  990. var formData = JSON.parse(json.data.data);
  991. //this.action.FormAction.update(version.form, formData,function( json ){
  992. this.designer.notice(MWF.APPFD.LP.version["resumeSuccess"]);
  993. this.reload(JSON.decode(MWF.decodeJsonString(formData.data)));
  994. this.dlg.close();
  995. //}.bind(this), null, false);
  996. }.bind(this), null, false);
  997. },
  998. deletePropertiesOrStyles: function(name, key){
  999. if (name=="styles"){
  1000. try{
  1001. if( key && this.json.styles[key] ){
  1002. delete this.json.styles[key];
  1003. }
  1004. this.setCustomStyles();
  1005. }catch(e){}
  1006. }
  1007. if (name=="properties"){
  1008. try{
  1009. this.node.removeProperty(key);
  1010. }catch(e){}
  1011. }
  1012. },
  1013. setPropertiesOrStyles: function(name){
  1014. if (name=="styles"){
  1015. this.setCustomStyles();
  1016. }
  1017. if (name=="properties"){
  1018. this.node.setProperties(this.json.properties);
  1019. }
  1020. },
  1021. setCustomStyles: function(){
  1022. var border = this.node.getStyle("border");
  1023. this.node.clearStyles();
  1024. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  1025. var y = this.container.getStyle("height");
  1026. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  1027. this.node.setStyle("min-height", ""+y+"px");
  1028. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  1029. this.node.setStyle("border", border);
  1030. Object.each(this.json.styles, function(value, key){
  1031. var reg = /^border\w*/ig;
  1032. if (!key.test(reg)){
  1033. this.node.setStyle(key, value);
  1034. }
  1035. }.bind(this));
  1036. },
  1037. _setEditStyle: function(name, obj, oldValue){
  1038. if (name=="name"){
  1039. var title = this.json.name || this.json.id;
  1040. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  1041. }
  1042. if (name=="id"){
  1043. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  1044. this.treeNode.setTitle(this.json.id);
  1045. this.node.set("id", this.json.id);
  1046. }
  1047. if (name=="formStyleType"){
  1048. var file = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].file : null;
  1049. var extendFile = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].extendFile : null;
  1050. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  1051. //this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  1052. this.templateStyles = templateStyles;
  1053. var oldFile, oldExtendFile;
  1054. if( oldValue && this.stylesList[oldValue] ){
  1055. oldFile = this.stylesList[oldValue].file;
  1056. oldExtendFile = this.stylesList[oldValue].extendFile;
  1057. }
  1058. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  1059. //if (oldValue) {
  1060. // var oldTemplateStyles = this.stylesList[oldValue];
  1061. // if (oldTemplateStyles){
  1062. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  1063. // }
  1064. //}
  1065. this.json.styleConfig = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  1066. if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  1067. if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  1068. this.setAllStyles();
  1069. this.moduleList.each(function(module){
  1070. if (oldTemplateStyles[module.moduleName]){
  1071. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1072. }
  1073. module.setStyleTemplate();
  1074. module.setAllStyles();
  1075. }.bind(this));
  1076. }.bind(this))
  1077. }.bind(this))
  1078. }
  1079. if (name==="css"){
  1080. this.reloadCss();
  1081. }
  1082. this._setEditStyle_custom(name, obj, oldValue);
  1083. },
  1084. parseCSS: function(css){
  1085. var rex = /(url\(.*\))/g;
  1086. var match;
  1087. while ((match = rex.exec(css)) !== null) {
  1088. var pic = match[0];
  1089. var len = pic.length;
  1090. var s = pic.substring(pic.length-2, pic.length-1);
  1091. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  1092. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  1093. pic = pic.substring(n0, pic.length-n1);
  1094. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  1095. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1096. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1097. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  1098. pic = pic.replace("/x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  1099. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  1100. pic = pic.replace("x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  1101. }
  1102. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  1103. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1104. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  1105. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1106. }
  1107. }
  1108. pic = "url('"+pic+"')";
  1109. var len2 = pic.length;
  1110. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  1111. rex.lastIndex = rex.lastIndex + (len2-len);
  1112. }
  1113. return css;
  1114. },
  1115. reloadCss: function(){
  1116. cssText = (this.json.css) ? this.json.css.code : "";
  1117. //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement);
  1118. var styleNode = $("style"+this.json.id);
  1119. if (styleNode) styleNode.destroy();
  1120. if (cssText){
  1121. cssText = this.parseCSS(cssText);
  1122. var rex = new RegExp("(.+)(?=\\{)", "g");
  1123. var match;
  1124. var id = this.json.id.replace(/\-/g, "");
  1125. var prefix = ".css" + id + " ";
  1126. while ((match = rex.exec(cssText)) !== null) {
  1127. // var rule = prefix + match[0];
  1128. // cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  1129. // rex.lastIndex = rex.lastIndex + prefix.length;
  1130. var rulesStr = match[0];
  1131. if (rulesStr.indexOf(",")!=-1){
  1132. var rules = rulesStr.split(/\s*,\s*/g);
  1133. rules = rules.map(function(r){
  1134. return prefix + r;
  1135. });
  1136. var rule = rules.join(", ");
  1137. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  1138. rex.lastIndex = rex.lastIndex + (prefix.length*rules.length);
  1139. }else{
  1140. var rule = prefix + match[0];
  1141. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  1142. rex.lastIndex = rex.lastIndex + prefix.length;
  1143. }
  1144. }
  1145. var styleNode = document.createElement("style");
  1146. styleNode.setAttribute("type", "text/css");
  1147. styleNode.id="style"+this.json.id;
  1148. styleNode.inject(this.container, "before");
  1149. if(styleNode.styleSheet){
  1150. var setFunc = function(){
  1151. styleNode.styleSheet.cssText = cssText;
  1152. };
  1153. if(styleNode.styleSheet.disabled){
  1154. setTimeout(setFunc, 10);
  1155. }else{
  1156. setFunc();
  1157. }
  1158. }else{
  1159. var cssTextNode = document.createTextNode(cssText);
  1160. styleNode.appendChild(cssTextNode);
  1161. }
  1162. }
  1163. },
  1164. setAllStyles: function(){
  1165. this.setPropertiesOrStyles("styles");
  1166. this.setPropertiesOrStyles("properties");
  1167. this.reloadMaplist();
  1168. },
  1169. reloadMaplist: function(){
  1170. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  1171. },
  1172. _setEditStyle_custom: function(){
  1173. },
  1174. saveAsTemplete: function(){
  1175. },
  1176. isModuleExited : function( id ){
  1177. for( var i=0; i<this.moduleList.length; i++ ){
  1178. if(this.moduleList[i].json.id === id)return true;
  1179. }
  1180. return false;
  1181. },
  1182. checkModuleId: function(id, type, currentSubform){
  1183. var fieldConflict = false;
  1184. var elementConflict = false;
  1185. //if (this.json.moduleList[id]){
  1186. if( this.isModuleExited(id) ){
  1187. elementConflict = true;
  1188. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(this.json.moduleList[id].type)!=-1){
  1189. fieldConflict = true;
  1190. }
  1191. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1192. }
  1193. //if (this.subformList){
  1194. // Object.each(this.subformList, function(subform){
  1195. // if (!currentSubform || currentSubform!=subform.id){
  1196. // if (subform.moduleList[id]){
  1197. // elementConflict = true;
  1198. // if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  1199. // fieldConflict = true;
  1200. // }
  1201. // }
  1202. // }
  1203. // }.bind(this));
  1204. //}
  1205. var subformList = this.getAllSubformJsonObject();
  1206. if (subformList){
  1207. Object.each(subformList, function(subform){
  1208. if (!currentSubform || currentSubform!=subform.id){
  1209. if (subform.moduleList[id]){
  1210. elementConflict = true;
  1211. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  1212. fieldConflict = true;
  1213. }
  1214. }
  1215. }
  1216. }.bind(this));
  1217. }
  1218. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1219. },
  1220. _resetTreeNode: function(){},
  1221. clearSubformList : function( level1subformName ){
  1222. if( !this.level1Subformlist )return;
  1223. if( !this.level1Subformlist[level1subformName] )return;
  1224. delete this.level1Subformlist[level1subformName];
  1225. },
  1226. addSubformList : function( level1subformName, addedSubformId ){
  1227. if( !this.level1Subformlist ){
  1228. this.level1Subformlist = {};
  1229. }
  1230. if( !this.level1Subformlist[level1subformName] ){
  1231. this.level1Subformlist[level1subformName] = [];
  1232. }
  1233. this.level1Subformlist[level1subformName].push( addedSubformId );
  1234. },
  1235. isSubformUnique : function( checkedSubformId, level1subformName, deletedSubformId){
  1236. if( !this.level1Subformlist )return true;
  1237. var level1Subformlist = Object.clone( this.level1Subformlist );
  1238. if( deletedSubformId && level1Subformlist[deletedSubformId] )delete level1Subformlist[deletedSubformId];
  1239. for( var key in level1Subformlist ){
  1240. if( key !== level1subformName ){
  1241. if( level1Subformlist[key].contains( checkedSubformId ) ){
  1242. return false;
  1243. }
  1244. }
  1245. }
  1246. return true;
  1247. },
  1248. getAllSubformTiled : function(){
  1249. var _nestToTiled = function( form , array ){
  1250. if ( form.subformModuleList && form.subformModuleList.length){
  1251. Array.each( form.subformModuleList, function( module ){
  1252. array.push( module );
  1253. if( module.subformModule )_nestToTiled( module.subformModule, array );
  1254. }.bind(this))
  1255. }
  1256. };
  1257. var array = [];
  1258. _nestToTiled( this, array );
  1259. return array;
  1260. },
  1261. getAllSubformJsonObject : function(){
  1262. var list = this.getAllSubformTiled();
  1263. var object = {};
  1264. Array.each( list, function( subform ){
  1265. if( subform && subform.json.subformSelected && subform.subformData && subform.subformData.json){
  1266. object[ subform.json.subformSelected ] = subform.subformData.json;
  1267. }
  1268. }.bind(this));
  1269. return object;
  1270. }
  1271. // getAllFieldModuleNameList: function(){
  1272. // var moduleNameList = [];
  1273. // Object.each(this.json.moduleList, function(o, k){
  1274. // if (this.options.fields.indexOf(o.type))
  1275. // }.bind(this))
  1276. // }
  1277. });