Form.js 53 KB

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