Form.js 54 KB

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