SectionMerger.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. MWF.xApplication.process.FormDesigner.widget = MWF.xApplication.process.FormDesigner.widget || {};
  2. MWF.require("MWF.widget.ScriptArea", null, false);
  3. MWF.xApplication.process.FormDesigner.widget.SectionMerger = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default",
  8. "maxObj": document.body
  9. },
  10. initialize: function(node, property, options){
  11. this.setOptions(options);
  12. this.node = $(node);
  13. this.property = property;
  14. this.app = this.property.designer;
  15. this.designer = this.property.designer;
  16. this.form = this.property.form;
  17. this.module = this.property.module;
  18. // this.path = "../x_component_process_FormDesigner/widget/$SectionMerger/";
  19. // this.cssPath = "../x_component_process_FormDesigner/widget/$SectionMerger/"+this.options.style+"/css.wcss";
  20. this.lp = this.app.lp.propertyTemplate;
  21. if( !this.lp ){
  22. o2.xDesktop.requireApp("process.FormDesigner", "lp."+o2.language, null, false);
  23. this.lp = MWF.xApplication.process.FormDesigner.LP.propertyTemplate;
  24. }
  25. // this._loadCss();
  26. },
  27. load: function(data){
  28. var _self = this;
  29. this.data = data;
  30. this.node.set("html", this.getHtml());
  31. this.readArea = this.node.getElement(".sectionMergeReadArea");
  32. this.readTypeArea = this.node.getElement(".sectionMergeReadTypeArea");
  33. this.readDefaultArea = this.node.getElement(".sectionMergeReadDefaultArea");
  34. this.readHtmlScriptArea = this.node.getElement(".sectionMergeReadHtmlScriptArea");
  35. this.readDataScriptArea = this.node.getElement(".sectionMergeReadDataScriptArea");
  36. this.keyContentSeparatorArea = this.node.getElement(".keyContentSeparatorArea");
  37. this.sectionKeyStylesArea = this.node.getElement(".sectionKeyStylesArea");
  38. this.readStyleArea = this.node.getElement(".sectionMergeReadStyleArea");
  39. this.readWithSectionKeyArea = this.node.getElement(".readWithSectionKeyArea");
  40. this.sectionKeyScriptArea = this.node.getElement(".sectionKeyScriptArea");
  41. this.sectionKeySequenceArea = this.node.getElement(".sectionKeySequenceArea");
  42. this.sectionKeyTotalArea = this.node.getElement(".sectionKeyTotalArea");
  43. this.editArea = this.node.getElement(".sectionMergeEditArea");
  44. this.editScriptArea = this.node.getElement(".sectionMergeEditScriptArea");
  45. this.mergeTypeEditTable = this.node.getElement("[item='mergeTypeEditTable']");
  46. this.sortScriptArea = this.node.getElement(".sectionMergeSortScriptArea");
  47. var lp = this.lp;
  48. var moduleName = this.module.moduleName;
  49. this.hasEditDefaultModuleList = ["textfield", "checkbox", "datatable", "datatemplate", "org", "textarea", "elautocomplete", "elcheckbox", "elinput"];
  50. if( o2.typeOf( this.data.sectionMerge ) === "null" )this.data.sectionMerge = "none";
  51. if( o2.typeOf( this.data.mergeTypeRead ) === "null" )this.data.mergeTypeRead = "default";
  52. if( o2.typeOf( this.data.showSectionKey ) === "null" )this.data.showSectionKey = true;
  53. if( o2.typeOf( this.data.sectionKey ) === "null" )this.data.sectionKey = "person";
  54. if( o2.typeOf( this.data.mergeTypeEdit ) === "null" ){
  55. if( !this.hasEditDefaultModuleList.contains( moduleName ) ){
  56. this.data.mergeTypeEdit = "script"
  57. }else if(["number", "elnumber"].contains(moduleName)){
  58. this.data.mergeTypeEdit = "amount"
  59. }else{
  60. this.data.mergeTypeEdit = "default"
  61. }
  62. }
  63. MWF.xDesktop.requireApp("Template", "MForm", function () {
  64. this.form = new MForm(this.node, this.data, {
  65. isEdited: true,
  66. style : "",
  67. hasColon : true,
  68. itemTemplate: {
  69. sectionMerge: { name: this.data.pid + "sectionMerge", type : "radio",
  70. selectValue: function(){
  71. return ["none", "read", "edit"];
  72. // switch (moduleName) {
  73. // case "datatable":
  74. // case "datatemplate":
  75. // return ["none", "read", "editSection", "edit"];
  76. // default:
  77. // return ["none", "read", "edit"]
  78. // }
  79. },
  80. selectText: function () {
  81. // switch (moduleName) {
  82. // case "datatable":
  83. // case "datatemplate":
  84. // return [lp.none, lp.mergeDisplay, lp.editCurrentSection, lp.mergeEdit];
  85. // default:
  86. // return [lp.none, lp.mergeDisplay, lp.mergeEdit]
  87. // }
  88. return [lp.none, lp.mergeDisplay, lp.mergeEdit];
  89. },
  90. event: {
  91. change: function (it, ev) {
  92. _self.property.setRadioValue("sectionMerge", this);
  93. _self.checkShow()
  94. }
  95. }},
  96. mergeTypeRead: { name: this.data.pid + "mergeTypeRead",
  97. type : "radio", className: "editTableRadio",
  98. selectValue: function(){
  99. switch (moduleName) {
  100. case "datatable":
  101. case "datatemplate":
  102. return ["default", "dataScript"];
  103. case "number":
  104. case "elnumber":
  105. return ["default", "amount", "average", "htmlScript"];
  106. default:
  107. return ["default", "htmlScript"]
  108. }
  109. },
  110. selectText: function () {
  111. switch (moduleName) {
  112. case "datatable":
  113. case "datatemplate":
  114. return [lp.default, lp.dataScript];
  115. case "number":
  116. case "elnumber":
  117. return [lp.default, lp.amountValue, lp.averageValue, lp.htmlScript];
  118. default:
  119. return [lp.default, lp.htmlScript];
  120. }
  121. },
  122. event: {
  123. change: function (it) {
  124. _self.property.setRadioValue("mergeTypeRead", this);
  125. _self.checkShow()
  126. }
  127. }},
  128. showSectionKey: { name: this.data.pid + "showSectionKey",
  129. type : "radio", className: "editTableRadio", selectValue: ["true", "false"], selectText: [lp.yes, lp.no], event: {
  130. change: function (it) {
  131. _self.property.setRadioValue("showSectionKey", this);
  132. _self.checkShow()
  133. }
  134. }},
  135. sequenceBySection: { name: this.data.pid + "sequenceBySection",
  136. type : "radio", className: "editTableRadio", selectValue: ["section","module"], selectText: [lp.bySection, lp.byModule], event: {
  137. change: function (it) {
  138. _self.property.setRadioValue("sequenceBySection", this);
  139. _self.checkShow()
  140. }
  141. }},
  142. totalRowBySection: { name: this.data.pid + "totalRowBySection",
  143. type : "checkbox", className: "editTableRadio", selectValue: ["section","module"], selectText: [lp.bySection, lp.byModule], event: {
  144. change: function (it) {
  145. _self.property.setCheckboxValue("totalRowBySection", this);
  146. _self.checkShow()
  147. }
  148. }},
  149. keyContentSeparator: { name: this.data.pid + "keyContentSeparator",
  150. tType : "text" , className: "editTableInput", event: {
  151. change: function (it) {
  152. _self.property.setValue("keyContentSeparator", it.getValue(), this);
  153. }
  154. }},
  155. sectionKey: { name: this.data.pid + "sectionKey",
  156. type : "radio", selectValue: ["person", "unit", "activity", "splitValue", "script"], selectText: [lp.handler, lp.handlerUnit, lp.activityId, lp.splitValue, lp.script], event: {
  157. change: function (it) {
  158. _self.property.setRadioValue("sectionKey", this);
  159. _self.checkShow()
  160. }
  161. }},
  162. mergeTypeEdit: { name: this.data.pid + "mergeTypeEdit",
  163. type : "radio", className: "editTableRadio",
  164. selectValue: function(){
  165. return ["number", "elnumber"].contains(moduleName) ? ["amount", "average", "script"] : ["default", "script"]
  166. },
  167. selectText: function () {
  168. return ["number", "elnumber"].contains(moduleName) ? [lp.amountValue, lp.averageValue, lp.script] : [lp.default, lp.script]
  169. },
  170. event: {
  171. change: function (it) {
  172. _self.property.setRadioValue("mergeTypeEdit", this);
  173. _self.checkShow()
  174. }
  175. }},
  176. }
  177. }, this.app, this.form.css);
  178. this.form.load();
  179. // this.setEditNodeStyles( this.node );
  180. this.loadMaplist();
  181. this.loadScriptArea();
  182. this.checkShow( this.data );
  183. this.fireEvent("postLoad");
  184. }.bind(this), true);
  185. },
  186. checkShow: function(d){
  187. if( !d )d = this.data;
  188. var _self = this;
  189. var showCondition = {
  190. "readArea": function() {
  191. return d.sectionMerge==='read' || d.sectionMerge==='editSection';
  192. },
  193. "readTypeArea": function(){
  194. return d.sectionMerge==='read';
  195. },
  196. "readDefaultArea": function () {
  197. return d.mergeTypeRead==='default' || !d.mergeTypeRead || d.sectionMerge==='editSection';
  198. },
  199. "readWithSectionKeyArea": function () {
  200. return !!d.showSectionKey || d.sectionMerge==='editSection';
  201. },
  202. "keyContentSeparatorArea": function () {
  203. return !!d.showSectionKey;
  204. },
  205. "sectionKeyStylesArea": function () {
  206. return !!d.showSectionKey;
  207. },
  208. "sectionKeyScriptArea": function () {
  209. return d.sectionKey === "script";
  210. },
  211. "sectionKeyTotalArea": function () {
  212. return d.showSectionKey && ["datatable"].contains( _self.module.moduleName );
  213. },
  214. "sectionKeySequenceArea": function () {
  215. return d.showSectionKey && ["datatable", "datatemplate"].contains( _self.module.moduleName );
  216. },
  217. "readStyleArea": function () {
  218. return !["datatable", "datatemplate"].contains( _self.module.moduleName );
  219. },
  220. "readHtmlScriptArea": function () {
  221. return d.sectionMerge==='read' && d.mergeTypeRead==='htmlScript';
  222. },
  223. "readDataScriptArea": function () {
  224. return d.sectionMerge==='read' && d.mergeTypeRead==='dataScript';
  225. },
  226. "editArea": function() {
  227. return d.sectionMerge==='edit';
  228. },
  229. "editScriptArea": function () {
  230. return d.sectionMerge==='edit' && d.mergeTypeEdit === 'script';
  231. },
  232. "sortScriptArea": function () {
  233. return ( d.sectionMerge==='read' && d.mergeTypeRead === "default" ) ||
  234. (d.sectionMerge==='edit' && d.mergeTypeEdit === "default") ||
  235. d.sectionMerge==='editSection'
  236. },
  237. "mergeTypeEditTable" : function () {
  238. return _self.hasEditDefaultModuleList.contains( _self.module.moduleName ) ||
  239. ["number", "elnumber"].contains( _self.module.moduleName );
  240. }
  241. };
  242. for( var key in showCondition ){
  243. if( showCondition[key]() ){
  244. this[key].setStyle("display", "");
  245. }else{
  246. this[key].hide()
  247. }
  248. }
  249. },
  250. getHtml: function(){
  251. return '<table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  252. ' <tr>' +
  253. ' <td class="editTableTitle">'+this.lp.enableSectionMerge+':</td>' +
  254. ' <td class="editTableValue" item="sectionMerge"></td>' +
  255. ' </tr>' +
  256. '</table>' +
  257. '<div class="sectionMergeReadArea">' +
  258. ' <div class="sectionMergeReadTypeArea">' +
  259. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  260. ' <tr>' +
  261. ' <td class="editTableTitle">'+this.lp.mergeType+':</td>' +
  262. ' <td class="editTableValue" item="mergeTypeRead"></td>' +
  263. ' </tr>' +
  264. ' </table>' +
  265. ' </div>' +
  266. ' <div class="sectionMergeReadDefaultArea">' +
  267. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  268. ' <tr>' +
  269. ' <td class="editTableTitle">'+this.lp.showSectionKey+':</td>' +
  270. ' <td class="editTableValue" item="showSectionKey"></td>' +
  271. ' </tr>' +
  272. ' </table>' +
  273. ' <div class="sectionMergeReadStyleArea">' +
  274. ' <div class="MWFMaplist" name="sectionNodeStyles" title="'+this.lp.sectionNodeStyles+'"></div>' +
  275. ' <div class="MWFMaplist" name="sectionContentStyles" title="'+this.lp.sectionContentStyles+'"></div>' +
  276. ' </div>' +
  277. ' <div class="readWithSectionKeyArea">' +
  278. ' <div class="sectionKeyStylesArea">' +
  279. ' <div class="MWFMaplist" name="sectionKeyStyles" title="'+this.lp.sectionKeystyles+'"></div>' +
  280. ' </div>'+
  281. ' <div class="sectionKeySequenceArea">' +
  282. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  283. ' <tr>' +
  284. ' <td class="editTableTitle">'+this.lp.serialNumber+':</td>' +
  285. ' <td class="editTableValue" item="sequenceBySection"></td>' +
  286. ' </tr>' +
  287. ' </table>' +
  288. ' </div>' +
  289. ' <div class="sectionKeyTotalArea">' +
  290. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  291. ' <tr>' +
  292. ' <td class="editTableTitle">'+this.lp.totalRow+':</td>' +
  293. ' <td class="editTableValue" item="totalRowBySection"></td>' +
  294. ' </tr>' +
  295. ' </table>' +
  296. ' </div>' +
  297. ' <div class="keyContentSeparatorArea">' +
  298. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  299. ' <tr>' +
  300. ' <td class="editTableTitle">'+this.lp.separator+':</td>' +
  301. ' <td class="editTableValue" item="keyContentSeparator"></td>' +
  302. ' </tr>' +
  303. ' </table>' +
  304. ' </div>' +
  305. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  306. ' <tr>' +
  307. ' <td class="editTableTitle">'+this.lp.sectionKey+':</td>' +
  308. ' <td class="editTableValue" item="sectionKey"></td>' +
  309. ' </tr>' +
  310. ' </table>' +
  311. ' <div class="sectionKeyScriptArea">' +
  312. ' <div class="MWFScriptArea" name="sectionKeyScript" title="'+this.lp.sectionKeyScript+' (S)"></div>' +
  313. ' </div>' +
  314. ' </div>' +
  315. ' </div>' +
  316. ' <div class="sectionMergeReadHtmlScriptArea">' +
  317. ' <div class="MWFScriptArea" name="sectionMergeReadHtmlScript" title="'+this.lp.sectionMergeReadHtmlScript+' (S)"></div>' +
  318. ' <div style="padding: 10px;color:#999">返回需展现的html</div>' +
  319. ' </div> ' +
  320. ' <div class="sectionMergeReadDataScriptArea">' +
  321. ' <div class="MWFScriptArea" name="sectionMergeReadDataScript" title="'+this.lp.sectionMergeReadDataScript+' (S)"></div>' +
  322. ' <div style="padding: 10px;color:#999">返回删除区段后合并的数据,不保存到后台</div>' +
  323. ' </div> ' +
  324. '</div>' +
  325. '<div class="sectionMergeEditArea">' +
  326. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable" item="mergeTypeEditTable">' +
  327. ' <tr>' +
  328. ' <td class="editTableTitle">'+this.lp.mergeType+':</td>' +
  329. ' <td class="editTableValue" item="mergeTypeEdit"></td>' +
  330. ' </tr>' +
  331. ' </table>' +
  332. ' <div class="sectionMergeEditScriptArea">' +
  333. ' <div class="MWFScriptArea" name="sectionMergeEditScript" title="'+this.lp.sectionMergeEditScript+' (S)"></div>' +
  334. ' <div style="padding: 10px;color:#999">通过this.data[fieldId]获取字段数据,返回删除区段后合并的数据。</div>' +
  335. ' </div>' +
  336. '</div>' +
  337. '<div class="sectionMergeSortScriptArea">' +
  338. ' <div class="MWFScriptArea" name="sectionMergeSortScript" title="'+this.lp.sectionMergeSortScript+' (S)"></div>' +
  339. ' <div style="padding: 10px;color:#999">排序脚本通过this.event.a和this.event.b获取数据,处理后返回正数表示升序,负数表示降序。this.event.a和this.event.b值如: <br/>' +
  340. ' { <br/>' +
  341. ' key: "张三@zhangsan@P", //区段值 <br/>' +
  342. ' data: "内容" //字段内容 <br/>' +
  343. ' }' +
  344. ' </div>' +
  345. '</div>'
  346. },
  347. setEditNodeStyles: function(node){
  348. var nodes = node.getChildren();
  349. if (nodes.length){
  350. nodes.each(function(el){
  351. var cName = el.get("class");
  352. if (cName){
  353. if (this.form.css[cName]) el.setStyles(this.form.css[cName]);
  354. }
  355. this.setEditNodeStyles(el);
  356. }.bind(this));
  357. }
  358. },
  359. loadMaplist: function(){
  360. var maplists = this.node.getElements(".MWFMaplist");
  361. maplists.each(function(node){
  362. var title = node.get("title");
  363. var name = node.get("name");
  364. var lName = name.toLowerCase();
  365. var collapse = node.get("collapse");
  366. var mapObj = this.data[name];
  367. if (!mapObj) mapObj = {};
  368. MWF.require("MWF.widget.Maplist", function(){
  369. node.empty();
  370. var maplist = new MWF.widget.Maplist(node, {
  371. "title": title,
  372. "collapse": (collapse) ? true : false,
  373. "onChange": function(){
  374. //this.data[name] = maplist.toJson();
  375. //
  376. var oldData = this.data[name];
  377. this.property.changeJsonDate(name, maplist.toJson());
  378. this.property.changeStyle(name, oldData);
  379. this.property.changeData(name, null, oldData);
  380. }.bind(this),
  381. "onDelete": function(key){
  382. this.module.deletePropertiesOrStyles(name, key);
  383. }.bind(this),
  384. "isProperty": (lName.contains("properties") || lName.contains("property") || lName.contains("attribute"))
  385. });
  386. maplist.load(mapObj);
  387. this.property.maplists[name] = maplist;
  388. }.bind(this));
  389. }.bind(this));
  390. },
  391. loadScriptArea: function(){
  392. var scriptAreas = this.node.getElements(".MWFScriptArea");
  393. var formulaAreas = this.node.getElements(".MWFFormulaArea");
  394. this.loadScriptEditor(scriptAreas);
  395. this.loadScriptEditor(formulaAreas, "formula");
  396. },
  397. loadScriptEditor: function(scriptAreas, style){
  398. scriptAreas.each(function(node){
  399. var title = node.get("title");
  400. var name = node.get("name");
  401. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  402. var scriptContent = this.data[name];
  403. var mode = node.dataset["mode"];
  404. MWF.require("MWF.widget.ScriptArea", function(){
  405. var scriptArea = new MWF.widget.ScriptArea(node, {
  406. "title": title,
  407. "isbind": false,
  408. "mode": mode || "javascript",
  409. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  410. "maxObj": this.designer.formContentNode || this.designer.pageContentNode,
  411. "onChange": function(){
  412. //this.data[name] = scriptArea.toJson();
  413. if (!this.data[name]){
  414. this.data[name] = {"code": "", "html": ""};
  415. if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  416. }
  417. var oldValue = this.data[name].code;
  418. var json = scriptArea.toJson();
  419. this.data[name].code = json.code;
  420. this.property.checkHistory(name+".code", oldValue, this.data[name].code);
  421. //this.data[name].html = json.html;
  422. }.bind(this),
  423. "onSave": function(){
  424. this.designer.saveForm();
  425. }.bind(this),
  426. "style": style || "default",
  427. "runtime": "web"
  428. });
  429. scriptArea.load(scriptContent);
  430. }.bind(this));
  431. }.bind(this));
  432. }
  433. });