Form.js 47 KB

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