SectionDisplayer.js 9.8 KB

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