Form.js 47 KB

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