Datatable$Title.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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$Title = MWF.FCDatatable$Title = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_process_FormDesigner/Module/Datatable$Title/datatable$Title.html",
  9. "actions": [
  10. {
  11. "name": "insertCol",
  12. "icon": "insertCol1.png",
  13. "event": "click",
  14. "action": "insertCol",
  15. "title": MWF.LP.process.formAction.insertCol
  16. },
  17. {
  18. "name": "deleteCol",
  19. "icon": "deleteCol1.png",
  20. "event": "click",
  21. "action": "deleteCol",
  22. "title": MWF.LP.process.formAction.deleteCol
  23. },
  24. {
  25. "name": "selectParent",
  26. "icon": "selectParent.png",
  27. "event": "click",
  28. "action": "selectParent",
  29. "title": MWF.APPFD.LP.formAction["selectParent"]
  30. }
  31. ]
  32. },
  33. initialize: function(form, options){
  34. this.setOptions(options);
  35. this.path = "../x_component_process_FormDesigner/Module/Datatable$Title/";
  36. this.cssPath = "../x_component_process_FormDesigner/Module/Datatable$Title/"+this.options.style+"/css.wcss";
  37. this._loadCss();
  38. this.moduleType = "element";
  39. this.moduleName = "datatable$Title";
  40. this.Node = null;
  41. this.form = form;
  42. },
  43. _setNodeProperty: function(){
  44. if (this.form.moduleList.indexOf(this)==-1) this.form.moduleList.push(this);
  45. if (this.form.moduleNodeList.indexOf(this.node)==-1) this.form.moduleNodeList.push(this.node);
  46. if (this.form.moduleElementNodeList.indexOf(this.node)==-1) this.form.moduleElementNodeList.push(this.node);
  47. this.node.store("module", this);
  48. this.setPrefixOrSuffix();
  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. _dragIn: function(module){
  61. this.parentContainer._dragIn(module);
  62. },
  63. over: function(){
  64. if (this.form.selectedModules.indexOf(this)==-1){
  65. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this) this.node.setStyles({
  66. "border-width": "1px",
  67. "border-color": "#0072ff"
  68. });
  69. }
  70. },
  71. unOver: function(){
  72. if (this.form.selectedModules.indexOf(this)==-1){
  73. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this) this.node.setStyles({
  74. "border-width": "1px",
  75. "border-color": "#999"
  76. });
  77. }
  78. },
  79. unSelected: function(){
  80. this.node.setStyles({
  81. "border-width": "1px",
  82. "border-color": "#999"
  83. });
  84. this._hideActions();
  85. this.form.currentSelectedModule = null;
  86. this.hideProperty();
  87. },
  88. load : function(json, node, parent){
  89. this.json = json;
  90. this.node= node;
  91. this.node.store("module", this);
  92. this.node.setStyles(this.css.moduleNode);
  93. this.node.set("text", this.json.name || "DataTitle");
  94. if (!this.json.id){
  95. var id = this._getNewId(parent.json.id);
  96. this.json.id = id;
  97. }
  98. node.set({
  99. "MWFType": "datatable$Title",
  100. "id": this.json.id
  101. });
  102. if (!this.form.json.moduleList[this.json.id]){
  103. this.form.json.moduleList[this.json.id] = this.json;
  104. }
  105. this._initModule();
  106. this._loadTreeNode(parent);
  107. this.parentContainer = this.treeNode.parentNode.module;
  108. this._setEditStyle_custom("id");
  109. this.json.moduleName = this.moduleName;
  110. if( this.json.isShow === false ){
  111. this._switchShow();
  112. }
  113. },
  114. _createMoveNode: function(){
  115. return false;
  116. },
  117. // _setEditStyle_custom: function(name){
  118. //
  119. // },
  120. _dragInLikeElement: function(module){
  121. return false;
  122. },
  123. setCustomStyles: function(){
  124. this._recoveryModuleData();
  125. var border = this.node.getStyle("border");
  126. this.node.clearStyles();
  127. this.node.setStyles(this.css.moduleNode);
  128. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  129. this.node.setStyle("border", border);
  130. Object.each(this.json.styles, function(value, key){
  131. var reg = /^border\w*/ig;
  132. if (!key.test(reg)){
  133. this.node.setStyle(key, value);
  134. }
  135. }.bind(this));
  136. this.setCustomNodeStyles(this.node, this.parentContainer.json.titleStyles);
  137. if( this.json.isShow === false ){
  138. this._switchShow();
  139. }
  140. },
  141. insertCol: function(){
  142. var module = this;
  143. var url = this.path+"insertCol.html";
  144. MWF.require("MWF.widget.Dialog", function(){
  145. var size = $(document.body).getSize();
  146. var x = size.x/2-150;
  147. var y = size.y/2-90;
  148. var dlg = new MWF.DL({
  149. "title": "Insert Col",
  150. "style": "property",
  151. "top": y,
  152. "left": x-40,
  153. "fromTop":size.y/2-45,
  154. "fromLeft": size.x/2,
  155. "width": 300,
  156. "height": 180,
  157. "url": url,
  158. "lp": MWF.xApplication.process.FormDesigner.LP.propertyTemplate,
  159. "buttonList": [
  160. {
  161. "text": MWF.APPFD.LP.button.ok,
  162. "action": function(){
  163. module._insertCol();
  164. this.close();
  165. }
  166. },
  167. {
  168. "text": MWF.APPFD.LP.button.cancel,
  169. "action": function(){
  170. this.close();
  171. }
  172. }
  173. ]
  174. });
  175. dlg.show();
  176. }.bind(this));
  177. },
  178. _insertCol: function(){
  179. var cols = $("MWFInsertColNumber").get("value");
  180. var positionRadios = document.getElementsByName("MWFInsertColPosition");
  181. var position = "before";
  182. for (var i=0; i<positionRadios.length; i++){
  183. if (positionRadios[i].checked){
  184. position = positionRadios[i].value;
  185. break;
  186. }
  187. }
  188. var tr = this.node.getParent("tr");
  189. var table = tr.getParent("table");
  190. var colIndex = this.node.cellIndex;
  191. var titleTr = table.rows[0];
  192. var dataTr = table.rows[1];
  193. var moduleList = [];
  194. var baseTh = titleTr.cells[colIndex];
  195. for (var m=1; m<=cols; m++){
  196. var newTh = new Element("th").inject(baseTh, position);
  197. this.form.getTemplateData("Datatable$Title", function(data){
  198. var moduleData = Object.clone(data);
  199. var thElement = new MWF.FCDatatable$Title(this.form);
  200. thElement.load(moduleData, newTh, this.parentContainer);
  201. moduleList.push(thElement);
  202. this.parentContainer.elements.push(thElement);
  203. }.bind(this));
  204. }
  205. var baseTd = dataTr.cells[colIndex];
  206. for (var n=1; n<=cols; n++){
  207. var newTd = new Element("td").inject(baseTd, position);
  208. this.form.getTemplateData("Datatable$Data", function(data){
  209. var moduleData = Object.clone(data);
  210. var tdContainer = new MWF.FCDatatable$Data(this.form);
  211. tdContainer.load(moduleData, newTd, this.parentContainer);
  212. moduleList.push(tdContainer);
  213. this.parentContainer.containers.push(tdContainer);
  214. }.bind(this));
  215. }
  216. this.unSelected();
  217. this.selected();
  218. this.addHistoryLog( "insertCol", moduleList );
  219. },
  220. deleteCol: function(e){
  221. var module = this;
  222. this.form.designer.confirm("warn", e, MWF.LP.process.notice.deleteColTitle, MWF.LP.process.notice.deleteCol, 300, 120, function(){
  223. var tr = module.node.getParent("tr");
  224. var table = tr.getParent("table");
  225. var colIndex = module.node.cellIndex;
  226. var titleTr = table.rows[0];
  227. var dataTr = table.rows[1];
  228. if (tr.cells.length<=1){
  229. module.parentContainer.addHistoryLog("delete");
  230. }else{
  231. var deleteTh = titleTr.cells[colIndex];
  232. var deleteTd = dataTr.cells[colIndex];
  233. var thModule = deleteTh.retrieve("module");
  234. var tdModule = deleteTd.retrieve("module");
  235. module.addHistoryLog("deleteCol", [thModule, tdModule]);
  236. }
  237. module._deleteCol();
  238. this.close();
  239. }, function(){
  240. this.close();
  241. }, null);
  242. },
  243. _deleteCol: function(){
  244. var tr = this.node.getParent("tr");
  245. var table = tr.getParent("table");
  246. var colIndex = this.node.cellIndex;
  247. var titleTr = table.rows[0];
  248. var dataTr = table.rows[1];
  249. this.unSelected();
  250. if (tr.cells.length<=1){
  251. this.parentContainer.destroy();
  252. }else{
  253. var deleteTh = titleTr.cells[colIndex];
  254. var deleteTd = dataTr.cells[colIndex];
  255. var thModule = deleteTh.retrieve("module");
  256. if (thModule){
  257. thModule.parentContainer.elements.erase(thModule);
  258. thModule.destroy();
  259. }
  260. var tdModule = deleteTd.retrieve("module");
  261. if (tdModule){
  262. tdModule.parentContainer.containers.erase(tdModule);
  263. tdModule.destroy();
  264. }
  265. }
  266. },
  267. _setEditStyle_custom: function(name){
  268. debugger;
  269. if (name=="name"){
  270. if (!this.json.name){
  271. this.node.set("text", "DataTitle");
  272. }else{
  273. this.node.set("text", this.json.name);
  274. }
  275. this.textNode = null;
  276. this.setPrefixOrSuffix();
  277. }
  278. if( name=="isShow" ){
  279. this._switchShow( true );
  280. }
  281. if (name=="prefixIcon" || name=="suffixIcon"){
  282. this.setPrefixOrSuffix();
  283. }
  284. // if (name=="styles"){
  285. // this.resetPrefixOrSuffix();
  286. // }
  287. },
  288. // resetPrefixOrSuffix: function(){
  289. // if (this.prefixNode){
  290. // var y = this.textNode.getSize().y;
  291. // this.prefixNode.setStyle("height", ""+y+"px");
  292. // }
  293. // if (this.suffixNode){
  294. // var y = this.textNode.getSize().y;
  295. // this.suffixNode.setStyle("height", ""+y+"px");
  296. // }
  297. // },
  298. getOffsetY: function(){
  299. return (this.node.getStyle("padding-top") || 0).toInt()
  300. + (this.node.getStyle("padding-bottom") || 0).toInt()
  301. + (this.node.getStyle("border-top") || 0).toInt()
  302. + (this.node.getStyle("border-bottom") || 0).toInt();
  303. },
  304. setPrefixOrSuffix: function(){
  305. if (this.json.prefixIcon || this.json.suffixIcon){
  306. var lineheight = this.node.getStyle("line-height") || "28px";
  307. if (!this.textNode){
  308. var text = this.node.get("text");
  309. this.node.empty();
  310. this.wrapNode = new Element("div", {
  311. "styles": {
  312. "display": "flex",
  313. "align-items": "center",
  314. "justify-content": "center"
  315. }
  316. }).inject(this.node);
  317. if (this.json.prefixIcon){
  318. this.prefixNode = new Element("div", {"styles": {
  319. "width": "20px",
  320. "min-width": "20px",
  321. "height": lineheight,
  322. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  323. }}).inject(this.wrapNode);
  324. }
  325. this.textNode = new Element("div", {"styles": {
  326. "line-height": lineheight,
  327. "vertical-align": "top",
  328. "padding": "1px"
  329. }, "text": text}).inject(this.wrapNode);
  330. if (this.json.suffixIcon){
  331. this.suffixNode = new Element("div", {"styles": {
  332. "width": "20px",
  333. "min-width": "20px",
  334. "height": lineheight,
  335. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  336. }}).inject(this.wrapNode);
  337. }
  338. }else{
  339. if (this.json.prefixIcon){
  340. if (!this.prefixNode){
  341. this.prefixNode = new Element("div", {"styles": {
  342. "width": "20px",
  343. "min-width": "20px",
  344. "height": lineheight,
  345. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  346. }}).inject(this.textNode, "before");
  347. }else{
  348. this.prefixNode.setStyle("background", "url("+this.json.prefixIcon+") center center no-repeat");
  349. }
  350. }else{
  351. if (this.prefixNode){
  352. this.prefixNode.destroy();
  353. this.prefixNode = null;
  354. }
  355. }
  356. if (this.json.suffixIcon){
  357. if (!this.suffixNode){
  358. this.suffixNode = new Element("div", {"styles": {
  359. "width": "20px",
  360. "min-width": "20px",
  361. "height": lineheight,
  362. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  363. }}).inject(this.textNode, "after");
  364. }else{
  365. this.suffixNode.setStyle("background", "url("+this.json.suffixIcon+") center center no-repeat");
  366. }
  367. }else{
  368. if (this.suffixNode){
  369. this.suffixNode.destroy();
  370. this.suffixNode = null;
  371. }
  372. }
  373. }
  374. }else{
  375. //var text = this.textNode.get("text");
  376. this.node.empty();
  377. if (!this.json.name){
  378. this.node.set("text", "DataTitle");
  379. }else{
  380. this.node.set("text", this.json.name);
  381. }
  382. this.textNode = null;
  383. this.prefixNode = null;
  384. this.suffixNode = null;
  385. }
  386. },
  387. _switchShow: function( isChangeTd ){
  388. var tr = this.node.getParent("tr");
  389. var table = tr.getParent("table");
  390. var colIndex = this.node.cellIndex;
  391. var isShow = this.json.isShow !== false;
  392. var titleTr = table.rows[0];
  393. var currentTh = titleTr.cells[colIndex];
  394. if( currentTh ){
  395. currentTh.setStyle("opacity", isShow ? "1" : "0.3")
  396. }
  397. if(isChangeTd){
  398. var dataTr = table.rows[1];
  399. var currentTd = dataTr.cells[colIndex];
  400. if( currentTd ){
  401. var module = currentTd.retrieve("module");
  402. if( module )module._switchShow( isShow );
  403. }
  404. }
  405. }
  406. });