SectionDisplayer.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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.SectionDisplayer = 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/$SectionDisplayer/";
  19. // this.cssPath = "../x_component_process_FormDesigner/widget/$SectionDisplayer/"+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.sectionDisplayArea = this.node.getElement(".sectionDisplayArea");
  32. this.displayWithSectionKeyArea = this.node.getElement(".displayWithSectionKeyArea");
  33. this.sortScriptArea = this.node.getElement(".sectionDisplaySortScriptArea");
  34. var lp = this.lp;
  35. var moduleName = this.module.moduleName;
  36. debugger;
  37. if( o2.typeOf( this.data.showAllSection ) === "null" )this.data.showAllSection = false;
  38. if( o2.typeOf( this.data.showSectionBy ) === "null" )this.data.showSectionBy = true;
  39. if( o2.typeOf( this.data.sequenceBy ) === "null" )this.data.sequenceBy = "section";
  40. if( o2.typeOf( this.data.keyContentSeparatorSectionBy ) === "null" )this.data.keyContentSeparatorSectionBy = ":";
  41. MWF.xDesktop.requireApp("Template", "MForm", function () {
  42. this.form = new MForm(this.node, this.data, {
  43. isEdited: true,
  44. style : "",
  45. hasColon : true,
  46. itemTemplate: {
  47. showAllSection: { name: this.data.pid + "showAllSection",
  48. type : "radio", className: "editTableRadio", selectValue: ["true", "false"], selectText: [lp.yes, lp.no], event: {
  49. change: function (it) {
  50. _self.property.setRadioValue("showAllSection", this);
  51. _self.checkShow()
  52. }
  53. }},
  54. showSectionBy: { name: this.data.pid + "showSectionBy",
  55. type : "radio", className: "editTableRadio", selectValue: ["true", "false"], selectText: [lp.yes, lp.no], event: {
  56. change: function (it) {
  57. _self.property.setRadioValue("showSectionBy", this);
  58. _self.checkShow()
  59. }
  60. }},
  61. sequenceBy: { name: this.data.pid + "sequenceBy",
  62. type : "radio", className: "editTableRadio", selectValue: ["section","module"], selectText: [lp.bySection, lp.byModule], event: {
  63. change: function (it) {
  64. _self.property.setRadioValue("sequenceBy", this);
  65. _self.checkShow()
  66. }
  67. }},
  68. totalRowBy: { name: this.data.pid + "totalRowBy",
  69. type : "checkbox", className: "editTableRadio", selectValue: ["section","module"], selectText: [lp.bySection, lp.byModule], event: {
  70. change: function (it) {
  71. _self.property.setCheckboxValue("totalRowBy", this);
  72. _self.checkShow()
  73. }
  74. }},
  75. keyContentSeparatorSectionBy: { name: this.data.pid + "keyContentSeparatorSectionBy",
  76. tType : "text" , className: "editTableInput", event: {
  77. change: function (it) {
  78. _self.property.setValue("keyContentSeparatorSectionBy", it.getValue(), this);
  79. }
  80. }}
  81. }
  82. }, this.app, this.form.css);
  83. this.form.load();
  84. // this.setEditNodeStyles( this.node );
  85. this.loadMaplist();
  86. this.loadScriptArea();
  87. this.checkShow( this.data );
  88. this.fireEvent("postLoad");
  89. }.bind(this), true);
  90. },
  91. checkShow: function(d){
  92. debugger;
  93. if( !d )d = this.data;
  94. var _self = this;
  95. var showCondition = {
  96. "sectionDisplayArea": function () {
  97. return !!d.showAllSection;
  98. },
  99. "displayWithSectionKeyArea": function () {
  100. return !!d.showSectionBy
  101. },
  102. "sortScriptArea": function () {
  103. return !!d.showAllSection
  104. }
  105. };
  106. for( var key in showCondition ){
  107. if( showCondition[key]() ){
  108. this[key].setStyle("display", "");
  109. }else{
  110. this[key].hide()
  111. }
  112. }
  113. },
  114. getHtml: function(){
  115. return '<table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  116. ' <tr>' +
  117. ' <td class="editTableTitle">'+this.lp.showAllSection+':</td>' +
  118. ' <td class="editTableValue" item="showAllSection"></td>' +
  119. ' </tr>' +
  120. '</table>' +
  121. '<div class="sectionDisplayArea">' +
  122. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  123. ' <tr>' +
  124. ' <td class="editTableTitle">'+this.lp.showSectionKey+':</td>' +
  125. ' <td class="editTableValue" item="showSectionBy"></td>' +
  126. ' </tr>' +
  127. ' </table>' +
  128. ' <div class="displayWithSectionKeyArea">' +
  129. ' <div class="MWFMaplist" name="sectionByStyles" title="'+this.lp.sectionKeystyles+'"></div>' +
  130. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  131. ' <tr>' +
  132. ' <td class="editTableTitle">'+this.lp.serialNumber+':</td>' +
  133. ' <td class="editTableValue" item="sequenceBy"></td>' +
  134. ' </tr>' +
  135. ' </table>' +
  136. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  137. ' <tr>' +
  138. ' <td class="editTableTitle">'+this.lp.totalRow+':</td>' +
  139. ' <td class="editTableValue" item="totalRowBy"></td>' +
  140. ' </tr>' +
  141. ' </table>' +
  142. ' <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">' +
  143. ' <tr>' +
  144. ' <td class="editTableTitle">'+this.lp.separator+':</td>' +
  145. ' <td class="editTableValue" item="keyContentSeparatorSectionBy"></td>' +
  146. ' </tr>' +
  147. ' </table>' +
  148. ' </div>' +
  149. '</div>' +
  150. '<div class="sectionDisplaySortScriptArea">' +
  151. ' <div class="MWFScriptArea" name="sectionDisplaySortScript" title="'+this.lp.sectionMergeSortScript+' (S)"></div>' +
  152. ' <div style="padding: 10px;color:#999">排序脚本通过this.event.a和this.event.b获取数据,处理后返回正数表示升序,负数表示降序。this.event.a和this.event.b值如: <br/>' +
  153. ' { <br/>' +
  154. ' key: "张三@zhangsan@P", //区段值 <br/>' +
  155. ' data: "内容" //字段内容 <br/>' +
  156. ' }' +
  157. ' </div>' +
  158. '</div>'
  159. },
  160. setEditNodeStyles: function(node){
  161. var nodes = node.getChildren();
  162. if (nodes.length){
  163. nodes.each(function(el){
  164. var cName = el.get("class");
  165. if (cName){
  166. if (this.form.css[cName]) el.setStyles(this.form.css[cName]);
  167. }
  168. this.setEditNodeStyles(el);
  169. }.bind(this));
  170. }
  171. },
  172. loadMaplist: function(){
  173. var maplists = this.node.getElements(".MWFMaplist");
  174. maplists.each(function(node){
  175. var title = node.get("title");
  176. var name = node.get("name");
  177. var lName = name.toLowerCase();
  178. var collapse = node.get("collapse");
  179. var mapObj = this.data[name];
  180. if (!mapObj) mapObj = {};
  181. MWF.require("MWF.widget.Maplist", function(){
  182. node.empty();
  183. var maplist = new MWF.widget.Maplist(node, {
  184. "title": title,
  185. "collapse": (collapse) ? true : false,
  186. "onChange": function(){
  187. //this.data[name] = maplist.toJson();
  188. //
  189. var oldData = this.data[name];
  190. this.property.changeJsonDate(name, maplist.toJson());
  191. this.property.changeStyle(name, oldData);
  192. this.property.changeData(name, null, oldData);
  193. }.bind(this),
  194. "onDelete": function(key){
  195. debugger;
  196. this.module.deletePropertiesOrStyles(name, key);
  197. }.bind(this),
  198. "isProperty": (lName.contains("properties") || lName.contains("property") || lName.contains("attribute"))
  199. });
  200. maplist.load(mapObj);
  201. this.property.maplists[name] = maplist;
  202. }.bind(this));
  203. }.bind(this));
  204. },
  205. loadScriptArea: function(){
  206. var scriptAreas = this.node.getElements(".MWFScriptArea");
  207. var formulaAreas = this.node.getElements(".MWFFormulaArea");
  208. this.loadScriptEditor(scriptAreas);
  209. this.loadScriptEditor(formulaAreas, "formula");
  210. },
  211. loadScriptEditor: function(scriptAreas, style){
  212. scriptAreas.each(function(node){
  213. var title = node.get("title");
  214. var name = node.get("name");
  215. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  216. var scriptContent = this.data[name];
  217. var mode = node.dataset["mode"];
  218. MWF.require("MWF.widget.ScriptArea", function(){
  219. var scriptArea = new MWF.widget.ScriptArea(node, {
  220. "title": title,
  221. "isbind": false,
  222. "mode": mode || "javascript",
  223. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  224. "maxObj": this.designer.formContentNode || this.designer.pageContentNode,
  225. "onChange": function(){
  226. //this.data[name] = scriptArea.toJson();
  227. if (!this.data[name]){
  228. this.data[name] = {"code": "", "html": ""};
  229. if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  230. }
  231. var oldValue = this.data[name].code;
  232. var json = scriptArea.toJson();
  233. this.data[name].code = json.code;
  234. this.property.checkHistory(name+".code", oldValue, this.data[name].code);
  235. //this.data[name].html = json.html;
  236. }.bind(this),
  237. "onSave": function(){
  238. this.designer.saveForm();
  239. }.bind(this),
  240. "style": style || "default",
  241. "runtime": "web"
  242. });
  243. scriptArea.load(scriptContent);
  244. }.bind(this));
  245. }.bind(this));
  246. }
  247. });