Table$Td.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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.Table$Td = MWF.FCTable$Td = new Class({
  4. Extends: MWF.FC$Container,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_process_FormDesigner/Module/Table$Td/table$td.html",
  9. "actions": [
  10. {
  11. "name": "insertRow",
  12. "icon": "insertRow1.png",
  13. "event": "click",
  14. "action": "insertRow",
  15. "title": MWF.APPFD.LP.formAction.insertRow
  16. },
  17. {
  18. "name": "insertCol",
  19. "icon": "insertCol1.png",
  20. "event": "click",
  21. "action": "insertCol",
  22. "title": MWF.APPFD.LP.formAction.insertCol
  23. },
  24. {
  25. "name": "deleteRow",
  26. "icon": "deleteRow1.png",
  27. "event": "click",
  28. "action": "deleteRow",
  29. "title": MWF.APPFD.LP.formAction.deleteRow
  30. },
  31. {
  32. "name": "deleteCol",
  33. "icon": "deleteCol1.png",
  34. "event": "click",
  35. "action": "deleteCol",
  36. "title": MWF.APPFD.LP.formAction.deleteCol
  37. },
  38. {
  39. "name": "splitCell",
  40. "icon": "splitCell.png",
  41. "event": "click",
  42. "action": "splitCell",
  43. "title": MWF.APPFD.LP.formAction.splitCell
  44. }
  45. ],
  46. "injectActions" : [
  47. {
  48. "name" : "top",
  49. "styles" : "injectActionTop",
  50. "event" : "click",
  51. "action" : "injectTop",
  52. "title": MWF.APPFD.LP.formAction["insertTop"]
  53. },
  54. {
  55. "name" : "bottom",
  56. "styles" : "injectActionBottom",
  57. "event" : "click",
  58. "action" : "injectBottom",
  59. "title": MWF.APPFD.LP.formAction["insertBottom"]
  60. }
  61. ]
  62. },
  63. initialize: function(form, options){
  64. this.setOptions(options);
  65. this.path = "/x_component_process_FormDesigner/Module/Table$Td/";
  66. this.cssPath = "/x_component_process_FormDesigner/Module/Table$Td/"+this.options.style+"/css.wcss";
  67. this._loadCss();
  68. this.moduleType = "container";
  69. this.moduleName = "table$Td";
  70. this.Node = null;
  71. this.form = form;
  72. },
  73. setAllStyles: function(){
  74. Object.each(this.json.styles, function(value, key){
  75. var reg = /^border\w*/ig;
  76. if (!key.test(reg)){
  77. if (key) this.node.setStyle(key, value);
  78. }
  79. }.bind(this));
  80. this.setPropertiesOrStyles("properties");
  81. this.reloadMaplist();
  82. },
  83. over: function(){
  84. if (this.form.selectedModules.indexOf(this)==-1){
  85. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this) this.node.setStyles({
  86. "border-width": "1px",
  87. "border-color": "#0072ff"
  88. });
  89. }
  90. },
  91. unOver: function(){
  92. if (this.form.selectedModules.indexOf(this)==-1){
  93. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this) this.node.setStyles({
  94. "border-width": "1px",
  95. "border-color": "#999"
  96. });
  97. }
  98. },
  99. unSelected: function(){
  100. this.node.setStyles({
  101. "border-width": "1px",
  102. "border-color": "#999"
  103. });
  104. this._hideActions();
  105. this.form.currentSelectedModule = null;
  106. this.hideProperty();
  107. },
  108. _showActions: function(){
  109. if (this.actionArea){
  110. this._setActionAreaPosition();
  111. this.actionArea.setStyle("display", "block");
  112. var colspan = this.node.get("colspan").toInt() || 1;
  113. var rowspan = this.node.get("rowspan").toInt() || 1;
  114. if (colspan<=1 && rowspan<=1){
  115. this.actionArea.getLast("div").setStyle("display", "none");
  116. }else{
  117. this.actionArea.getLast("div").setStyle("display", "block");
  118. }
  119. }
  120. },
  121. unSelectedMulti: function(){
  122. if (this.form.selectedModules.indexOf(this)!=-1){
  123. this.form.selectedModules.erase(this);
  124. this.node.setStyle("border-color", "#999");
  125. }
  126. },
  127. load : function(json, node, parent){
  128. this.json = json;
  129. this.node= node;
  130. this.node.store("module", this);
  131. this.node.setStyles(this.css.moduleNode);
  132. if (!this.json.id){
  133. var id = this._getNewId(parent.json.id);
  134. this.json.id = id;
  135. }
  136. node.set({
  137. "MWFType": "table$Td",
  138. "id": this.json.id
  139. });
  140. if (!this.form.json.moduleList[this.json.id]){
  141. this.form.json.moduleList[this.json.id] = this.json;
  142. }
  143. this._initModule();
  144. this._loadTreeNode(parent);
  145. this.form.parseModules(this, this.node);
  146. this.parentContainer = this.treeNode.parentNode.module;
  147. this._setEditStyle_custom("id");
  148. this.json.moduleName = this.moduleName;
  149. },
  150. // _setNodeEvent: function(){
  151. // if (!this.isSetEvents){
  152. // this.node.addEvent("click", function(e){
  153. // this.selected();
  154. // e.stop();
  155. // }.bind(this));
  156. //
  157. // this.node.addEvent("mouseover", function(e){
  158. // this.over();
  159. // e.stop();
  160. // }.bind(this));
  161. // this.node.addEvent("mouseout", function(e){
  162. // this.unOver();
  163. // e.stop();
  164. // }.bind(this));
  165. //
  166. // this._setOtherNodeEvent();cellType
  167. // },
  168. _createMoveNode: function(){
  169. return false;
  170. },
  171. _setEditStyle_custom: function(name){
  172. if (name=="cellType"){
  173. this.setCustomStyles();
  174. }
  175. },
  176. setCustomStyles: function(){
  177. var border = this.node.getStyle("border");
  178. this.node.clearStyles();
  179. this.node.setStyles(this.css.moduleNode);
  180. var addStyles = {};
  181. if (this.json.cellType=="title"){
  182. addStyles = this.table.json.titleTdStyles
  183. }
  184. if (this.json.cellType=="content"){
  185. addStyles = this.table.json.contentTdStyles
  186. }
  187. if (this.json.cellType=="layout"){
  188. addStyles = this.table.json.layoutTdStyles
  189. }
  190. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  191. this.node.setStyle("border", border);
  192. Object.each(addStyles, function(value, key){
  193. if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
  194. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  195. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  196. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  197. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  198. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  199. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  200. }
  201. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  202. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  203. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  204. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  205. }
  206. }
  207. var reg = /^border\w*/ig;
  208. if (!key.test(reg)){
  209. if (key){
  210. if (key.toString().toLowerCase()==="display"){
  211. if (value.toString().toLowerCase()==="none"){
  212. this.node.setStyle("opacity", 0.3);
  213. }else{
  214. this.node.setStyle("opacity", 1);
  215. this.node.setStyle(key, value);
  216. }
  217. }else{
  218. this.node.setStyle(key, value);
  219. }
  220. }
  221. }
  222. }.bind(this));
  223. Object.each(this.json.styles, function(value, key){
  224. if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
  225. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  226. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  227. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  228. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  229. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  230. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  231. }
  232. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  233. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  234. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  235. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  236. }
  237. }
  238. var reg = /^border\w*/ig;
  239. if (!key.test(reg)){
  240. if (key){
  241. if (key.toString().toLowerCase()==="display"){
  242. if (value.toString().toLowerCase()==="none"){
  243. this.node.setStyle("opacity", 0.3);
  244. }else{
  245. this.node.setStyle("opacity", 1);
  246. this.node.setStyle(key, value);
  247. }
  248. }else{
  249. this.node.setStyle(key, value);
  250. }
  251. }
  252. }
  253. }.bind(this));
  254. },
  255. _dragInLikeElement: function(module){
  256. return false;
  257. },
  258. insertRow: function(){
  259. var module = this;
  260. var url = this.path+"insertRow.html";
  261. MWF.require("MWF.widget.Dialog", function(){
  262. var size = $(document.body).getSize();
  263. var x = size.x/2-150;
  264. var y = size.y/2-90;
  265. var dlg = new MWF.DL({
  266. "title": "Insert Row",
  267. "style": "property",
  268. "top": y,
  269. "left": x-40,
  270. "fromTop":size.y/2-45,
  271. "fromLeft": size.x/2,
  272. "width": 300,
  273. "height": 180,
  274. "url": url,
  275. "buttonList": [
  276. {
  277. "text": MWF.APPFD.LP.button.ok,
  278. "action": function(){
  279. module._insertRow();
  280. this.close();
  281. }
  282. },
  283. {
  284. "text": MWF.APPFD.LP.button.cancel,
  285. "action": function(){
  286. this.close();
  287. }
  288. }
  289. ]
  290. });
  291. dlg.show();
  292. }.bind(this));
  293. },
  294. _insertRow: function(){
  295. var rows = $("MWFInsertRowNumber").get("value");
  296. var positionRadios = document.getElementsByName("MWFInsertRowPosition");
  297. var position = "before";
  298. for (var i=0; i<positionRadios.length; i++){
  299. if (positionRadios[i].checked){
  300. position = positionRadios[i].value;
  301. break;
  302. }
  303. }
  304. var tr = this.node.getParent("tr");
  305. var table = tr.getParent("table");
  306. var cellNumber = tr.cells.length;
  307. var rowIndex = tr.rowIndex;
  308. var rowspanBeforeTds = table.getElements("td:rowspanBefore("+rowIndex+")");
  309. var colCurrentTds = tr.getElements("td:colspan");
  310. colCurrentTds.each(function(td){
  311. var colspan = td.get("colspan").toInt() || 1;
  312. cellNumber = cellNumber+colspan-1;
  313. });
  314. rowspanBeforeTds.each(function(td){
  315. this.__rowspanPlus(td, rows);
  316. }.bind(this));
  317. if (position=="after"){
  318. var rowspanCurrentTds = tr.getElements("td:rowspan");
  319. rowspanCurrentTds.each(function(td){
  320. this.__rowspanPlus(td, rows);
  321. var colspan = td.get("colspan").toInt() || 1;
  322. cellNumber = cellNumber-colspan;
  323. }.bind(this));
  324. }
  325. for (var n=1; n<=rows; n++){
  326. var newTr = new Element("tr").inject(tr, position);
  327. for (var m=1; m<=cellNumber; m++){
  328. var cell = new Element("td").inject(newTr);
  329. this.form.getTemplateData("Table$Td", function(data){
  330. var moduleData = Object.clone(data);
  331. var tdContainer = new MWF.FCTable$Td(this.form);
  332. tdContainer.table = this.table;
  333. tdContainer.load(moduleData, cell, this.parentContainer);
  334. this.parentContainer.containers.push(tdContainer);
  335. }.bind(this));
  336. }
  337. }
  338. this.unSelected();
  339. this.selected();
  340. },
  341. insertCol: function(){
  342. var module = this;
  343. var url = this.path+"insertCol.html";
  344. MWF.require("MWF.widget.Dialog", function(){
  345. var size = $(document.body).getSize();
  346. var x = size.x/2-150;
  347. var y = size.y/2-90;
  348. var dlg = new MWF.DL({
  349. "title": "Insert Col",
  350. "style": "property",
  351. "top": y,
  352. "left": x-40,
  353. "fromTop":size.y/2-45,
  354. "fromLeft": size.x/2,
  355. "width": 300,
  356. "height": 180,
  357. "url": url,
  358. "buttonList": [
  359. {
  360. "text": MWF.APPFD.LP.button.ok,
  361. "action": function(){
  362. module._insertCol();
  363. this.close();
  364. }
  365. },
  366. {
  367. "text": MWF.APPFD.LP.button.cancel,
  368. "action": function(){
  369. this.close();
  370. }
  371. }
  372. ]
  373. });
  374. dlg.show();
  375. }.bind(this));
  376. },
  377. _insertCol: function(){
  378. var cols = $("MWFInsertColNumber").get("value");
  379. var positionRadios = document.getElementsByName("MWFInsertColPosition");
  380. var position = "before";
  381. for (var i=0; i<positionRadios.length; i++){
  382. if (positionRadios[i].checked){
  383. position = positionRadios[i].value;
  384. break;
  385. }
  386. }
  387. var tr = this.node.getParent("tr");
  388. var table = tr.getParent("table");
  389. var colIndex = this.__getCellIndex(this.node);
  390. for (var m=1; m<=cols; m++){
  391. var insertTdObjs = this.__getInsertTableColTds(table, colIndex);
  392. insertTdObjs.each(function(obj){
  393. obj.td.inject(obj.toTd, position);
  394. this.form.getTemplateData("Table$Td", function(data){
  395. var moduleData = Object.clone(data);
  396. var tdContainer = new MWF.FCTable$Td(this.form);
  397. tdContainer.table = this.table;
  398. tdContainer.load(moduleData, obj.td, this.parentContainer);
  399. this.parentContainer.containers.push(tdContainer);
  400. }.bind(this));
  401. }.bind(this));
  402. }
  403. this.unSelected();
  404. this.selected();
  405. },
  406. deleteRow: function(e){
  407. var module = this;
  408. this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteRowTitle, MWF.APPFD.LP.notice.deleteRow, 300, 120, function(){
  409. module._deleteRow();
  410. this.close();
  411. }, function(){
  412. this.close();
  413. }, null);
  414. },
  415. __rowspanPlus: function(td,n){
  416. var rowspan = td.get("rowspan").toInt() || 1;
  417. rowspan = rowspan+n.toInt();
  418. var module = td.retrieve("module");
  419. if (rowspan>1){
  420. td.set("rowspan", rowspan);
  421. if (module) module.json.properties.rowspan = rowspan;
  422. }else{
  423. td.set("rowspan", 1);
  424. delete td.rowspan;
  425. if (module) delete module.json.properties.rowspan;
  426. }
  427. },
  428. __rowspanMinus: function(td){
  429. var rowspan = td.get("rowspan").toInt() || 1;
  430. rowspan = rowspan-1;
  431. var module = td.retrieve("module");
  432. if (rowspan>1){
  433. td.set("rowspan", rowspan);
  434. if (module) module.json.properties.rowspan = rowspan;
  435. }else{
  436. td.set("rowspan", 1);
  437. delete td.rowspan;
  438. if (module) delete module.json.properties.rowspan;
  439. }
  440. },
  441. __colspanPlus: function(td, n){
  442. var colspan = td.get("colspan").toInt() || 1;
  443. colspan = colspan+n.toInt();
  444. var module = td.retrieve("module");
  445. if (colspan>1){
  446. td.set("colspan", colspan);
  447. if (module) module.json.properties.colspan = colspan;
  448. }else{
  449. td.set("colspan", 1);
  450. delete td.colspan;
  451. if (module) delete module.json.properties.colspan;
  452. }
  453. },
  454. __colspanMinus: function(td){
  455. var colspan = td.get("colspan").toInt() || 1;
  456. colspan = colspan-1;
  457. var module = td.retrieve("module");
  458. if (colspan>1){
  459. td.set("colspan", colspan);
  460. if (module) module.json.properties.colspan = colspan;
  461. }else{
  462. td.set("colspan", 1);
  463. delete td.colspan;
  464. if (module) delete module.json.properties.colspan;
  465. }
  466. },
  467. __getNextTd: function(nextTr, cellIndex){
  468. var nextTd = null;
  469. while (cellIndex>0){
  470. if (!nextTd){
  471. nextTd = nextTr.getFirst("td");
  472. }else{
  473. nextTd = nextTd.getNext("td");
  474. }
  475. cellIndex--;
  476. var colspan = nextTd.get("colspan").toInt() || 1;
  477. cellIndex = cellIndex-colspan-1;
  478. }
  479. return nextTd;
  480. },
  481. __getCellIndex: function(td){
  482. var tr = td.getParent("tr");
  483. var table = tr.getParent("table");
  484. // var rowindex = tr.rowIndex;
  485. var idx = -1;
  486. var trs = table.rows;
  487. var rowspanTds = {};
  488. var isBreak = false;
  489. for (var i=0; i<trs.length; i++){
  490. var ervryTd = null;
  491. var j=0;
  492. while (true){
  493. var rowspan = rowspanTds["rowspan_"+j];
  494. if (rowspan){
  495. rowspan.rows = rowspan.rows-1;
  496. if (!rowspan.rows){
  497. delete rowspanTds["rowspan_"+j];
  498. }
  499. j++;
  500. }else{
  501. if (!ervryTd){
  502. ervryTd = trs[i].getFirst("td");
  503. }else{
  504. ervryTd = ervryTd.getNext("td");
  505. }
  506. if (!ervryTd) break;
  507. if (ervryTd==td){
  508. idx = j;
  509. isBreak = true;
  510. break;
  511. }else{
  512. var rowspan = ervryTd.get("rowspan").toInt() || 1;
  513. var colspan = ervryTd.get("colspan").toInt() || 1;
  514. if (rowspan>1){
  515. var rows = rowspan-1;
  516. for (var x=0; x<colspan; x++){
  517. var n = j+x;
  518. rowspanTds["rowspan_"+n] = {"rows": rows};
  519. }
  520. }
  521. j = j + colspan-1;
  522. }
  523. j++;
  524. }
  525. }
  526. if (isBreak) break;
  527. }
  528. return idx;
  529. },
  530. __getInsertTableColTds: function(table, idx){
  531. var insertTds = [];
  532. var trs = table.rows;
  533. var rowspanTds = {};
  534. for (var i=0; i<trs.length; i++){
  535. var ervryTd = null;
  536. var j=0;
  537. while (true){
  538. var rowspan = rowspanTds["rowspan_"+j];
  539. if (rowspan){
  540. rowspan.rows = rowspan.rows-1;
  541. if (!rowspan.rows){
  542. delete rowspanTds["rowspan_"+j];
  543. }
  544. j++;
  545. }else{
  546. if (!ervryTd){
  547. ervryTd = trs[i].getFirst("td");
  548. }else{
  549. ervryTd = ervryTd.getNext("td");
  550. }
  551. if (!ervryTd) break;
  552. var rowspan = ervryTd.get("rowspan").toInt() || 1;
  553. var colspan = ervryTd.get("colspan").toInt() || 1;
  554. if (rowspan>1){
  555. var rows = rowspan-1;
  556. for (var x=0; x<colspan; x++){
  557. var n = j+x;
  558. rowspanTds["rowspan_"+n] = {"rows": rows};
  559. }
  560. }
  561. if (colspan>1){
  562. if (j + colspan-1>=idx && j<=idx){
  563. // ervryTd.setStyle("background", "#FF9999");
  564. this.__colspanPlus(ervryTd, 1);
  565. break;
  566. }
  567. }else{
  568. if (j==idx){
  569. var newTd = new Element("td");
  570. insertTds.push({"td": newTd, "toTd": ervryTd});
  571. break;
  572. }
  573. }
  574. j = j + colspan-1;
  575. j++;
  576. }
  577. }
  578. }
  579. return insertTds;
  580. },
  581. __getDeleteTableColTds: function(table, idx){
  582. var deleteTds = [];
  583. var trs = table.rows;
  584. var rowspanTds = {};
  585. for (var i=0; i<trs.length; i++){
  586. var ervryTd = null;
  587. var j=0;
  588. while (true){
  589. var rowspan = rowspanTds["rowspan_"+j];
  590. if (rowspan){
  591. rowspan.rows = rowspan.rows-1;
  592. if (!rowspan.rows){
  593. delete rowspanTds["rowspan_"+j];
  594. }
  595. j++;
  596. }else{
  597. if (!ervryTd){
  598. ervryTd = trs[i].getFirst("td");
  599. }else{
  600. ervryTd = ervryTd.getNext("td");
  601. }
  602. if (!ervryTd) break;
  603. var rowspan = ervryTd.get("rowspan").toInt() || 1;
  604. var colspan = ervryTd.get("colspan").toInt() || 1;
  605. if (rowspan>1){
  606. var rows = rowspan-1;
  607. for (var x=0; x<colspan; x++){
  608. var n = j+x;
  609. rowspanTds["rowspan_"+n] = {"rows": rows};
  610. }
  611. }
  612. if (colspan>1){
  613. if (j + colspan-1>=idx && j<=idx){
  614. // ervryTd.setStyle("background", "#FF9999");
  615. this.__colspanMinus(ervryTd);
  616. break;
  617. }
  618. }else{
  619. if (j==idx){
  620. deleteTds.push(ervryTd);
  621. break;
  622. }
  623. }
  624. j = j + colspan-1;
  625. j++;
  626. }
  627. }
  628. }
  629. return deleteTds;
  630. },
  631. _deleteRow:function(){
  632. var _form = this.form;
  633. var tr = this.node.getParent("tr");
  634. var table = tr.getParent("table");
  635. var rowIndex = tr.rowIndex;
  636. // var currentRowspan = this.node.get("rowspan").toInt() || 1;
  637. var rowspanBeforeTds = table.getElements("td:rowspanBefore("+rowIndex+")");
  638. var rowspanCurrentTds = tr.getElements("td:rowspan");
  639. rowspanBeforeTds.each(function(td){
  640. this.__rowspanMinus(td);
  641. }.bind(this));
  642. rowspanCurrentTds.each(function(td){
  643. this.__rowspanMinus(td);
  644. var nextTr = table.rows[rowIndex+1];
  645. if (nextTr){
  646. var cellIndex = td.cellIndex;
  647. var nextTd = null;
  648. if (cellIndex>0){
  649. nextTd = this.__getNextTd(nextTr, cellIndex);
  650. }else{
  651. nextTd = this.__getNextTd(nextTr, 2);
  652. }
  653. if (nextTd) td.inject(nextTd, "after");
  654. }
  655. }.bind(this));
  656. if (table.rows.length<=1){
  657. this.parentContainer.destroy();
  658. }else{
  659. tds = tr.getElements("td");
  660. tds.each(function(td){
  661. var module = td.retrieve("module");
  662. if (module){
  663. module.parentContainer.containers.erase(module);
  664. module.destroy();
  665. }
  666. });
  667. tr.destroy();
  668. }
  669. _form.currentSelectedModule = null;
  670. _form.selected();
  671. _form = null;
  672. },
  673. deleteCol: function(e){
  674. var module = this;
  675. this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteColTitle, MWF.APPFD.LP.notice.deleteCol, 300, 120, function(){
  676. module._deleteCol();
  677. this.close();
  678. }, function(){
  679. this.close();
  680. }, null);
  681. },
  682. _deleteCol: function(){
  683. var _form = this.form;
  684. var tr = this.node.getParent("tr");
  685. var table = tr.getParent("table");
  686. var colIndex = this.__getCellIndex(this.node);
  687. var currentRowspan = this.node.get("colspan").toInt() || 1;
  688. if (tr.cells.length<=1 && currentRowspan<=1){
  689. this.parentContainer.destroy();
  690. }else{
  691. var deleteTds = this.__getDeleteTableColTds(table, colIndex);
  692. deleteTds.each(function(dtd){
  693. // dtd.setStyle("background", "#999999");
  694. var module = dtd.retrieve("module");
  695. if (module){
  696. module.parentContainer.containers.erase(module);
  697. module.destroy();
  698. }
  699. });
  700. }
  701. _form.currentSelectedModule = null;
  702. _form.selected();
  703. _form = null;
  704. },
  705. // __getTdByIndex11: function(tr, idx){
  706. // //??????????????????????????????????????
  707. // //??????????????????????????????????????
  708. // //??????????????????????????????????????
  709. // //??????????????????????????????????????
  710. // //??????????????????????????????????????
  711. // var findTd = false;
  712. // var td = null;
  713. // var n=-1;
  714. // while (n!=idx){
  715. // if (!td){
  716. // td = tr.getFirst("td");
  717. // }else{
  718. // td = tr.getNext("td");
  719. // }
  720. // var colspan = td.get("colspan").toInt() || 1;
  721. // n = n+colspan;
  722. // if (n>=idx && n-colspan<=idx) n=idx;
  723. // }
  724. // return td;
  725. // },
  726. __getTdsByIndex: function(table, beginRow, rows, idx){
  727. var indexTds = [];
  728. var trs = table.rows;
  729. var rowspanTds = {};
  730. for (var i=0; i<trs.length; i++){
  731. var ervryTd = null;
  732. var j=0;
  733. var findTd=false;
  734. while (true){
  735. var rowspan = rowspanTds["rowspan_"+j];
  736. if (rowspan){
  737. rowspan.rows = rowspan.rows-1;
  738. if (!rowspan.rows){
  739. delete rowspanTds["rowspan_"+j];
  740. }
  741. j++;
  742. }else{
  743. if (!ervryTd){
  744. ervryTd = trs[i].getFirst("td");
  745. }else{
  746. ervryTd = ervryTd.getNext("td");
  747. }
  748. if (!ervryTd){
  749. if (i>=beginRow && i<=beginRow+rows) if (!findTd) indexTds.push(null);
  750. break;
  751. }
  752. var rowspan = ervryTd.get("rowspan").toInt() || 1;
  753. var colspan = ervryTd.get("colspan").toInt() || 1;
  754. var rows;
  755. if (rowspan>1){
  756. rows = rowspan-1;
  757. for (var x=0; x<colspan; x++){
  758. var n = j+x;
  759. rowspanTds["rowspan_"+n] = {"rows": rows};
  760. }
  761. }
  762. if (j + colspan-1>=idx && j<=idx){
  763. if (i>=beginRow && i<=beginRow+rows){
  764. indexTds.push(ervryTd);
  765. findTd = true;
  766. }
  767. break;
  768. }
  769. j = j + colspan-1;
  770. j++;
  771. }
  772. }
  773. }
  774. return indexTds;
  775. },
  776. splitCell: function(){
  777. var colspan = this.node.get("colspan").toInt() || 1;
  778. var rowspan = this.node.get("rowspan").toInt() || 1;
  779. var tr = this.node.getParent("tr");
  780. var table = tr.getParent("table");
  781. var rowIndex = tr.rowIndex;
  782. var colIndex = this.__getCellIndex(this.node);
  783. this.node.set("rowspan", 1);
  784. delete this.node.rowspan;
  785. delete this.json.properties.rowspan;
  786. this.node.set("colspan", 1);
  787. delete this.node.colspan;
  788. delete this.json.properties.colspan;
  789. if (this.form.currentSelectedModule) this.form.currentSelectedModule.unSelected();
  790. this.unSelectedMulti();
  791. this.selectedMulti();
  792. var startTds = this.__getTdsByIndex(table, rowIndex+1, rowspan-1, colIndex-1);
  793. for (var i=1; i<=rowspan; i++){
  794. if (i==1){
  795. for (var j=2; j<=colspan; j++){
  796. var newTd = new Element("td").inject(this.node, "after");
  797. this.form.getTemplateData("Table$Td", function(data){
  798. var moduleData = Object.clone(data);
  799. var tdContainer = new MWF.FCTable$Td(this.form);
  800. tdContainer.table = this.table;
  801. tdContainer.load(moduleData, newTd, this.parentContainer);
  802. this.parentContainer.containers.push(tdContainer);
  803. tdContainer.selectedMulti();
  804. }.bind(this));
  805. }
  806. }else{
  807. var tr = tr.getNext("tr");
  808. var startTd = startTds[i-2];
  809. for (var j=1; j<=colspan; j++){
  810. var newTd = new Element("td");
  811. if (startTd){
  812. newTd.inject(startTd, "after");
  813. }else{
  814. newTd.inject(tr, "top");
  815. }
  816. this.form.getTemplateData("Table$Td", function(data){
  817. var moduleData = Object.clone(data);
  818. var tdContainer = new MWF.FCTable$Td(this.form);
  819. tdContainer.table = this.table;
  820. tdContainer.load(moduleData, newTd, this.parentContainer);
  821. this.parentContainer.containers.push(tdContainer);
  822. tdContainer.selectedMulti();
  823. }.bind(this));
  824. }
  825. }
  826. }
  827. this.form._completeSelectMulti();
  828. }
  829. //_showInjectAction : function( module ){
  830. // if ( module.moveNode ){
  831. // module.moveNode.setStyle("display","none");
  832. // }
  833. //
  834. // this.draggingModule = module;
  835. // if( !this.node.getFirst() ){
  836. // this.inject( "top" );
  837. // return;
  838. // }
  839. //
  840. // if( !this.injectActionArea )this._createInjectAction();
  841. // this.injectActionArea.setStyle("display","");
  842. // this._setInjectActionAreaPosition();
  843. //}
  844. });