306 lines
9.3 KiB
JavaScript
306 lines
9.3 KiB
JavaScript
|
|
//addresses
|
||
|
|
function saveItems(){
|
||
|
|
document.getElementById('position_list').value = ItemsList(true);
|
||
|
|
}
|
||
|
|
function doRequest(where,post,doFunction,error) {
|
||
|
|
|
||
|
|
this.Display = function(result) { doFunction(result.responseText); }
|
||
|
|
|
||
|
|
this.Fail = function(result){ if(error) alert(error);}
|
||
|
|
|
||
|
|
YAHOO.util.Connect.asyncRequest('POST',where,{success:this.Display,failure:this.Fail},post);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function changeValidateRequired(formname,name,required) {
|
||
|
|
|
||
|
|
for(var i=0; i<validate[formname].length; i++)
|
||
|
|
|
||
|
|
if(validate[formname][i][0] == name) { validate[formname][i][2] = required; break; }
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function addEvent(object,eventName,do_function) {
|
||
|
|
if(typeof(object) == "string") object = document.getElementById(object);
|
||
|
|
if(!object) { alert('No object in function addEvent!'); return; }
|
||
|
|
if(object.addEventListener) {
|
||
|
|
object.addEventListener(eventName, do_function, false);
|
||
|
|
} else {
|
||
|
|
object.attachEvent('on'+eventName, do_function);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
var tbody_;
|
||
|
|
var ItemListSave;
|
||
|
|
var ItemListClear;
|
||
|
|
var ItemListFil;
|
||
|
|
var FillText;
|
||
|
|
|
||
|
|
addEvent(
|
||
|
|
window,
|
||
|
|
'load',
|
||
|
|
function() {
|
||
|
|
var paramsTable = new paramsMT('itemsTable');
|
||
|
|
paramsTable.onCreateRow = function(row) {
|
||
|
|
row.newPos = false;
|
||
|
|
row.noAddNew = true;
|
||
|
|
row.ondblclick = function() {}
|
||
|
|
row.onSelect = function() {
|
||
|
|
//for(var i=0; i<this.myTable.colCount(); i++)
|
||
|
|
//this.cells.item(i).change(!this.newPos);
|
||
|
|
//this.cells.item(0).change(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
row.onDeselect = function() {
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
paramsTable.onCreateCell = function(cell) {
|
||
|
|
|
||
|
|
var i = cell.index;
|
||
|
|
cell.change = function(select) {};
|
||
|
|
if(i == 0) {
|
||
|
|
cell.setData = function(data) {
|
||
|
|
if(data.position) cell.firstChild.value = data.position;
|
||
|
|
if (data.id)
|
||
|
|
cell.getElementsByTagName('input')[1].value = data.id;
|
||
|
|
};
|
||
|
|
cell.getData = function(data) {
|
||
|
|
data.position = cell.firstChild.value;
|
||
|
|
data.id = cell.getElementsByTagName('input')[1].value;
|
||
|
|
}
|
||
|
|
//cell.select = function() { this.selectNext(); }
|
||
|
|
//cell.selectNext = function() { var row = this.parentNode.selectNext(); row.select(); row.cells.item(i).select(); };
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','text');
|
||
|
|
edit.setAttribute('readonly','readonly');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','hidden');
|
||
|
|
edit.setAttribute('readonly','readonly');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
}
|
||
|
|
if(i == 1) {
|
||
|
|
cell.setData = function(data) {
|
||
|
|
if(data.name) {
|
||
|
|
cell.firstChild.value = data.name;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
cell.getData = function(data) {
|
||
|
|
data.name = cell.firstChild.value;
|
||
|
|
}
|
||
|
|
|
||
|
|
cell.onDeselect = function() {
|
||
|
|
ERROR = false;
|
||
|
|
var data = new Object();
|
||
|
|
this.getData(data);
|
||
|
|
if(!ERROR) {
|
||
|
|
data.name = data.name;
|
||
|
|
this.setData(data);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//cell.select = function() { this.selectNext(); }
|
||
|
|
//cell.selectNext = function() { var row = this.parentNode.selectNext(); row.select(); row.cells.item(i).select(); };
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','text');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
}
|
||
|
|
if(i == 2) {
|
||
|
|
cell.setData = function(data) {
|
||
|
|
if (data.street)
|
||
|
|
cell.getElementsByTagName('input')[0].value = data.street;
|
||
|
|
};
|
||
|
|
cell.getData = function(data) {
|
||
|
|
data.street = cell.firstChild.value;
|
||
|
|
}
|
||
|
|
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','text');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
|
||
|
|
}
|
||
|
|
if(i == 3) {
|
||
|
|
cell.setData = function(data) {
|
||
|
|
if(data.city) cell.firstChild.value = data.city;
|
||
|
|
};
|
||
|
|
cell.getData = function(data) {
|
||
|
|
data.city = cell.firstChild.value;
|
||
|
|
}
|
||
|
|
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','text');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
}
|
||
|
|
if(i == 4) {
|
||
|
|
cell.setData = function(data) {
|
||
|
|
if(data.postalcode) cell.firstChild.value = data.postalcode;
|
||
|
|
};
|
||
|
|
cell.getData = function(data) {
|
||
|
|
data.postalcode = cell.firstChild.value;
|
||
|
|
}
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','text');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
}
|
||
|
|
if(i == 5) {
|
||
|
|
cell.setData = function(data) {
|
||
|
|
if(data.country) cell.firstChild.value = data.country;
|
||
|
|
};
|
||
|
|
cell.getData = function(data) {
|
||
|
|
data.country = cell.firstChild.value;
|
||
|
|
}
|
||
|
|
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','text');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
}
|
||
|
|
if(i == 6) {
|
||
|
|
cell.setData = function(data) {
|
||
|
|
if(data.phone) cell.firstChild.value = data.phone;
|
||
|
|
};
|
||
|
|
cell.getData = function(data) {
|
||
|
|
data.phone = cell.firstChild.value;
|
||
|
|
}
|
||
|
|
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','text');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
}
|
||
|
|
if(i == 7) {
|
||
|
|
cell.setData = function(data) {
|
||
|
|
if(data.fax) cell.firstChild.value = data.fax;
|
||
|
|
};
|
||
|
|
cell.getData = function(data) {
|
||
|
|
data.fax = cell.firstChild.value;
|
||
|
|
}
|
||
|
|
|
||
|
|
var edit = document.createElement('input');
|
||
|
|
edit.setAttribute('type','text');
|
||
|
|
edit.setAttribute('tabIndex',1);
|
||
|
|
edit.className = 'inputs';
|
||
|
|
cell.appendChild(edit);
|
||
|
|
}
|
||
|
|
if(i == 8) {
|
||
|
|
var img;
|
||
|
|
|
||
|
|
cell.style.padding="auto auto auto auto";
|
||
|
|
//insert
|
||
|
|
img = document.createElement('img');
|
||
|
|
img.setAttribute('alt',MOD['LBL_INSERT_NEW_ROW']);
|
||
|
|
img.setAttribute('src','modules/EcmQuotes/images/insertrow.gif');
|
||
|
|
img.style.cursor = 'pointer';
|
||
|
|
img.onclick = function() {
|
||
|
|
this.parentNode.myTable.addRow(this.parentNode.parentNode.index+1);
|
||
|
|
refreshPositionIndex();
|
||
|
|
};
|
||
|
|
|
||
|
|
//delete
|
||
|
|
cell.appendChild(img);
|
||
|
|
cell.appendChild(document.createTextNode(" "));
|
||
|
|
img = document.createElement('img');
|
||
|
|
img.setAttribute('alt',MOD['LBL_DELETE_ROW']);
|
||
|
|
img.setAttribute('src','modules/EcmQuotes/images/deleterow.gif');
|
||
|
|
img.style.cursor = 'pointer';
|
||
|
|
img.onclick = function() { this.parentNode.parentNode.deleteRow(); refreshPositionIndex();};
|
||
|
|
cell.appendChild(img);
|
||
|
|
cell.appendChild(document.createTextNode(" "));
|
||
|
|
|
||
|
|
cell.appendChild(document.createElement('br'));
|
||
|
|
//move up
|
||
|
|
img = document.createElement('img');
|
||
|
|
img.setAttribute('alt',MOD['LBL_MOVE_ROW_UP']);
|
||
|
|
img.setAttribute('src','modules/EcmQuotes/images/moverowup.gif');
|
||
|
|
img.style.cursor = 'pointer';
|
||
|
|
img.onclick = function() { this.parentNode.parentNode.moveUp(); refreshPositionIndex();};
|
||
|
|
cell.appendChild(img);
|
||
|
|
cell.appendChild(document.createTextNode(" "));
|
||
|
|
//move down
|
||
|
|
img = document.createElement('img');
|
||
|
|
img.setAttribute('alt',MOD['LBL_MOVE_ROW_DOWN']);
|
||
|
|
img.setAttribute('src','modules/EcmQuotes/images/moverowdown.gif');
|
||
|
|
img.style.cursor = 'pointer';
|
||
|
|
img.onclick = function() { this.parentNode.parentNode.moveDown();refreshPositionIndex(); }
|
||
|
|
cell.appendChild(img);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
refreshPositionIndex = function() {
|
||
|
|
for(var i=0; i<paramsTable.rowCount(); i++) {
|
||
|
|
var data = paramsTable.row(i).getData();
|
||
|
|
data.position = i+1;
|
||
|
|
paramsTable.row(i).setData(data);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ItemsList = function(json) {
|
||
|
|
var data = '';
|
||
|
|
for(var i=0; i<paramsTable.rowCount(); i++) {
|
||
|
|
data = data + '||||' + JSON.stringifyNoSecurity(paramsTable.row(i).getData());
|
||
|
|
}
|
||
|
|
return data;
|
||
|
|
}
|
||
|
|
if(paramsTable.rowCount() == 0) {paramsTable.addRow(); refreshPositionIndex();};
|
||
|
|
paramsTable.onSetCellData = function(row,cell,data) {
|
||
|
|
if(cell.innerHTML == '') cell.innerHTML = ' ';
|
||
|
|
}
|
||
|
|
|
||
|
|
ItemListSave = function(json,el) {
|
||
|
|
var data = new Object();
|
||
|
|
var tmp;
|
||
|
|
for(var i=0; i<paramsTable.rowCount(); i++) {
|
||
|
|
data[i.toString()] = paramsTable.row(i).getData();
|
||
|
|
}
|
||
|
|
paramsOptions = data;
|
||
|
|
var r = JSON.stringifyNoSecurity(paramsOptions);
|
||
|
|
doRequest(
|
||
|
|
'index.php',
|
||
|
|
'module=Accounts&action=price_conditionSave&to_pdf=1¶mslist='+r+'&record='+document.forms.EditView.record.value,
|
||
|
|
function(result) {
|
||
|
|
if(result.indexOf("Saved") >= 0) alert("Zapisano!"); else alert("Błąd podczas zapisywania!");
|
||
|
|
}
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
ItemListClear = function(noNew,save) {
|
||
|
|
if(typeof(save)=="string") ItemListSave(null,save);
|
||
|
|
while(paramsTable.rowCount()>0) paramsTable.row(0).deleteRow(noNew);
|
||
|
|
refreshPositionIndex();
|
||
|
|
}
|
||
|
|
|
||
|
|
ItemListFill = function() {
|
||
|
|
var pl;
|
||
|
|
pl = document.getElementById('position_list').value;
|
||
|
|
if(pl && pl != '') {
|
||
|
|
try {
|
||
|
|
pl = eval(pl);
|
||
|
|
for(x in pl) { var pl_row = pl[x]; if (pl_row.template=='') continue; paramsTable.addRow().setData(pl_row); }
|
||
|
|
} catch(err) { pl = null; };
|
||
|
|
}
|
||
|
|
refreshPositionIndex();
|
||
|
|
}
|
||
|
|
|
||
|
|
ItemListClear();
|
||
|
|
ItemListFill();
|
||
|
|
}
|
||
|
|
);
|