Table$Td.js 29 KB

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