Page.js 45 KB

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