Table$Td.js 27 KB

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