123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065 |
- MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
- MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Container", null, false);
- MWF.xApplication.process.FormDesigner.Module.Table$Td = MWF.FCTable$Td = new Class({
- Extends: MWF.FC$Container,
- Implements: [Options, Events],
- options: {
- "style": "default",
- "propertyPath": "../x_component_process_FormDesigner/Module/Table$Td/table$td.html",
-
- "actions": [
- {
- "name": "insertRow",
- "icon": "insertRow1.png",
- "event": "click",
- "action": "insertRow",
- "title": MWF.APPFD.LP.formAction.insertRow
- },
- {
- "name": "insertCol",
- "icon": "insertCol1.png",
- "event": "click",
- "action": "insertCol",
- "title": MWF.APPFD.LP.formAction.insertCol
- },
- {
- "name": "deleteRow",
- "icon": "deleteRow1.png",
- "event": "click",
- "action": "deleteRow",
- "title": MWF.APPFD.LP.formAction.deleteRow
- },
- {
- "name": "deleteCol",
- "icon": "deleteCol1.png",
- "event": "click",
- "action": "deleteCol",
- "title": MWF.APPFD.LP.formAction.deleteCol
- },
- {
- "name": "selectParent",
- "icon": "selectParent.png",
- "event": "click",
- "action": "selectParent",
- "title": MWF.APPFD.LP.formAction["selectParent"]
- },
- {
- "name": "splitCell",
- "icon": "splitCell.png",
- "event": "click",
- "action": "splitCell",
- "title": MWF.APPFD.LP.formAction.splitCell
- }
- ],
- "injectActions" : [
- {
- "name" : "top",
- "styles" : "injectActionTop",
- "event" : "click",
- "action" : "injectTop",
- "title": MWF.APPFD.LP.formAction["insertTop"]
- },
- {
- "name" : "bottom",
- "styles" : "injectActionBottom",
- "event" : "click",
- "action" : "injectBottom",
- "title": MWF.APPFD.LP.formAction["insertBottom"]
- }
- ]
- },
-
- initialize: function(form, options){
- this.setOptions(options);
-
- this.path = "../x_component_process_FormDesigner/Module/Table$Td/";
- this.cssPath = "../x_component_process_FormDesigner/Module/Table$Td/"+this.options.style+"/css.wcss";
- this._loadCss();
- this.moduleType = "container";
- this.moduleName = "table$Td";
-
- this.Node = null;
- this.form = form;
- },
- setAllStyles: function(){
- Object.each(this.json.styles, function(value, key){
- var reg = /^border\w*/ig;
- if (!key.test(reg)){
- if (key) this.node.setStyle(key, value);
- }
- }.bind(this));
- this.setPropertiesOrStyles("properties");
- this.reloadMaplist();
- },
- over: function(){
- if (this.form.selectedModules.indexOf(this)==-1){
- if (!this.form.moveModule) if (this.form.currentSelectedModule!=this) this.node.setStyles({
- "border-width": "1px",
- "border-color": "#0072ff"
- });
- }
- },
- unOver: function(){
- if (this.form.selectedModules.indexOf(this)==-1){
- if (!this.form.moveModule) if (this.form.currentSelectedModule!=this) this.node.setStyles({
- "border-width": "1px",
- "border-color": "#999"
- });
- }
- },
- unSelected: function(){
- this.node.setStyles({
- "border-width": "1px",
- "border-color": "#999"
- });
- this._hideActions();
- this.form.currentSelectedModule = null;
-
- this.hideProperty();
- },
-
- _showActions: function(){
- if (this.actionArea){
- this._setActionAreaPosition();
- this.actionArea.setStyle("display", "block");
- var colspan = this.node.get("colspan").toInt() || 1;
- var rowspan = this.node.get("rowspan").toInt() || 1;
- if (colspan<=1 && rowspan<=1){
- this.actionArea.getLast("div").setStyle("display", "none");
- }else{
- this.actionArea.getLast("div").setStyle("display", "block");
- }
- }
- },
-
- unSelectedMulti: function(){
- if (this.form.selectedModules.indexOf(this)!=-1){
- this.form.selectedModules.erase(this);
- this.node.setStyle("border-color", "#999");
- }
- },
-
- load : function(json, node, parent){
- this.json = json;
- this.node= node;
- this.node.store("module", this);
- this.node.setStyles(this.css.moduleNode);
-
- if (!this.json.id){
- var id = this._getNewId(parent.json.id);
- this.json.id = id;
- }
-
-
- node.set({
- "MWFType": "table$Td",
- "id": this.json.id
- });
-
- if (!this.form.json.moduleList[this.json.id]){
- this.form.json.moduleList[this.json.id] = this.json;
- }
- this._initModule();
- this._loadTreeNode(parent);
- this.form.parseModules(this, this.node);
-
- this.parentContainer = this.treeNode.parentNode.module;
- this._setEditStyle_custom("id");
- this.json.moduleName = this.moduleName;
- },
-
- // _setNodeEvent: function(){
- // if (!this.isSetEvents){
- // this.node.addEvent("click", function(e){
- // this.selected();
- // e.stop();
- // }.bind(this));
- //
- // this.node.addEvent("mouseover", function(e){
- // this.over();
- // e.stop();
- // }.bind(this));
- // this.node.addEvent("mouseout", function(e){
- // this.unOver();
- // e.stop();
- // }.bind(this));
- //
- // this._setOtherNodeEvent();cellType
- // },
-
- _createMoveNode: function(){
- return false;
- },
- _setEditStyle_custom: function(name){
- if (name=="cellType"){
- this.setCustomStyles();
- }
-
- },
- _preprocessingSetNodeStyles: function(styles){
- Object.each(styles, function(value, key){
- if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
- this.node.setStyle(key, value);
- }
- }.bind(this));
- },
- _preprocessingModuleData: function(){
- this.node.clearStyles();
- var addStyles = {};
- if (this.json.cellType==="title") addStyles = this.table.json.titleTdStyles;
- if (this.json.cellType==="content") addStyles = this.table.json.contentTdStyles;
- if (this.json.cellType==="layout") addStyles = this.table.json.layoutTdStyles;
- this._preprocessingSetNodeStyles(addStyles);
- if (this.json.styles){
- this.json.recoveryStyles = Object.clone(this.json.styles);
- if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
- if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
- this.node.setStyle(key, value);
- delete this.json.styles[key];
- }
- }.bind(this));
- }
- // if (this.table){
- // if (!(this.json.styles && this.json.styles.border) && this.table.json.styles && this.table.json.styles.border){
- // this.node.setStyle("border", this.table.json.styles.border);
- // }
- // }
- this.json.preprocessing = "y";
- },
- _recoveryModuleData: function(){
- if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
- this.json.recoveryStyles = null;
- // if (this.table){
- // if (!(this.json.styles && this.json.styles.border) && this.table.json.styles && this.table.json.styles.border){
- // this.node.setStyle("border", "");
- // }
- // }
- },
- setCustomStyles: function(){
- this._recoveryModuleData();
- var border = this.node.getStyle("border");
- this.node.clearStyles();
- this.node.setStyles(this.css.moduleNode);
- var addStyles = {};
- if (this.json.cellType=="title"){
- addStyles = this.table.json.titleTdStyles;
- }
- if (this.json.cellType=="content"){
- addStyles = this.table.json.contentTdStyles;
- }
- if (this.json.cellType=="layout"){
- addStyles = this.table.json.layoutTdStyles;
- }
- if (this.initialStyles) this.node.setStyles(this.initialStyles);
- this.node.setStyle("border", border);
- Object.each(addStyles, function(value, key){
- if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
- var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
- var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
- if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
- value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
- }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
- value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
- }
- if (value.indexOf("/x_portal_assemble_surface")!==-1){
- value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
- }else if (value.indexOf("x_portal_assemble_surface")!==-1){
- value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
- }
- value = o2.filterUrl(value);
- }
- var reg = /^border\w*/ig;
- if (!key.test(reg)){
- if (key){
- if (key.toString().toLowerCase()==="display"){
- if (value.toString().toLowerCase()==="none"){
- this.node.setStyle("opacity", 0.3);
- }else{
- this.node.setStyle("opacity", 1);
- this.node.setStyle(key, value);
- }
- }else{
- this.node.setStyle(key, value);
- }
- }
- }
- }.bind(this));
- Object.each(this.json.styles, function(value, key){
- if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
- var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
- var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
- if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
- value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
- }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
- value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
- }
- if (value.indexOf("/x_portal_assemble_surface")!==-1){
- value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
- }else if (value.indexOf("x_portal_assemble_surface")!==-1){
- value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
- }
- value = o2.filterUrl(value);
- }
- var reg = /^border\w*/ig;
- if (!key.test(reg)){
- if (key){
- if (key.toString().toLowerCase()==="display"){
- if (value.toString().toLowerCase()==="none"){
- this.node.setStyle("opacity", 0.3);
- }else{
- this.node.setStyle("opacity", 1);
- this.node.setStyle(key, value);
- }
- }else{
- this.node.setStyle(key, value);
- }
- }
- }
- }.bind(this));
- },
- _dragInLikeElement: function(module){
- return false;
- },
-
- insertRow: function(){
- var module = this;
- var url = this.path+"insertRow.html";
- MWF.require("MWF.widget.Dialog", function(){
- var size = $(document.body).getSize();
- var x = size.x/2-150;
- var y = size.y/2-90;
- var dlg = new MWF.DL({
- "title": "Insert Row",
- "style": "property",
- "top": y,
- "left": x-40,
- "fromTop":size.y/2-45,
- "fromLeft": size.x/2,
- "width": 300,
- "height": 180,
- "url": url,
- "lp": MWF.xApplication.process.FormDesigner.LP.propertyTemplate,
- "buttonList": [
- {
- "text": MWF.APPFD.LP.button.ok,
- "action": function(){
- module._insertRow();
- this.close();
- }
- },
- {
- "text": MWF.APPFD.LP.button.cancel,
- "action": function(){
- this.close();
- }
- }
- ]
- });
-
- dlg.show();
- }.bind(this));
- },
- _insertRow: function(){
- var rows = $("MWFInsertRowNumber").get("value");
- var positionRadios = document.getElementsByName("MWFInsertRowPosition");
- var position = "before";
- for (var i=0; i<positionRadios.length; i++){
- if (positionRadios[i].checked){
- position = positionRadios[i].value;
- break;
- }
- }
- var tr = this.node.getParent("tr");
- var table = tr.getParent("table");
-
-
- var cellNumber = tr.cells.length;
- var rowIndex = tr.rowIndex;
-
- var rowspanBeforeTds = table.getElements("td:rowspanBefore("+rowIndex+")");
- var colCurrentTds = tr.getElements("td:colspan");
- colCurrentTds.each(function(td){
- var colspan = td.get("colspan").toInt() || 1;
- cellNumber = cellNumber+colspan-1;
- });
- rowspanBeforeTds.each(function(td){
- this.__rowspanPlus(td, rows);
- }.bind(this));
-
- if (position=="after"){
- var rowspanCurrentTds = tr.getElements("td:rowspan");
- rowspanCurrentTds.each(function(td){
- this.__rowspanPlus(td, rows);
- var colspan = td.get("colspan").toInt() || 1;
- cellNumber = cellNumber-colspan;
- }.bind(this));
- }
- var moduleList = [];
- for (var n=1; n<=rows; n++){
- var newTr = new Element("tr").inject(tr, position);
- for (var m=1; m<=cellNumber; m++){
- var cell = new Element("td").inject(newTr);
-
- this.form.getTemplateData("Table$Td", function(data){
- var moduleData = Object.clone(data);
- var tdContainer = new MWF.FCTable$Td(this.form);
- moduleList.push(tdContainer);
- tdContainer.table = this.table;
- tdContainer.load(moduleData, cell, this.parentContainer);
- this.parentContainer.containers.push(tdContainer);
-
- }.bind(this));
-
- }
- }
- this.unSelected();
- this.selected();
- // moduleList.sort(function (a, b) {
- // if( a.node.cellIndex === b.node.cellIndex ){
- // return a.node.getParent().rowIndex - b.node.getParent().rowIndex;
- // }else{
- // return a.node.cellIndex - b.node.cellIndex
- // }
- // });
- this.addHistoryLog( "insertRow", moduleList );
- },
-
- insertCol: function(){
- var module = this;
- var url = this.path+"insertCol.html";
- MWF.require("MWF.widget.Dialog", function(){
- var size = $(document.body).getSize();
- var x = size.x/2-150;
- var y = size.y/2-90;
- var dlg = new MWF.DL({
- "title": "Insert Col",
- "style": "property",
- "top": y,
- "left": x-40,
- "fromTop":size.y/2-45,
- "fromLeft": size.x/2,
- "width": 300,
- "height": 180,
- "url": url,
- "lp": MWF.xApplication.process.FormDesigner.LP.propertyTemplate,
- "buttonList": [
- {
- "text": MWF.APPFD.LP.button.ok,
- "action": function(){
- module._insertCol();
- this.close();
- }
- },
- {
- "text": MWF.APPFD.LP.button.cancel,
- "action": function(){
- this.close();
- }
- }
- ]
- });
-
- dlg.show();
- }.bind(this));
- },
- _insertCol: function(){
- var cols = $("MWFInsertColNumber").get("value");
- var positionRadios = document.getElementsByName("MWFInsertColPosition");
- var position = "before";
- for (var i=0; i<positionRadios.length; i++){
- if (positionRadios[i].checked){
- position = positionRadios[i].value;
- break;
- }
- }
-
- var tr = this.node.getParent("tr");
- var table = tr.getParent("table");
- var colIndex = this.__getCellIndex(this.node);
- var moduleList = [];
- for (var m=1; m<=cols; m++){
- var insertTdObjs = this.__getInsertTableColTds(table, colIndex);
- insertTdObjs.each(function(obj){
- obj.td.inject(obj.toTd, position);
-
- this.form.getTemplateData("Table$Td", function(data){
- var moduleData = Object.clone(data);
- var tdContainer = new MWF.FCTable$Td(this.form);
- moduleList.push(tdContainer);
- tdContainer.table = this.table;
- tdContainer.load(moduleData, obj.td, this.parentContainer);
- this.parentContainer.containers.push(tdContainer);
- }.bind(this));
- }.bind(this));
- }
-
- this.unSelected();
- this.selected();
- this.addHistoryLog( "insertCol", moduleList );
-
- },
-
- deleteRow: function(e){
- var module = this;
- this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteRowTitle, MWF.APPFD.LP.notice.deleteRow, 300, 120, function(){
- var tr = module.node.getParent("tr");
- var table = tr.getParent("table");
- if (table.rows.length<=1){
- // this.parentContainer.destroy();
- module.parentContainer.addHistoryLog("delete");
- }else{
- var moduleList = [];
- var tds =tr.getElements("td");
- tds.each(function(td){
- var m = td.retrieve("module");
- if(m)moduleList.push(m);
- });
- module.addHistoryLog("deleteRow", moduleList);
- }
- module._deleteRow();
- this.close();
- }, function(){
- this.close();
- }, null);
- },
-
- __rowspanPlus: function(td,n){
- var rowspan = td.get("rowspan").toInt() || 1;
- rowspan = rowspan+n.toInt();
- var module = td.retrieve("module");
- if (rowspan>1){
- td.set("rowspan", rowspan);
- if (module) module.json.properties.rowspan = rowspan;
- }else{
- td.set("rowspan", 1);
- delete td.rowspan;
- if (module) delete module.json.properties.rowspan;
- }
-
- },
- __rowspanMinus: function(td){
- var rowspan = td.get("rowspan").toInt() || 1;
- rowspan = rowspan-1;
- var module = td.retrieve("module");
- if (rowspan>1){
- td.set("rowspan", rowspan);
- if (module) module.json.properties.rowspan = rowspan;
- }else{
- td.set("rowspan", 1);
- delete td.rowspan;
- if (module) delete module.json.properties.rowspan;
- }
- },
- __colspanPlus: function(td, n){
- var colspan = td.get("colspan").toInt() || 1;
- colspan = colspan+n.toInt();
- var module = td.retrieve("module");
- if (colspan>1){
- td.set("colspan", colspan);
- if (module) module.json.properties.colspan = colspan;
- }else{
- td.set("colspan", 1);
- delete td.colspan;
- if (module) delete module.json.properties.colspan;
- }
- },
- __colspanMinus: function(td){
- var colspan = td.get("colspan").toInt() || 1;
- colspan = colspan-1;
- var module = td.retrieve("module");
- if (colspan>1){
- td.set("colspan", colspan);
- if (module) module.json.properties.colspan = colspan;
- }else{
- td.set("colspan", 1);
- delete td.colspan;
- if (module) delete module.json.properties.colspan;
- }
- },
-
- __getNextTd: function(nextTr, cellIndex){
- var nextTd = null;
- while (cellIndex>0){
- if (!nextTd){
- nextTd = nextTr.getFirst("td");
- }else{
- nextTd = nextTd.getNext("td");
- }
- cellIndex--;
- var colspan = nextTd.get("colspan").toInt() || 1;
- cellIndex = cellIndex-colspan-1;
- }
- return nextTd;
- },
- __getCellIndex: function(td){
- var tr = td.getParent("tr");
- var table = tr.getParent("table");
- // var rowindex = tr.rowIndex;
-
- var idx = -1;
- var trs = table.rows;
- var rowspanTds = {};
-
- var isBreak = false;
- for (var i=0; i<trs.length; i++){
- var ervryTd = null;
- var j=0;
- while (true){
- var rowspan = rowspanTds["rowspan_"+j];
- if (rowspan){
- rowspan.rows = rowspan.rows-1;
- if (!rowspan.rows){
- delete rowspanTds["rowspan_"+j];
- }
- j++;
- }else{
- if (!ervryTd){
- ervryTd = trs[i].getFirst("td");
- }else{
- ervryTd = ervryTd.getNext("td");
- }
- if (!ervryTd) break;
-
- if (ervryTd==td){
- idx = j;
- isBreak = true;
- break;
- }else{
- var rowspan = ervryTd.get("rowspan").toInt() || 1;
- var colspan = ervryTd.get("colspan").toInt() || 1;
- if (rowspan>1){
- var rows = rowspan-1;
- for (var x=0; x<colspan; x++){
- var n = j+x;
- rowspanTds["rowspan_"+n] = {"rows": rows};
- }
- }
- j = j + colspan-1;
- }
- j++;
- }
- }
- if (isBreak) break;
- }
-
- return idx;
- },
- __getInsertTableColTds: function(table, idx){
- var insertTds = [];
- var trs = table.rows;
- var rowspanTds = {};
-
- for (var i=0; i<trs.length; i++){
- var ervryTd = null;
- var j=0;
- while (true){
- var rowspan = rowspanTds["rowspan_"+j];
- if (rowspan){
- rowspan.rows = rowspan.rows-1;
- if (!rowspan.rows){
- delete rowspanTds["rowspan_"+j];
- }
- j++;
- }else{
- if (!ervryTd){
- ervryTd = trs[i].getFirst("td");
- }else{
- ervryTd = ervryTd.getNext("td");
- }
- if (!ervryTd) break;
-
- var rowspan = ervryTd.get("rowspan").toInt() || 1;
- var colspan = ervryTd.get("colspan").toInt() || 1;
-
- if (rowspan>1){
- var rows = rowspan-1;
- for (var x=0; x<colspan; x++){
- var n = j+x;
- rowspanTds["rowspan_"+n] = {"rows": rows};
- }
- }
-
- if (colspan>1){
- if (j + colspan-1>=idx && j<=idx){
- // ervryTd.setStyle("background", "#FF9999");
- this.__colspanPlus(ervryTd, 1);
- break;
- }
-
- }else{
- if (j==idx){
- var newTd = new Element("td");
- insertTds.push({"td": newTd, "toTd": ervryTd});
- break;
- }
- }
-
- j = j + colspan-1;
- j++;
- }
- }
- }
-
- return insertTds;
-
- },
- __getDeleteTableColTds: function(table, idx){
- var deleteTds = [];
- var trs = table.rows;
- var rowspanTds = {};
-
- for (var i=0; i<trs.length; i++){
- var ervryTd = null;
- var j=0;
- while (true){
- var rowspan = rowspanTds["rowspan_"+j];
- if (rowspan){
- rowspan.rows = rowspan.rows-1;
- if (!rowspan.rows){
- delete rowspanTds["rowspan_"+j];
- }
- j++;
- }else{
- if (!ervryTd){
- ervryTd = trs[i].getFirst("td");
- }else{
- ervryTd = ervryTd.getNext("td");
- }
- if (!ervryTd) break;
-
- var rowspan = ervryTd.get("rowspan").toInt() || 1;
- var colspan = ervryTd.get("colspan").toInt() || 1;
-
- if (rowspan>1){
- var rows = rowspan-1;
- for (var x=0; x<colspan; x++){
- var n = j+x;
- rowspanTds["rowspan_"+n] = {"rows": rows};
- }
- }
-
- if (colspan>1){
- if (j + colspan-1>=idx && j<=idx){
- // ervryTd.setStyle("background", "#FF9999");
- this.__colspanMinus(ervryTd);
- break;
- }
- }else{
- if (j==idx){
- deleteTds.push(ervryTd);
- break;
- }
- }
-
- j = j + colspan-1;
- j++;
- }
- }
- }
-
- return deleteTds;
- },
-
- _deleteRow:function(){
- var _form = this.form;
- var tr = this.node.getParent("tr");
- var table = tr.getParent("table");
- var rowIndex = tr.rowIndex;
- // var currentRowspan = this.node.get("rowspan").toInt() || 1;
- var rowspanBeforeTds = table.getElements("td:rowspanBefore("+rowIndex+")");
- var rowspanCurrentTds = tr.getElements("td:rowspan");
-
- rowspanBeforeTds.each(function(td){
- this.__rowspanMinus(td);
- }.bind(this));
-
- rowspanCurrentTds.each(function(td){
- this.__rowspanMinus(td);
- var nextTr = table.rows[rowIndex+1];
- if (nextTr){
- var cellIndex = td.cellIndex;
- var nextTd = null;
- if (cellIndex>0){
- nextTd = this.__getNextTd(nextTr, cellIndex);
- }else{
- nextTd = this.__getNextTd(nextTr, 2);
- }
- if (nextTd) td.inject(nextTd, "after");
- }
- }.bind(this));
- if (table.rows.length<=1){
- this.parentContainer.destroy();
- }else{
- tds = tr.getElements("td");
- tds.each(function(td){
- var module = td.retrieve("module");
- if (module){
- module.parentContainer.containers.erase(module);
- module.destroy();
- }
- });
- tr.destroy();
- }
- _form.currentSelectedModule = null;
- _form.selected();
- _form = null;
- },
- deleteCol: function(e){
- var module = this;
- this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteColTitle, MWF.APPFD.LP.notice.deleteCol, 300, 120, function(){
- var tr = module.node.getParent("tr");
- var table = tr.getParent("table");
- var colIndex = module.__getCellIndex(module.node);
- var currentRowspan = module.node.get("colspan").toInt() || 1;
- if (tr.cells.length<=1 && currentRowspan<=1){
- //this.parentContainer.destroy();
- module.parentContainer.addHistoryLog("delete");
- }else{
- var moduleList = [];
- var deleteTds = module.__getDeleteTableColTds(table, colIndex);
- deleteTds.each(function(td){
- var m = td.retrieve("module");
- if(m)moduleList.push(m);
- });
- module.addHistoryLog("deleteCol", moduleList);
- }
- module._deleteCol();
- this.close();
- }, function(){
- this.close();
- }, null);
- },
- _deleteCol: function(){
- var _form = this.form;
- var tr = this.node.getParent("tr");
- var table = tr.getParent("table");
- var colIndex = this.__getCellIndex(this.node);
- var currentRowspan = this.node.get("colspan").toInt() || 1;
-
- if (tr.cells.length<=1 && currentRowspan<=1){
- this.parentContainer.destroy();
- }else{
- var deleteTds = this.__getDeleteTableColTds(table, colIndex);
- deleteTds.each(function(dtd){
- // dtd.setStyle("background", "#999999");
- var module = dtd.retrieve("module");
- if (module){
- module.parentContainer.containers.erase(module);
- module.destroy();
- }
- });
- }
- _form.currentSelectedModule = null;
- _form.selected();
- _form = null;
- },
- // __getTdByIndex11: function(tr, idx){
- // //??????????????????????????????????????
- // //??????????????????????????????????????
- // //??????????????????????????????????????
- // //??????????????????????????????????????
- // //??????????????????????????????????????
- // var findTd = false;
- // var td = null;
- // var n=-1;
- // while (n!=idx){
- // if (!td){
- // td = tr.getFirst("td");
- // }else{
- // td = tr.getNext("td");
- // }
- // var colspan = td.get("colspan").toInt() || 1;
- // n = n+colspan;
- // if (n>=idx && n-colspan<=idx) n=idx;
- // }
- // return td;
- // },
-
- __getTdsByIndex: function(table, beginRow, rows, idx){
- var indexTds = [];
- var trs = table.rows;
- var rowspanTds = {};
-
- for (var i=0; i<trs.length; i++){
- var ervryTd = null;
- var j=0;
- var findTd=false;
- while (true){
- var rowspan = rowspanTds["rowspan_"+j];
- if (rowspan){
- rowspan.rows = rowspan.rows-1;
- if (!rowspan.rows){
- delete rowspanTds["rowspan_"+j];
- }
- j++;
- }else{
- if (!ervryTd){
- ervryTd = trs[i].getFirst("td");
- }else{
- ervryTd = ervryTd.getNext("td");
- }
- if (!ervryTd){
- if (i>=beginRow && i<=beginRow+rows) if (!findTd) indexTds.push(null);
- break;
- }
-
- var rowspan = ervryTd.get("rowspan").toInt() || 1;
- var colspan = ervryTd.get("colspan").toInt() || 1;
-
- var rows;
- if (rowspan>1){
- rows = rowspan-1;
- for (var x=0; x<colspan; x++){
- var n = j+x;
- rowspanTds["rowspan_"+n] = {"rows": rows};
- }
- }
- if (j + colspan-1>=idx && j<=idx){
- if (i>=beginRow && i<=beginRow+rows){
- indexTds.push(ervryTd);
- findTd = true;
- }
- break;
- }
-
- j = j + colspan-1;
- j++;
- }
- }
- }
-
- return indexTds;
- },
-
- splitCell: function(){
- var fromLog = this.createHistoryLog();
- var colspan = this.node.get("colspan").toInt() || 1;
- var rowspan = this.node.get("rowspan").toInt() || 1;
-
- var tr = this.node.getParent("tr");
- var table = tr.getParent("table");
- var rowIndex = tr.rowIndex;
-
- var colIndex = this.__getCellIndex(this.node);
- this.node.set("rowspan", 1);
- delete this.node.rowspan;
- delete this.json.properties.rowspan;
- this.node.set("colspan", 1);
- delete this.node.colspan;
- delete this.json.properties.colspan;
-
- if (this.form.currentSelectedModule) this.form.currentSelectedModule.unSelected();
- this.unSelectedMulti();
-
- this.selectedMulti();
-
- var startTds = this.__getTdsByIndex(table, rowIndex+1, rowspan-1, colIndex-1);
- var moduleList = [];
- for (var i=1; i<=rowspan; i++){
- if (i==1){
- for (var j=2; j<=colspan; j++){
- var newTd = new Element("td").inject(this.node, "after");
-
- this.form.getTemplateData("Table$Td", function(data){
- var moduleData = Object.clone(data);
- var tdContainer = new MWF.FCTable$Td(this.form);
- moduleList.push(tdContainer);
- tdContainer.table = this.table;
- tdContainer.load(moduleData, newTd, this.parentContainer);
- this.parentContainer.containers.push(tdContainer);
- tdContainer.selectedMulti();
- }.bind(this));
- }
- }else{
- var tr = tr.getNext("tr");
- var startTd = startTds[i-2];
-
- for (var j=1; j<=colspan; j++){
- var newTd = new Element("td");
- if (startTd){
- newTd.inject(startTd, "after");
- }else{
- newTd.inject(tr, "top");
- }
-
- this.form.getTemplateData("Table$Td", function(data){
- var moduleData = Object.clone(data);
- var tdContainer = new MWF.FCTable$Td(this.form);
- moduleList.push(tdContainer);
- tdContainer.table = this.table;
- tdContainer.load(moduleData, newTd, this.parentContainer);
- this.parentContainer.containers.push(tdContainer);
- tdContainer.selectedMulti();
- }.bind(this));
- }
- }
- }
- this.form._completeSelectMulti();
- moduleList.push(this);
- // moduleList.sort(function (a, b) {
- // if( a.node.cellIndex === b.node.cellIndex ){
- // return a.node.getParent().rowIndex - b.node.getParent().rowIndex;
- // }else{
- // return a.node.cellIndex - b.node.cellIndex
- // }
- // });
- this.addHistoryLog("splitCell", moduleList, fromLog);
- }
- //_showInjectAction : function( module ){
- // if ( module.moveNode ){
- // module.moveNode.setStyle("display","none");
- // }
- //
- // this.draggingModule = module;
- // if( !this.node.getFirst() ){
- // this.inject( "top" );
- // return;
- // }
- //
- // if( !this.injectActionArea )this._createInjectAction();
- // this.injectActionArea.setStyle("display","");
- // this._setInjectActionAreaPosition();
- //}
-
- });
|