Form.js 48 KB

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