Table$Td.js 27 KB

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