448 lines
12 KiB
JavaScript
448 lines
12 KiB
JavaScript
|
|
|
||
|
|
function NumberToUserFormatNumber(number,add) {
|
||
|
|
|
||
|
|
if(!number) number = 0;
|
||
|
|
|
||
|
|
number = parseFloat(number);
|
||
|
|
|
||
|
|
var tmp = number.toFixed(OPT['dec_len']);
|
||
|
|
|
||
|
|
var s1 = tmp.substring(0,tmp.length-1-OPT['dec_len']);
|
||
|
|
|
||
|
|
var s2 = tmp.substring(tmp.length-OPT['dec_len'],tmp.length);
|
||
|
|
|
||
|
|
var tmp = '';
|
||
|
|
|
||
|
|
for(var i=s1.length;i>0;i-=3) {
|
||
|
|
|
||
|
|
tmp = ((i<=3)?"":OPT['sep_1000'])+s1.substring(i-3,i)+tmp;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
s1 = tmp;
|
||
|
|
|
||
|
|
return (s1+OPT['dec_sep']+s2).toString()+((add)?add:'');
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function UserFormatNumberToNumber(ufn,add) {
|
||
|
|
|
||
|
|
if(add) {
|
||
|
|
|
||
|
|
var match = /add/g;
|
||
|
|
|
||
|
|
ufn = ufn.replace(match,'');
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
var match = /Err/g;
|
||
|
|
|
||
|
|
ufn = ufn.replace(match,'');
|
||
|
|
|
||
|
|
if(!ufn) return parseFloat(0);
|
||
|
|
|
||
|
|
var pos = ufn.indexOf(OPT['dec_sep']);
|
||
|
|
|
||
|
|
var s1='', s2='';
|
||
|
|
|
||
|
|
if(pos==-1) { s1 = ufn; s2 = ''; }
|
||
|
|
|
||
|
|
else { s1 = ufn.substring(0,pos); s2 = ufn.substring(pos+1,ufn.length); }
|
||
|
|
|
||
|
|
|
||
|
|
/*
|
||
|
|
if(OPT['sep_1000'] != "")
|
||
|
|
|
||
|
|
for(var i=s1.length-4;i>=0;i-=4)
|
||
|
|
|
||
|
|
if(s1.charAt(i) != OPT['sep_1000']) { return -1; }
|
||
|
|
|
||
|
|
if(s1.charAt(0) == OPT['sep_1000']) return -1;
|
||
|
|
*/
|
||
|
|
|
||
|
|
|
||
|
|
var pos = -1;
|
||
|
|
|
||
|
|
while((pos = s1.indexOf(OPT['sep_1000'])) != -1)
|
||
|
|
|
||
|
|
s1 = s1.substring(0,pos)+s1.substring(pos+1,s1.length);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//alert(s1);
|
||
|
|
|
||
|
|
return parseFloat(s1+"."+s2);
|
||
|
|
|
||
|
|
}
|
||
|
|
function keyPressedNumber(e) {
|
||
|
|
var keynum;
|
||
|
|
if(window.event) //IE
|
||
|
|
keynum = e.keyCode;
|
||
|
|
else
|
||
|
|
keynum = e.which;
|
||
|
|
return keynum;
|
||
|
|
}
|
||
|
|
|
||
|
|
function isEnterOrTabPressed(e) {
|
||
|
|
var keynum = keyPressedNumber(e);
|
||
|
|
if(keynum == 9 || keynum == 13) return true; else return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
function setSelectionRange(obj) {
|
||
|
|
if(obj && typeof(obj) == "object" && (obj.type == "text" || obj.type == "textarea")) {
|
||
|
|
if(obj.createTextRange) {
|
||
|
|
var range = obj.createTextRange();
|
||
|
|
range.moveStart("character", 0);
|
||
|
|
range.moveEnd("character", obj.value.lengh-1);
|
||
|
|
range.select();
|
||
|
|
} else {
|
||
|
|
if(obj.setSelectionRange) {
|
||
|
|
obj.setSelectionRange(0,obj.value.length);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
obj.focus();
|
||
|
|
}
|
||
|
|
if(obj && typeof(obj) == "object" && obj.options) { obj.focus(); }
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
function paramsMT(name) {
|
||
|
|
|
||
|
|
this.myTableName = name;
|
||
|
|
this.table = document.getElementById(this.myTableName);
|
||
|
|
|
||
|
|
this.thead = this.table.tHead;
|
||
|
|
this.tbody = this.table.tBodies.item(0);
|
||
|
|
|
||
|
|
this.cellSelectedClass = 'selectedCell';
|
||
|
|
this.rowSelectedClass = 'selectedRow';
|
||
|
|
|
||
|
|
this.selectedRow;
|
||
|
|
this.selectedCell;
|
||
|
|
|
||
|
|
this.rowCount = function() {
|
||
|
|
return this.tbody.rows.length;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.colCount = function() {
|
||
|
|
return this.thead.rows.item(0).cells.length;
|
||
|
|
};
|
||
|
|
|
||
|
|
this.colWidth = function(i) {
|
||
|
|
return this.thead.rows.item(0).cells.item(i).width;
|
||
|
|
};
|
||
|
|
|
||
|
|
this.moveUpRow = function() {
|
||
|
|
if(this.selectedRow) this.selectedRow.moveUp();
|
||
|
|
};
|
||
|
|
|
||
|
|
this.moveDownRow = function() {
|
||
|
|
if(this.selectedRow) this.selectedRow.moveDown();
|
||
|
|
};
|
||
|
|
|
||
|
|
this.insertRow = function(row, newRow) {
|
||
|
|
if(!row)
|
||
|
|
if(this.rowCount())
|
||
|
|
if(typeof(row) == "number")
|
||
|
|
row = this.tbody.rows.item(row);
|
||
|
|
else
|
||
|
|
row = this.tbody.rows.item(this.tbody.rows.length-1);
|
||
|
|
|
||
|
|
var row_tmp;
|
||
|
|
if((newRow) && (row)) row_tmp = newRow; else { row_tmp = this.createRow(); this.fillWithDefaultData(row_tmp); }
|
||
|
|
|
||
|
|
if(this.rowCount() > 0 && row.nextSibling)
|
||
|
|
this.tbody.insertBefore(row_tmp, row.nextSibling);
|
||
|
|
else
|
||
|
|
this.tbody.appendChild(row_tmp);
|
||
|
|
|
||
|
|
return row_tmp;
|
||
|
|
};
|
||
|
|
|
||
|
|
this.refreshRowIndex = function() {
|
||
|
|
for(var i=0; i<this.rowCount(); i++) {
|
||
|
|
this.tbody.rows.item(i).index = i;
|
||
|
|
if(this.onRefreshRowIndex) this.onRefreshRowIndex(this.tbody.rows.item(i));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.onRefreshRowIndex;
|
||
|
|
|
||
|
|
this.addRow = function(i,data) {
|
||
|
|
var row = this.createRow();
|
||
|
|
if(this.selectedRow) this.selectedRow.deselect();
|
||
|
|
if(this.selectedCell) this.selectedCell.deselect();
|
||
|
|
row.myTable = this;
|
||
|
|
if(i || i===0)
|
||
|
|
this.tbody.insertBefore(row,this.tbody.rows.item(i));
|
||
|
|
else
|
||
|
|
this.tbody.appendChild(row);
|
||
|
|
this.refreshRowIndex();
|
||
|
|
this.setRowData(row, data);
|
||
|
|
for(var i=0; i<this.colCount(); i++) row.cells.item(i).afterCreate();
|
||
|
|
return row;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.createRow = function(row) {
|
||
|
|
var row = document.createElement('tr');
|
||
|
|
row.myTable = this;
|
||
|
|
row.isnew = false;
|
||
|
|
row.onclick = function() { this.select(); }
|
||
|
|
row.select = function() {
|
||
|
|
if(!this.myTable.selectedRow || this.myTable.selectedRow !== this) {
|
||
|
|
if(this.myTable.selectedRow) this.myTable.selectedRow.deselect();
|
||
|
|
this.myTable.selectedRow = this;
|
||
|
|
this.className = this.myTable.rowSelectedClass;
|
||
|
|
if(row.onSelect) row.onSelect();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
row.deselect = function() {
|
||
|
|
if(this.myTable.selectedRow === this) {
|
||
|
|
this.className = '';
|
||
|
|
this.myTable.selectedRow = '';
|
||
|
|
if(row.onDeselect) row.onDeselect();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
row.selectNext = function() {
|
||
|
|
|
||
|
|
if(this.index < this.myTable.rowCount()-1) { this.deselect(); this.nextSibling.select(); return this.nextSibling; }
|
||
|
|
else {
|
||
|
|
if(this.noAddNew) return this;
|
||
|
|
|
||
|
|
this.deselect();
|
||
|
|
var row = this.myTable.addRow(); return row;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
row.selectPrevious = function() {
|
||
|
|
this.deselect();
|
||
|
|
if(this.previousSibling && this.index > 0) { this.previousSibling.select(); return this.previousSibling; }else return this;
|
||
|
|
}
|
||
|
|
row.deleteRow = function(noNew) {
|
||
|
|
if(this.myTable.selectedCell) this.myTable.selectedCell.deselect();
|
||
|
|
if(this.myTable.selectedRow) this.myTable.selectedRow.deselect();
|
||
|
|
if(this.myTable.rowCount() == 1 && !noNew) {
|
||
|
|
var MyTaBlE = this.myTable;
|
||
|
|
setTimeout( function() { MyTaBlE.addRow(); refreshPositionIndex();} , 1000);
|
||
|
|
}
|
||
|
|
this.myTable.tbody.removeChild(this);
|
||
|
|
this.myTable.refreshRowIndex();
|
||
|
|
}
|
||
|
|
row.moveUp = function() {
|
||
|
|
if(!this.previousSibling) return;
|
||
|
|
this.myTable.tbody.insertBefore(this,this.previousSibling);
|
||
|
|
this.myTable.refreshRowIndex();
|
||
|
|
}
|
||
|
|
row.moveDown = function() {
|
||
|
|
if(!this.nextSibling) this.myTable.addRow(row);
|
||
|
|
this.myTable.tbody.insertBefore(this.nextSibling,this);
|
||
|
|
this.myTable.refreshRowIndex();
|
||
|
|
}
|
||
|
|
row.setData = function(data) {
|
||
|
|
if(!data || typeof(data) != "object") { return; };
|
||
|
|
for(var i=0; i<this.myTable.colCount(); i++) {
|
||
|
|
this.cells.item(i).setData(data);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
row.getData = function() {
|
||
|
|
var data = new Object();
|
||
|
|
for(var i=0; i<this.myTable.colCount(); i++) {
|
||
|
|
if(this.cells.item(i).getData) this.cells.item(i).getData(data,true);
|
||
|
|
}
|
||
|
|
return data;
|
||
|
|
}
|
||
|
|
|
||
|
|
for(var i=0; i<this.colCount(); i++) {
|
||
|
|
var cell = this.createCell(i);
|
||
|
|
row.appendChild(cell);
|
||
|
|
}
|
||
|
|
if(this.onCreateRow) this.onCreateRow(row);
|
||
|
|
return row;
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
this.onCreateRow; //function(row) {}
|
||
|
|
|
||
|
|
this.createCell = function(i) {
|
||
|
|
var cell = document.createElement('td');
|
||
|
|
cell.index = i;
|
||
|
|
cell.myTable = this;
|
||
|
|
cell.onclick = function() { this.select(); }
|
||
|
|
cell.select = function() {
|
||
|
|
|
||
|
|
if(!this.myTable.selectedCell || this.myTable.selectedCell !== this) {
|
||
|
|
if(this.myTable.selectedCell) this.myTable.selectedCell.deselect();
|
||
|
|
this.myTable.selectedCell = this;
|
||
|
|
if(this.firstChild.focus && !this.noSelect) setSelectionRange(this.firstChild);
|
||
|
|
|
||
|
|
if(this.onSelect) this.onSelect();
|
||
|
|
this.className = this.myTable.cellSelectedClass;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
cell.deselect = function() {
|
||
|
|
if(this.myTable.selectedCell === this) {
|
||
|
|
if(cell.onDeselect) cell.onDeselect();
|
||
|
|
this.className = '';
|
||
|
|
this.selected = false;
|
||
|
|
this.myTable.selectedCell = '';
|
||
|
|
}
|
||
|
|
};
|
||
|
|
cell.selectNext = function() {
|
||
|
|
this.deselect();
|
||
|
|
if(this.nextSibling) this.nextSibling.select();
|
||
|
|
else {
|
||
|
|
if(!this.parentNode.nextSibling) { if(this.noNewAdd) return; else this.myTable.addRow(); }
|
||
|
|
this.parentNode.nextSibling.select();
|
||
|
|
this.parentNode.nextSibling.firstChild.select();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
cell.afterCreate = function() {}
|
||
|
|
cell.setData = function(data) {}
|
||
|
|
cell.getData = function(data) {}
|
||
|
|
if(this.onCreateCell) this.onCreateCell(cell);
|
||
|
|
return cell;
|
||
|
|
};
|
||
|
|
this.onCreateCell; //function(cell) {}
|
||
|
|
|
||
|
|
|
||
|
|
this.setRowData = function(row,data) {
|
||
|
|
for(var i=0; i<this.colCount(); i++) {
|
||
|
|
this.setCellData(row,row.cells.item(i),data);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
this.setCellData = function(row,cell,data) {
|
||
|
|
if(typeof(row) == "number")
|
||
|
|
if(this.tbody.rows.item(row)) row = this.tbody.rows.item(row);
|
||
|
|
if(typeof(cell) != "object")
|
||
|
|
if(typeof(cell) == "number" && typeof(row) == "object") {
|
||
|
|
if(row.cells.item(cell))
|
||
|
|
cell = row.cells.item(cell);
|
||
|
|
else return;
|
||
|
|
}
|
||
|
|
else return;
|
||
|
|
if(this.onSetCellData) this.onSetCellData(row,cell,data);
|
||
|
|
}
|
||
|
|
|
||
|
|
this.onSetCellData; //function(row,cell,data) {}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
this.selectRow = function(row) {
|
||
|
|
if(this.selectedRow === row) return;
|
||
|
|
|
||
|
|
|
||
|
|
if(this.selectedRow) this.deselectRow();
|
||
|
|
|
||
|
|
|
||
|
|
this.selectedRow = row;
|
||
|
|
|
||
|
|
|
||
|
|
this.selectedRow.className = this.rowSelectedClass;
|
||
|
|
|
||
|
|
|
||
|
|
this.setEditNames(this.selectedRow,!this.selectedRow.isnew);
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
this.selectNextRow = function() {
|
||
|
|
|
||
|
|
if(!this.selectedRow) return;
|
||
|
|
|
||
|
|
|
||
|
|
if(!this.selectedRow.nextSibling) this.insertRow();
|
||
|
|
|
||
|
|
|
||
|
|
var cell_id = this.selectedCell.lp;
|
||
|
|
|
||
|
|
|
||
|
|
this.selectRow(this.selectedRow.nextSibling);
|
||
|
|
|
||
|
|
|
||
|
|
this.selectCell(this.selectedRow.cells.item(cell_id));
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
this.selectPreviousRow = function() {
|
||
|
|
|
||
|
|
|
||
|
|
if(!this.selectedRow) return;
|
||
|
|
|
||
|
|
|
||
|
|
if(!this.selectedRow.previousSibling) return;
|
||
|
|
|
||
|
|
|
||
|
|
if(this.selectedRow === this.tbody.rows.item(0)) return;
|
||
|
|
|
||
|
|
|
||
|
|
var cell_id = this.selectedCell.lp;
|
||
|
|
|
||
|
|
|
||
|
|
this.selectRow(this.selectedRow.previousSibling);
|
||
|
|
|
||
|
|
|
||
|
|
this.selectCell(this.selectedRow.cells.item(cell_id));
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
this.refreshNumeration = function() {
|
||
|
|
for(var i=0; i<this.tbody.rows.length; i++)
|
||
|
|
this.tbody.rows.item(i).cells.item(0).firstChild.value = i+1;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.KeyPressedNumber = function(e) {
|
||
|
|
var keynum;
|
||
|
|
if(window.event) //IE
|
||
|
|
keynum = e.keyCode;
|
||
|
|
else
|
||
|
|
keynum = e.which;
|
||
|
|
return keynum;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.KeyPressed = function(e, cell, method) {
|
||
|
|
var keynum;
|
||
|
|
if(window.event) //IE
|
||
|
|
keynum = e.keyCode;
|
||
|
|
else
|
||
|
|
keynum = e.which;
|
||
|
|
if((keynum == 9) || (keynum == 13)) {
|
||
|
|
cell.selectNext();
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if(keynum == 40) { var id = cell.index; var row = cell.parentNode.selectNext(); if(row) { row.select(); row.cells.item(id).select(); } }
|
||
|
|
if(keynum == 38) { var id = cell.index; var row = cell.parentNode.selectPrevious(); if(row) { row.select(); row.cells.item(id).select(); } }
|
||
|
|
if(e.shiftKey && (method == "decimalNumber" || method == "onlyNumber")) return false;
|
||
|
|
if(method == "decimalNumber") return this.OnlyNumbers(keynum);
|
||
|
|
if(method == "onlyNumber") return this.OnlyNumbers(keynum, true);
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.OnlyNumbers = function(e, noQuote) { var keynum = e, keychar, numcheck;
|
||
|
|
keychar = String.fromCharCode(keynum);
|
||
|
|
numcheck = /\d/;
|
||
|
|
return numcheck.test(keychar) || ((!noQuote)?(keynum == 190):false)
|
||
|
|
|| (keynum == 8) //backspace
|
||
|
|
|| (keynum == 46) //delete
|
||
|
|
|| (keynum == 13) //enter || (keynum == 0) //special keys with FF
|
||
|
|
|| (keynum == 37) //left arrow
|
||
|
|
|| (keynum == 39) //right arrow
|
||
|
|
|| (keynum == 188); //,
|
||
|
|
}
|
||
|
|
|
||
|
|
this.row = function(i) { if(this.tbody.rows.item(i)) return this.tbody.rows.item(i); }
|
||
|
|
this.cells = function(i,j) { if(this.tbody.rows.item(i).cells.item(i)) return this.tbody.rows.item(i).cells.item(i); }
|
||
|
|
}
|