Datatable$Data.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Container", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.Datatable$Data = MWF.FCDatatable$Data = new Class({
  4. Extends: MWF.FCTable$Td,
  5. Implements: [Options, Events],
  6. options: {
  7. "propertyPath": "../x_component_process_FormDesigner/Module/Datatable$Data/datatable$Data.html",
  8. "actions": [
  9. {
  10. "name": "insertCol",
  11. "icon": "insertCol1.png",
  12. "event": "click",
  13. "action": "insertCol",
  14. "title": MWF.LP.process.formAction.insertCol
  15. },
  16. {
  17. "name": "deleteCol",
  18. "icon": "deleteCol1.png",
  19. "event": "click",
  20. "action": "deleteCol",
  21. "title": MWF.LP.process.formAction.deleteCol
  22. },
  23. {
  24. "name": "selectParent",
  25. "icon": "selectParent.png",
  26. "event": "click",
  27. "action": "selectParent",
  28. "title": MWF.APPFD.LP.formAction["selectParent"]
  29. }
  30. ],
  31. "allowModules": ["textfield", "number", "currency", "personfield", "orgfield", "org", "calendar", "textarea", "select", "radio", "checkbox", "combox", "image", "label",
  32. "htmleditor", "tinymceeditor", "button","imageclipper", "address", "attachment", "elinput", "elcheckbox", "elselect", "elautocomplete", "elnumber", "elradio", "elcascader",
  33. "elswitch", "elslider", "eltime", "eldate", "eldatetime", "elrate"]
  34. },
  35. initialize: function(form, options){
  36. this.setOptions(options);
  37. this.path = "../x_component_process_FormDesigner/Module/Datatable$Data/";
  38. this.cssPath = "../x_component_process_FormDesigner/Module/Datatable$Data/"+this.options.style+"/css.wcss";
  39. this._loadCss();
  40. this.moduleType = "container";
  41. this.moduleName = "datatable$Data";
  42. this.Node = null;
  43. this.form = form;
  44. },
  45. setAllStyles: function(){
  46. Object.each(this.json.styles, function(value, key){
  47. var reg = /^border\w*/ig;
  48. if (!key.test(reg)){
  49. if (key) this.node.setStyle(key, value);
  50. }
  51. }.bind(this));
  52. this.setPropertiesOrStyles("properties");
  53. this.reloadMaplist();
  54. },
  55. load : function(json, node, parent){
  56. this.json = json;
  57. this.node= node;
  58. this.node.store("module", this);
  59. this.node.setStyles(this.css.moduleNode);
  60. if (!this.json.id){
  61. var id = this._getNewId(parent.json.id);
  62. this.json.id = id;
  63. }
  64. node.set({
  65. "MWFType": "datatable$Data",
  66. "id": this.json.id
  67. });
  68. if (!this.form.json.moduleList[this.json.id]){
  69. this.form.json.moduleList[this.json.id] = this.json;
  70. }
  71. this._initModule();
  72. this._loadTreeNode(parent);
  73. this.form.parseModules(this, this.node);
  74. this.parentContainer = this.treeNode.parentNode.module;
  75. this._setEditStyle_custom("id");
  76. this.checkSequence();
  77. this.json.moduleName = this.moduleName;
  78. if( this.json.isShow === false ){
  79. this._switchShow();
  80. }
  81. },
  82. _setEditStyle_custom: function(name, obj, oldValue) {
  83. if (name == "cellType") this.checkSequence(obj, oldValue);
  84. },
  85. _preprocessingModuleData: function(){
  86. this.node.clearStyles();
  87. //if (this.initialStyles) this.node.setStyles(this.initialStyles);
  88. this.json.recoveryStyles = Object.clone(this.json.styles);
  89. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  90. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  91. //需要运行时处理
  92. }else{
  93. this.node.setStyle(key, value);
  94. delete this.json.styles[key];
  95. }
  96. }.bind(this));
  97. },
  98. _recoveryModuleData: function(){
  99. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  100. this.json.recoveryStyles = null;
  101. },
  102. setCustomStyles: function(){
  103. this._recoveryModuleData();
  104. var border = this.node.getStyle("border");
  105. this.node.clearStyles();
  106. this.node.setStyles(this.css.moduleNode);
  107. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  108. this.node.setStyle("border", border);
  109. Object.each(this.json.styles, function(value, key){
  110. var reg = /^border\w*/ig;
  111. if (!key.test(reg)){
  112. this.node.setStyle(key, value);
  113. }
  114. }.bind(this));
  115. this.setCustomNodeStyles(this.node, this.parentContainer.json.contentStyles);
  116. if( this.json.isShow === false ){
  117. this._switchShow();
  118. }
  119. },
  120. checkSequence: function(obj, oldValue){
  121. if ((this.json.cellType == "sequence") && (oldValue != "sequence")){
  122. if (this.treeNode.firstChild){
  123. var _self = this;
  124. var module = this.treeNode.firstChild.module;
  125. this.form.designer.confirm("warn", module.node, MWF.APPFD.LP.notice.changeToSequenceTitle, MWF.APPFD.LP.notice.changeToSequence, 300, 120, function(){
  126. module.destroy();
  127. this.close();
  128. if (!_self.sequenceNode){
  129. _self.node.empty();
  130. _self.sequenceNode = new Element("div", {"styles": _self.css.sequenceNode, "text": "(N)", "MWFType1": "MWFTemp"}).inject(_self.node);
  131. }
  132. }, function(){
  133. _self.json.cellType = "content";
  134. obj.checked = false;
  135. this.close();
  136. }, null);
  137. }else{
  138. if (!this.sequenceNode){
  139. this.node.empty();
  140. this.sequenceNode = new Element("div", {"styles": this.css.sequenceNode, "text": "(N)", "MWFType1": "MWFTemp"}).inject(this.node);
  141. }
  142. }
  143. }else if (oldValue == "sequence") {
  144. }else{
  145. if (this.sequenceNode){
  146. this.sequenceNode.destroy();
  147. this.sequenceNode = null;
  148. }
  149. }
  150. },
  151. _dragIn: function(module){
  152. if (this.json.cellType == "sequence"){ //this.treeNode.firstChild ||
  153. this.parentContainer._dragIn(module);
  154. }else{
  155. if (this.options.allowModules.indexOf(module.moduleName)!=-1){
  156. this.parentContainer._dragOut(module);
  157. // if (!this.Component) module.inContainer = this;
  158. // module.parentContainer = this;
  159. // module.nextModule = null;
  160. // this.node.setStyles({"border": "1px solid #ffa200"});
  161. // var copyNode = module._getCopyNode();
  162. // copyNode.inject(this.node);
  163. module.onDragModule = this;
  164. if (!this.Component) module.inContainer = this;
  165. module.parentContainer = this;
  166. module.nextModule = null;
  167. this.node.setStyles({"border": "1px solid #ffa200"});
  168. if (module.controlMode){
  169. if (module.copyNode) module.copyNode.hide();
  170. }else{
  171. var copyNode = module._getCopyNode(this);
  172. copyNode.show();
  173. copyNode.inject(this.node);
  174. }
  175. }else{
  176. this.parentContainer._dragIn(module);
  177. }
  178. }
  179. },
  180. _showActions: function(){
  181. if (this.actionArea){
  182. this._setActionAreaPosition();
  183. this.actionArea.setStyle("display", "block");
  184. }
  185. },
  186. _insertCol: function(){
  187. var cols = $("MWFInsertColNumber").get("value");
  188. var positionRadios = document.getElementsByName("MWFInsertColPosition");
  189. var position = "before";
  190. for (var i=0; i<positionRadios.length; i++){
  191. if (positionRadios[i].checked){
  192. position = positionRadios[i].value;
  193. break;
  194. }
  195. }
  196. var tr = this.node.getParent("tr");
  197. var table = tr.getParent("table");
  198. var colIndex = this.node.cellIndex;
  199. var titleTr = table.rows[0];
  200. var dataTr = table.rows[1];
  201. var moduleList = [];
  202. var baseTh = titleTr.cells[colIndex];
  203. for (var m=1; m<=cols; m++){
  204. var newTh = new Element("th").inject(baseTh, position);
  205. this.form.getTemplateData("Datatable$Title", function(data){
  206. var moduleData = Object.clone(data);
  207. var thElement = new MWF.FCDatatable$Title(this.form);
  208. thElement.load(moduleData, newTh, this.parentContainer);
  209. moduleList.push(thElement);
  210. this.parentContainer.elements.push(thElement);
  211. }.bind(this));
  212. }
  213. var baseTd = dataTr.cells[colIndex];
  214. for (var n=1; n<=cols; n++){
  215. var newTd = new Element("td").inject(baseTd, position);
  216. this.form.getTemplateData("Datatable$Data", function(data){
  217. var moduleData = Object.clone(data);
  218. var tdContainer = new MWF.FCDatatable$Data(this.form);
  219. tdContainer.load(moduleData, newTd, this.parentContainer);
  220. moduleList.push(tdContainer);
  221. this.parentContainer.containers.push(tdContainer);
  222. }.bind(this));
  223. }
  224. this.unSelected();
  225. this.selected();
  226. this.addHistoryLog( "insertCol", moduleList );
  227. },
  228. _deleteCol: function(){
  229. var tr = this.node.getParent("tr");
  230. var table = tr.getParent("table");
  231. var colIndex = this.node.cellIndex;
  232. var titleTr = table.rows[0];
  233. var dataTr = table.rows[1];
  234. if (tr.cells.length<=1){
  235. this.parentContainer.destroy();
  236. }else{
  237. var deleteTh = titleTr.cells[colIndex];
  238. var deleteTd = dataTr.cells[colIndex];
  239. var thModule = deleteTh.retrieve("module");
  240. if (thModule){
  241. thModule.parentContainer.elements.erase(thModule);
  242. thModule.destroy();
  243. }
  244. var tdModule = deleteTd.retrieve("module");
  245. if (tdModule){
  246. tdModule.parentContainer.containers.erase(tdModule);
  247. tdModule.destroy();
  248. }
  249. }
  250. },
  251. _switchShow : function (isShow) {
  252. if( typeOf(isShow) === "boolean" ){
  253. this.json.isShow = isShow;
  254. }else{
  255. isShow = this.json.isShow !== false ;
  256. }
  257. this.node.setStyle("opacity", isShow ? "1" : "0.3");
  258. }
  259. });