Table$Td.js 24 KB

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