Form.js 47 KB

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