Form.js 47 KB

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