Table$Td.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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. _preprocessingSetNodeStyles: function(styles){
  177. Object.each(styles, function(value, key){
  178. if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  179. this.node.setStyle(key, value);
  180. }
  181. }.bind(this));
  182. },
  183. _preprocessingModuleData: function(){
  184. this.node.clearStyles();
  185. var addStyles = {};
  186. if (this.json.cellType==="title") addStyles = this.table.json.titleTdStyles;
  187. if (this.json.cellType==="content") addStyles = this.table.json.contentTdStyles;
  188. if (this.json.cellType==="layout") addStyles = this.table.json.layoutTdStyles;
  189. this._preprocessingSetNodeStyles(addStyles);
  190. if (this.json.styles){
  191. this.json.recoveryStyles = Object.clone(this.json.styles);
  192. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  193. if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  194. this.node.setStyle(key, value);
  195. delete this.json.styles[key];
  196. }
  197. }.bind(this));
  198. }
  199. this.json.preprocessing = "y";
  200. },
  201. _recoveryModuleData: function(){
  202. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  203. this.json.recoveryStyles = null;
  204. },
  205. setCustomStyles: function(){
  206. this._recoveryModuleData();
  207. var border = this.node.getStyle("border");
  208. this.node.clearStyles();
  209. this.node.setStyles(this.css.moduleNode);
  210. var addStyles = {};
  211. if (this.json.cellType=="title"){
  212. addStyles = this.table.json.titleTdStyles;
  213. }
  214. if (this.json.cellType=="content"){
  215. addStyles = this.table.json.contentTdStyles;
  216. }
  217. if (this.json.cellType=="layout"){
  218. addStyles = this.table.json.layoutTdStyles;
  219. }
  220. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  221. this.node.setStyle("border", border);
  222. Object.each(addStyles, function(value, key){
  223. if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
  224. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  225. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  226. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  227. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  228. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  229. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  230. }
  231. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  232. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  233. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  234. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  235. }
  236. }
  237. var reg = /^border\w*/ig;
  238. if (!key.test(reg)){
  239. if (key){
  240. if (key.toString().toLowerCase()==="display"){
  241. if (value.toString().toLowerCase()==="none"){
  242. this.node.setStyle("opacity", 0.3);
  243. }else{
  244. this.node.setStyle("opacity", 1);
  245. this.node.setStyle(key, value);
  246. }
  247. }else{
  248. this.node.setStyle(key, value);
  249. }
  250. }
  251. }
  252. }.bind(this));
  253. Object.each(this.json.styles, function(value, key){
  254. if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
  255. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  256. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  257. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  258. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  259. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  260. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  261. }
  262. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  263. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  264. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  265. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  266. }
  267. }
  268. var reg = /^border\w*/ig;
  269. if (!key.test(reg)){
  270. if (key){
  271. if (key.toString().toLowerCase()==="display"){
  272. if (value.toString().toLowerCase()==="none"){
  273. this.node.setStyle("opacity", 0.3);
  274. }else{
  275. this.node.setStyle("opacity", 1);
  276. this.node.setStyle(key, value);
  277. }
  278. }else{
  279. this.node.setStyle(key, value);
  280. }
  281. }
  282. }
  283. }.bind(this));
  284. },
  285. _dragInLikeElement: function(module){
  286. return false;
  287. },
  288. insertRow: function(){
  289. var module = this;
  290. var url = this.path+"insertRow.html";
  291. MWF.require("MWF.widget.Dialog", function(){
  292. var size = $(document.body).getSize();
  293. var x = size.x/2-150;
  294. var y = size.y/2-90;
  295. var dlg = new MWF.DL({
  296. "title": "Insert Row",
  297. "style": "property",
  298. "top": y,
  299. "left": x-40,
  300. "fromTop":size.y/2-45,
  301. "fromLeft": size.x/2,
  302. "width": 300,
  303. "height": 180,
  304. "url": url,
  305. "buttonList": [
  306. {
  307. "text": MWF.APPFD.LP.button.ok,
  308. "action": function(){
  309. module._insertRow();
  310. this.close();
  311. }
  312. },
  313. {
  314. "text": MWF.APPFD.LP.button.cancel,
  315. "action": function(){
  316. this.close();
  317. }
  318. }
  319. ]
  320. });
  321. dlg.show();
  322. }.bind(this));
  323. },
  324. _insertRow: function(){
  325. var rows = $("MWFInsertRowNumber").get("value");
  326. var positionRadios = document.getElementsByName("MWFInsertRowPosition");
  327. var position = "before";
  328. for (var i=0; i<positionRadios.length; i++){
  329. if (positionRadios[i].checked){
  330. position = positionRadios[i].value;
  331. break;
  332. }
  333. }
  334. var tr = this.node.getParent("tr");
  335. var table = tr.getParent("table");
  336. var cellNumber = tr.cells.length;
  337. var rowIndex = tr.rowIndex;
  338. var rowspanBeforeTds = table.getElements("td:rowspanBefore("+rowIndex+")");
  339. var colCurrentTds = tr.getElements("td:colspan");
  340. colCurrentTds.each(function(td){
  341. var colspan = td.get("colspan").toInt() || 1;
  342. cellNumber = cellNumber+colspan-1;
  343. });
  344. rowspanBeforeTds.each(function(td){
  345. this.__rowspanPlus(td, rows);
  346. }.bind(this));
  347. if (position=="after"){
  348. var rowspanCurrentTds = tr.getElements("td:rowspan");
  349. rowspanCurrentTds.each(function(td){
  350. this.__rowspanPlus(td, rows);
  351. var colspan = td.get("colspan").toInt() || 1;
  352. cellNumber = cellNumber-colspan;
  353. }.bind(this));
  354. }
  355. for (var n=1; n<=rows; n++){
  356. var newTr = new Element("tr").inject(tr, position);
  357. for (var m=1; m<=cellNumber; m++){
  358. var cell = new Element("td").inject(newTr);
  359. this.form.getTemplateData("Table$Td", function(data){
  360. var moduleData = Object.clone(data);
  361. var tdContainer = new MWF.FCTable$Td(this.form);
  362. tdContainer.table = this.table;
  363. tdContainer.load(moduleData, cell, this.parentContainer);
  364. this.parentContainer.containers.push(tdContainer);
  365. }.bind(this));
  366. }
  367. }
  368. this.unSelected();
  369. this.selected();
  370. },
  371. insertCol: function(){
  372. var module = this;
  373. var url = this.path+"insertCol.html";
  374. MWF.require("MWF.widget.Dialog", function(){
  375. var size = $(document.body).getSize();
  376. var x = size.x/2-150;
  377. var y = size.y/2-90;
  378. var dlg = new MWF.DL({
  379. "title": "Insert Col",
  380. "style": "property",
  381. "top": y,
  382. "left": x-40,
  383. "fromTop":size.y/2-45,
  384. "fromLeft": size.x/2,
  385. "width": 300,
  386. "height": 180,
  387. "url": url,
  388. "buttonList": [
  389. {
  390. "text": MWF.APPFD.LP.button.ok,
  391. "action": function(){
  392. module._insertCol();
  393. this.close();
  394. }
  395. },
  396. {
  397. "text": MWF.APPFD.LP.button.cancel,
  398. "action": function(){
  399. this.close();
  400. }
  401. }
  402. ]
  403. });
  404. dlg.show();
  405. }.bind(this));
  406. },
  407. _insertCol: function(){
  408. var cols = $("MWFInsertColNumber").get("value");
  409. var positionRadios = document.getElementsByName("MWFInsertColPosition");
  410. var position = "before";
  411. for (var i=0; i<positionRadios.length; i++){
  412. if (positionRadios[i].checked){
  413. position = positionRadios[i].value;
  414. break;
  415. }
  416. }
  417. var tr = this.node.getParent("tr");
  418. var table = tr.getParent("table");
  419. var colIndex = this.__getCellIndex(this.node);
  420. for (var m=1; m<=cols; m++){
  421. var insertTdObjs = this.__getInsertTableColTds(table, colIndex);
  422. insertTdObjs.each(function(obj){
  423. obj.td.inject(obj.toTd, position);
  424. this.form.getTemplateData("Table$Td", function(data){
  425. var moduleData = Object.clone(data);
  426. var tdContainer = new MWF.FCTable$Td(this.form);
  427. tdContainer.table = this.table;
  428. tdContainer.load(moduleData, obj.td, this.parentContainer);
  429. this.parentContainer.containers.push(tdContainer);
  430. }.bind(this));
  431. }.bind(this));
  432. }
  433. this.unSelected();
  434. this.selected();
  435. },
  436. deleteRow: function(e){
  437. var module = this;
  438. this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteRowTitle, MWF.APPFD.LP.notice.deleteRow, 300, 120, function(){
  439. module._deleteRow();
  440. this.close();
  441. }, function(){
  442. this.close();
  443. }, null);
  444. },
  445. __rowspanPlus: function(td,n){
  446. var rowspan = td.get("rowspan").toInt() || 1;
  447. rowspan = rowspan+n.toInt();
  448. var module = td.retrieve("module");
  449. if (rowspan>1){
  450. td.set("rowspan", rowspan);
  451. if (module) module.json.properties.rowspan = rowspan;
  452. }else{
  453. td.set("rowspan", 1);
  454. delete td.rowspan;
  455. if (module) delete module.json.properties.rowspan;
  456. }
  457. },
  458. __rowspanMinus: function(td){
  459. var rowspan = td.get("rowspan").toInt() || 1;
  460. rowspan = rowspan-1;
  461. var module = td.retrieve("module");
  462. if (rowspan>1){
  463. td.set("rowspan", rowspan);
  464. if (module) module.json.properties.rowspan = rowspan;
  465. }else{
  466. td.set("rowspan", 1);
  467. delete td.rowspan;
  468. if (module) delete module.json.properties.rowspan;
  469. }
  470. },
  471. __colspanPlus: function(td, n){
  472. var colspan = td.get("colspan").toInt() || 1;
  473. colspan = colspan+n.toInt();
  474. var module = td.retrieve("module");
  475. if (colspan>1){
  476. td.set("colspan", colspan);
  477. if (module) module.json.properties.colspan = colspan;
  478. }else{
  479. td.set("colspan", 1);
  480. delete td.colspan;
  481. if (module) delete module.json.properties.colspan;
  482. }
  483. },
  484. __colspanMinus: function(td){
  485. var colspan = td.get("colspan").toInt() || 1;
  486. colspan = colspan-1;
  487. var module = td.retrieve("module");
  488. if (colspan>1){
  489. td.set("colspan", colspan);
  490. if (module) module.json.properties.colspan = colspan;
  491. }else{
  492. td.set("colspan", 1);
  493. delete td.colspan;
  494. if (module) delete module.json.properties.colspan;
  495. }
  496. },
  497. __getNextTd: function(nextTr, cellIndex){
  498. var nextTd = null;
  499. while (cellIndex>0){
  500. if (!nextTd){
  501. nextTd = nextTr.getFirst("td");
  502. }else{
  503. nextTd = nextTd.getNext("td");
  504. }
  505. cellIndex--;
  506. var colspan = nextTd.get("colspan").toInt() || 1;
  507. cellIndex = cellIndex-colspan-1;
  508. }
  509. return nextTd;
  510. },
  511. __getCellIndex: function(td){
  512. var tr = td.getParent("tr");
  513. var table = tr.getParent("table");
  514. // var rowindex = tr.rowIndex;
  515. var idx = -1;
  516. var trs = table.rows;
  517. var rowspanTds = {};
  518. var isBreak = false;
  519. for (var i=0; i<trs.length; i++){
  520. var ervryTd = null;
  521. var j=0;
  522. while (true){
  523. var rowspan = rowspanTds["rowspan_"+j];
  524. if (rowspan){
  525. rowspan.rows = rowspan.rows-1;
  526. if (!rowspan.rows){
  527. delete rowspanTds["rowspan_"+j];
  528. }
  529. j++;
  530. }else{
  531. if (!ervryTd){
  532. ervryTd = trs[i].getFirst("td");
  533. }else{
  534. ervryTd = ervryTd.getNext("td");
  535. }
  536. if (!ervryTd) break;
  537. if (ervryTd==td){
  538. idx = j;
  539. isBreak = true;
  540. break;
  541. }else{
  542. var rowspan = ervryTd.get("rowspan").toInt() || 1;
  543. var colspan = ervryTd.get("colspan").toInt() || 1;
  544. if (rowspan>1){
  545. var rows = rowspan-1;
  546. for (var x=0; x<colspan; x++){
  547. var n = j+x;
  548. rowspanTds["rowspan_"+n] = {"rows": rows};
  549. }
  550. }
  551. j = j + colspan-1;
  552. }
  553. j++;
  554. }
  555. }
  556. if (isBreak) break;
  557. }
  558. return idx;
  559. },
  560. __getInsertTableColTds: function(table, idx){
  561. var insertTds = [];
  562. var trs = table.rows;
  563. var rowspanTds = {};
  564. for (var i=0; i<trs.length; i++){
  565. var ervryTd = null;
  566. var j=0;
  567. while (true){
  568. var rowspan = rowspanTds["rowspan_"+j];
  569. if (rowspan){
  570. rowspan.rows = rowspan.rows-1;
  571. if (!rowspan.rows){
  572. delete rowspanTds["rowspan_"+j];
  573. }
  574. j++;
  575. }else{
  576. if (!ervryTd){
  577. ervryTd = trs[i].getFirst("td");
  578. }else{
  579. ervryTd = ervryTd.getNext("td");
  580. }
  581. if (!ervryTd) break;
  582. var rowspan = ervryTd.get("rowspan").toInt() || 1;
  583. var colspan = ervryTd.get("colspan").toInt() || 1;
  584. if (rowspan>1){
  585. var rows = rowspan-1;
  586. for (var x=0; x<colspan; x++){
  587. var n = j+x;
  588. rowspanTds["rowspan_"+n] = {"rows": rows};
  589. }
  590. }
  591. if (colspan>1){
  592. if (j + colspan-1>=idx && j<=idx){
  593. // ervryTd.setStyle("background", "#FF9999");
  594. this.__colspanPlus(ervryTd, 1);
  595. break;
  596. }
  597. }else{
  598. if (j==idx){
  599. var newTd = new Element("td");
  600. insertTds.push({"td": newTd, "toTd": ervryTd});
  601. break;
  602. }
  603. }
  604. j = j + colspan-1;
  605. j++;
  606. }
  607. }
  608. }
  609. return insertTds;
  610. },
  611. __getDeleteTableColTds: function(table, idx){
  612. var deleteTds = [];
  613. var trs = table.rows;
  614. var rowspanTds = {};
  615. for (var i=0; i<trs.length; i++){
  616. var ervryTd = null;
  617. var j=0;
  618. while (true){
  619. var rowspan = rowspanTds["rowspan_"+j];
  620. if (rowspan){
  621. rowspan.rows = rowspan.rows-1;
  622. if (!rowspan.rows){
  623. delete rowspanTds["rowspan_"+j];
  624. }
  625. j++;
  626. }else{
  627. if (!ervryTd){
  628. ervryTd = trs[i].getFirst("td");
  629. }else{
  630. ervryTd = ervryTd.getNext("td");
  631. }
  632. if (!ervryTd) break;
  633. var rowspan = ervryTd.get("rowspan").toInt() || 1;
  634. var colspan = ervryTd.get("colspan").toInt() || 1;
  635. if (rowspan>1){
  636. var rows = rowspan-1;
  637. for (var x=0; x<colspan; x++){
  638. var n = j+x;
  639. rowspanTds["rowspan_"+n] = {"rows": rows};
  640. }
  641. }
  642. if (colspan>1){
  643. if (j + colspan-1>=idx && j<=idx){
  644. // ervryTd.setStyle("background", "#FF9999");
  645. this.__colspanMinus(ervryTd);
  646. break;
  647. }
  648. }else{
  649. if (j==idx){
  650. deleteTds.push(ervryTd);
  651. break;
  652. }
  653. }
  654. j = j + colspan-1;
  655. j++;
  656. }
  657. }
  658. }
  659. return deleteTds;
  660. },
  661. _deleteRow:function(){
  662. var _form = this.form;
  663. var tr = this.node.getParent("tr");
  664. var table = tr.getParent("table");
  665. var rowIndex = tr.rowIndex;
  666. // var currentRowspan = this.node.get("rowspan").toInt() || 1;
  667. var rowspanBeforeTds = table.getElements("td:rowspanBefore("+rowIndex+")");
  668. var rowspanCurrentTds = tr.getElements("td:rowspan");
  669. rowspanBeforeTds.each(function(td){
  670. this.__rowspanMinus(td);
  671. }.bind(this));
  672. rowspanCurrentTds.each(function(td){
  673. this.__rowspanMinus(td);
  674. var nextTr = table.rows[rowIndex+1];
  675. if (nextTr){
  676. var cellIndex = td.cellIndex;
  677. var nextTd = null;
  678. if (cellIndex>0){
  679. nextTd = this.__getNextTd(nextTr, cellIndex);
  680. }else{
  681. nextTd = this.__getNextTd(nextTr, 2);
  682. }
  683. if (nextTd) td.inject(nextTd, "after");
  684. }
  685. }.bind(this));
  686. if (table.rows.length<=1){
  687. this.parentContainer.destroy();
  688. }else{
  689. tds = tr.getElements("td");
  690. tds.each(function(td){
  691. var module = td.retrieve("module");
  692. if (module){
  693. module.parentContainer.containers.erase(module);
  694. module.destroy();
  695. }
  696. });
  697. tr.destroy();
  698. }
  699. _form.currentSelectedModule = null;
  700. _form.selected();
  701. _form = null;
  702. },
  703. deleteCol: function(e){
  704. var module = this;
  705. this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteColTitle, MWF.APPFD.LP.notice.deleteCol, 300, 120, function(){
  706. module._deleteCol();
  707. this.close();
  708. }, function(){
  709. this.close();
  710. }, null);
  711. },
  712. _deleteCol: function(){
  713. var _form = this.form;
  714. var tr = this.node.getParent("tr");
  715. var table = tr.getParent("table");
  716. var colIndex = this.__getCellIndex(this.node);
  717. var currentRowspan = this.node.get("colspan").toInt() || 1;
  718. if (tr.cells.length<=1 && currentRowspan<=1){
  719. this.parentContainer.destroy();
  720. }else{
  721. var deleteTds = this.__getDeleteTableColTds(table, colIndex);
  722. deleteTds.each(function(dtd){
  723. // dtd.setStyle("background", "#999999");
  724. var module = dtd.retrieve("module");
  725. if (module){
  726. module.parentContainer.containers.erase(module);
  727. module.destroy();
  728. }
  729. });
  730. }
  731. _form.currentSelectedModule = null;
  732. _form.selected();
  733. _form = null;
  734. },
  735. // __getTdByIndex11: function(tr, idx){
  736. // //??????????????????????????????????????
  737. // //??????????????????????????????????????
  738. // //??????????????????????????????????????
  739. // //??????????????????????????????????????
  740. // //??????????????????????????????????????
  741. // var findTd = false;
  742. // var td = null;
  743. // var n=-1;
  744. // while (n!=idx){
  745. // if (!td){
  746. // td = tr.getFirst("td");
  747. // }else{
  748. // td = tr.getNext("td");
  749. // }
  750. // var colspan = td.get("colspan").toInt() || 1;
  751. // n = n+colspan;
  752. // if (n>=idx && n-colspan<=idx) n=idx;
  753. // }
  754. // return td;
  755. // },
  756. __getTdsByIndex: function(table, beginRow, rows, idx){
  757. var indexTds = [];
  758. var trs = table.rows;
  759. var rowspanTds = {};
  760. for (var i=0; i<trs.length; i++){
  761. var ervryTd = null;
  762. var j=0;
  763. var findTd=false;
  764. while (true){
  765. var rowspan = rowspanTds["rowspan_"+j];
  766. if (rowspan){
  767. rowspan.rows = rowspan.rows-1;
  768. if (!rowspan.rows){
  769. delete rowspanTds["rowspan_"+j];
  770. }
  771. j++;
  772. }else{
  773. if (!ervryTd){
  774. ervryTd = trs[i].getFirst("td");
  775. }else{
  776. ervryTd = ervryTd.getNext("td");
  777. }
  778. if (!ervryTd){
  779. if (i>=beginRow && i<=beginRow+rows) if (!findTd) indexTds.push(null);
  780. break;
  781. }
  782. var rowspan = ervryTd.get("rowspan").toInt() || 1;
  783. var colspan = ervryTd.get("colspan").toInt() || 1;
  784. var rows;
  785. if (rowspan>1){
  786. rows = rowspan-1;
  787. for (var x=0; x<colspan; x++){
  788. var n = j+x;
  789. rowspanTds["rowspan_"+n] = {"rows": rows};
  790. }
  791. }
  792. if (j + colspan-1>=idx && j<=idx){
  793. if (i>=beginRow && i<=beginRow+rows){
  794. indexTds.push(ervryTd);
  795. findTd = true;
  796. }
  797. break;
  798. }
  799. j = j + colspan-1;
  800. j++;
  801. }
  802. }
  803. }
  804. return indexTds;
  805. },
  806. splitCell: function(){
  807. var colspan = this.node.get("colspan").toInt() || 1;
  808. var rowspan = this.node.get("rowspan").toInt() || 1;
  809. var tr = this.node.getParent("tr");
  810. var table = tr.getParent("table");
  811. var rowIndex = tr.rowIndex;
  812. var colIndex = this.__getCellIndex(this.node);
  813. this.node.set("rowspan", 1);
  814. delete this.node.rowspan;
  815. delete this.json.properties.rowspan;
  816. this.node.set("colspan", 1);
  817. delete this.node.colspan;
  818. delete this.json.properties.colspan;
  819. if (this.form.currentSelectedModule) this.form.currentSelectedModule.unSelected();
  820. this.unSelectedMulti();
  821. this.selectedMulti();
  822. var startTds = this.__getTdsByIndex(table, rowIndex+1, rowspan-1, colIndex-1);
  823. for (var i=1; i<=rowspan; i++){
  824. if (i==1){
  825. for (var j=2; j<=colspan; j++){
  826. var newTd = new Element("td").inject(this.node, "after");
  827. this.form.getTemplateData("Table$Td", function(data){
  828. var moduleData = Object.clone(data);
  829. var tdContainer = new MWF.FCTable$Td(this.form);
  830. tdContainer.table = this.table;
  831. tdContainer.load(moduleData, newTd, this.parentContainer);
  832. this.parentContainer.containers.push(tdContainer);
  833. tdContainer.selectedMulti();
  834. }.bind(this));
  835. }
  836. }else{
  837. var tr = tr.getNext("tr");
  838. var startTd = startTds[i-2];
  839. for (var j=1; j<=colspan; j++){
  840. var newTd = new Element("td");
  841. if (startTd){
  842. newTd.inject(startTd, "after");
  843. }else{
  844. newTd.inject(tr, "top");
  845. }
  846. this.form.getTemplateData("Table$Td", function(data){
  847. var moduleData = Object.clone(data);
  848. var tdContainer = new MWF.FCTable$Td(this.form);
  849. tdContainer.table = this.table;
  850. tdContainer.load(moduleData, newTd, this.parentContainer);
  851. this.parentContainer.containers.push(tdContainer);
  852. tdContainer.selectedMulti();
  853. }.bind(this));
  854. }
  855. }
  856. }
  857. this.form._completeSelectMulti();
  858. }
  859. //_showInjectAction : function( module ){
  860. // if ( module.moveNode ){
  861. // module.moveNode.setStyle("display","none");
  862. // }
  863. //
  864. // this.draggingModule = module;
  865. // if( !this.node.getFirst() ){
  866. // this.inject( "top" );
  867. // return;
  868. // }
  869. //
  870. // if( !this.injectActionArea )this._createInjectAction();
  871. // this.injectActionArea.setStyle("display","");
  872. // this._setInjectActionAreaPosition();
  873. //}
  874. });