Datatable$Data.js 9.4 KB

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