var linkEl = createElement('a');
linkEl.href = '#';
linkEl.onclick = this.upRow;
linkEl.setAttribute('columnId', k);
var innerEls = table.tBodies[0].rows[j+1].cells[k].childNodes;
linkEl.innerText = "上移";
table.tBodies[0].rows[j+1].cells[k].appendChild(linkEl);
var p = createElement('span');
p.innerHTML = " ";
table.tBodies[0].rows[j+1].cells[k].appendChild(p);
var linkEl2 = createElement('a');
linkEl2.href = '#';
linkEl2.onclick = this.downRow;
linkEl2.setAttribute('columnId', k);
var innerEls2 = table.tBodies[0].rows[j+1].cells[k].childNodes;
linkEl2.innerText = "下移";
table.tBodies[0].rows[j+1].cells[k].appendChild(linkEl2);
}
}
}
// 隔行換顏色,依賴odd樣式
this.isOdd = true;
var rows = table.tBodies[0].rows;
// We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
for (var i=0;i<rows.length-1;i++) ...{
this.doStripe(rows[i+1]);
}
},
/**//**
* 隔行分色策略,依賴odd樣式
**/
doStripe : function(rowItem) ...{
if (!this.isOdd) ...{
css.addClassToElement(rowItem, 'odd');
} else ...{
css.removeClassFromElement(rowItem, 'odd');
}
this.isOdd = !this.isOdd;
},
/**//**
* 刪除目標列
**/
delRow : function(e) ...{
var that = crudbtn.that;
var linkEl = getEventTarget(e);
var td = linkEl.parentNode;
var tr = td.parentNode;
var thead = tr.parentNode;
var table = thead.parentNode;
if (!table.tBodies || table.tBodies[0].rows.length <= 1) ...{
return false;
}
this.isOdd = true;
var rows = table.tBodies[0].rows;
// 實現AJAX調用處理刪除
var pars = "pars=";
for(h=0;h<tr.cells.length;h++) ...{
if(!css.elementHasClass(tr.cells[h],'editbtn')&&!css.elementHasClass(tr.cells[h],'delbtn')
&&!css.elementHasClass(tr.cells[h],'updownbtn')) ...{
var colid = tr.cells[h].getAttribute('columnId');
if(tr.cells[h].firstChild.value!=null) ...{
pars += h +"^"+ tr.cells[h].firstChild.value +"|";
}
else ...{
pars += h +"^"+ tr.cells[h].innerText +"|";
}
}
}
pars += "&command=delrow&callback=afterUpdate&table="+table.id;
table.deleteRow(tr.rowIndex);
// 重新隔行換色
for (var i=1;i<rows.length;i++) ...{
if (!this.isOdd) ...{
css.addClassToElement(rows[i], 'odd');
} else ...{
css.removeClassFromElement(rows[i], 'odd');
}
this.isOdd = !this.isOdd;
}
new Ajax.Updater('result','Dispatcher.ajax?'+pars,...{evalScripts: true});
if(table.rows.length<=1) ...{
alert("該頁已無資料,系統將重載資料項目");
window.location = "?";
}
},
/**//**
* 修改按鈕
**/
editRow : function(e) ...{
var that = crudbtn.that;
var linkEl = getEventTarget(e);
var td = linkEl.parentNode;
var tr = td.parentNode;
var thead = tr.parentNode;
var table = thead.parentNode;
var column = linkEl.getAttribute('columnId') || td.cellIndex;
var cellcount = tr.cells.length;
// 如果沒點擊修改
if(tr.getAttribute('editing')!=1) ...{
for(var o=0;o<cellcount;o++) ...{
// 如果該列含有修改樣式、刪除樣式或其他類似樣式,則忽略該列
if(!css.elementHasClass(tr.cells[o],'editbtn')&&!css.elementHasClass(tr.cells[o],'delbtn')
&&!css.elementHasClass(tr.cells[o],'updownbtn') &&!css.elementHasClass(tr.cells[o],'noedit')) ...{
var inputEl = createElement('input');
inputEl.type = "text";
// 文字框大小
// inputEl.size = tr.cells[o].innerText.length*2; inputEl.size = tr.cells[o].innerText.replace(/[^\x00-\xff]/gi,'xx').length;
tr.cells[o].setAttribute('columnId', o);
inputEl.setAttribute('oldValue', tr.cells[o].innerHTML);
var inputEls = tr.cells[o].innerText;
inputEl.value = inputEls;
tr.cells[o].firstChild.removeNode(true);
tr.cells[o].appendChild(inputEl);
tr.setAttribute('editing',1);
linkEl.setAttribute('oldValue',linkEl.innerText);
}
}
linkEl.innerText = "確定";
var p = createElement('span');
p.innerHTML = " ";
td.appendChild(p);
var linkEl2 = createElement('a');
linkEl2.href="#";
linkEl2.onclick = that.cancelRow;
linkEl2.innerText = "取消";
td.appendChild(linkEl2);
}