Add JS files
This commit is contained in:
402
modules/EcmProducts/AjaxSearch/AjaxSearch.js
Executable file
402
modules/EcmProducts/AjaxSearch/AjaxSearch.js
Executable file
@@ -0,0 +1,402 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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(); }
|
||||
}
|
||||
|
||||
var AjaxSearchItems;
|
||||
function AjaxSearch(div,displayNone) {
|
||||
|
||||
//fields
|
||||
|
||||
this.parentDIV = div; //pole w ktorym zawiera sie pole wyszukiwania
|
||||
this.div; //pole glowne wyszukiwania
|
||||
this.inputSearch; //input wyszukiwania
|
||||
this.timeout; //wskaznik zwracany przez setTimeout przy wcisnieciu klawisza
|
||||
this.searchDelay = 800; //opoznienie wyszukiwania
|
||||
this.divList; //pole w ktorym wyswietlana bedzie lista znalezionnych elementow
|
||||
this.ajaxSearchItem; //unikalny identyfikator;
|
||||
this.module = 'EcmQuotes';
|
||||
this.inputCode;
|
||||
|
||||
this.positionSelected;
|
||||
|
||||
//functions
|
||||
this.setInputCode = function(input) {
|
||||
this.inputCode = input;
|
||||
this.inputCode.previousCode = this.inputCode.value;
|
||||
}
|
||||
|
||||
this.inputSearchOnKeyDown = function(e,other) {
|
||||
var keynum;
|
||||
if(typeof(e) == "number")
|
||||
keynum = e;
|
||||
else {
|
||||
if(window.event) //IE
|
||||
keynum = e.keyCode;
|
||||
else
|
||||
keynum = e.which;
|
||||
}
|
||||
|
||||
if(keynum == 38) { this.selectPreviousPosition(); return false; }
|
||||
if(keynum == 40) { this.selectNextPosition(); return false; }
|
||||
if(keynum == 13 || keynum == 9) { this.inputSearchEnterPressed(other); return false; }
|
||||
if(keynum == 27) { this.div.style.display = 'none'; }
|
||||
|
||||
if(this.timeout) { clearTimeout(this.timeout); this.timeout = null; }
|
||||
this.timeout = setTimeout("document.getElementById('"+this.div.id+"').AjaxSearch.search();", 500);
|
||||
}
|
||||
|
||||
this.inputSearchEnterPressed = function(other) {
|
||||
if(this.positionSelected) {
|
||||
var row;
|
||||
if(N.selectedRow) {
|
||||
N.selectedRow.setData(this.positionSelected.positionData);
|
||||
row = N.selectedRow;
|
||||
}
|
||||
else {
|
||||
row = N.addRow().setData(this.positionSelected.positionData);
|
||||
}
|
||||
row.calculateTotal();
|
||||
if((other && other == "clear") || OPT['quick_product_item_adding']==0) {
|
||||
this.clearList();
|
||||
this.div.style.display = 'none';
|
||||
if(OPT['quick_product_item_adding'] == 0) if(N.selectedCell && N.selectedCell.index == 1) N.selectedCell.selectNext();
|
||||
} else {
|
||||
row.noHideASP = true;
|
||||
if(N.selectedRow) row = row.myTable.addRow(row.index+1);
|
||||
row.select();
|
||||
row.cells.item(0).select();
|
||||
setSelectionRange(this.inputSearch);
|
||||
}
|
||||
}
|
||||
else if(N.selectedRow) {
|
||||
if(this.inputSearch.value != this.inputCode.previousCode || this.inputCode.previousCode == '') {
|
||||
var data = new Object();
|
||||
N.selectedRow.setData(data);
|
||||
N.selectedRow.cells.item(1).select();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//N.addRow();
|
||||
}
|
||||
|
||||
this.selectNextPosition = function() {
|
||||
if(this.positionSelected) {
|
||||
if(this.positionSelected.nextSibling) {
|
||||
this.positionSelect(this.positionSelected.nextSibling);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.positionSelect(this.divList.lastChild);
|
||||
}
|
||||
|
||||
this.selectPreviousPosition = function() {
|
||||
if(this.positionSelected) {
|
||||
if(this.positionSelected.previousSibling) {
|
||||
this.positionSelect(this.positionSelected.previousSibling);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.positionSelect(this.divList.firstChild);
|
||||
}
|
||||
|
||||
this.search = function() {
|
||||
|
||||
if(this.inputSearch.value == '') { this.clearList(); return; }
|
||||
var _ajax_search_process_search_ = this;
|
||||
this.Display = function(result) { _ajax_search_process_search_.processSearch(result.responseText); }
|
||||
this.Fail = function(result) { alert(result.responseText); }
|
||||
YAHOO.util.Connect.asyncRequest('POST','index.php',{success:this.Display,failure:this.Fail},'module='+this.module+'&action=AjaxSearchQuery&to_pdf=1&as_inputSearch='+this.inputSearch.value); //+'&ecmlanguage='+document.forms.EditView.ecmlanguage.value);
|
||||
|
||||
}
|
||||
|
||||
this.processSearch = function(result) {
|
||||
this.clearList();
|
||||
var list = eval(result);
|
||||
if(typeof(list) != "object") return;
|
||||
this.fillList(list);
|
||||
}
|
||||
|
||||
this.clearList = function() {
|
||||
this.divList.innerHTML = '';
|
||||
this.divList.style.height = '';
|
||||
this.positionDeselect();
|
||||
}
|
||||
|
||||
this.fillList = function(list) {
|
||||
for(x in list) {
|
||||
this.addPosition(list[x]);
|
||||
}
|
||||
this.positionSelect();
|
||||
this.setScrolls();
|
||||
}
|
||||
|
||||
this.setScrolls = function() {
|
||||
var clientH = -1;
|
||||
if(window.innerHeight && window.innerHeight > 0) clientH = window.innerHeight;
|
||||
else if(document.documentElement && document.documentElement.clientHeight > 0) clientH = document.documentElement.clientHeight;
|
||||
else if(document.body && document.body.clientHeight > 0) clientH = document.body.clientHeight;
|
||||
var XY = YAHOO.util.Dom.getXY(this.div);
|
||||
var divTop = (XY[1]+this.div.offsetHeight);
|
||||
if((divTop - (clientH+document.body.scrollTop)) > 0) {
|
||||
var newPos = divTop-clientH;
|
||||
document.body.scrollTop = newPos;
|
||||
}
|
||||
}
|
||||
|
||||
this.positionSelect = function(div,noScroll) {
|
||||
if(!div) {
|
||||
if(!this.positionSelected) {
|
||||
if(this.divList.firstChild) this.positionSelect(this.divList.firstChild);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.positionDeselect();
|
||||
div.className = 'AjaxSearchPositionDivSelected';
|
||||
this.positionSelected = div;
|
||||
if(!noScroll) this.divList.scrollTop = div.offsetTop;
|
||||
}
|
||||
|
||||
this.positionDeselect = function() {
|
||||
if(this.positionSelected) {
|
||||
this.positionSelected.className = '';
|
||||
this.positionSelected = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.addPosition = function(list) {
|
||||
if(typeof(list.code) == "undefined") return;
|
||||
var position = document.createElement('div');
|
||||
position.positionData = list;
|
||||
position.onclick = function() { this.parentNode.AjaxSearch.inputSearchEnterPressed(this); }
|
||||
position.onmouseover = function() { this.parentNode.AjaxSearch.positionSelect(this,true); };
|
||||
position.innerHTML = '<table width="100%" class="AjaxSearchPositionTable"><tr><td class="AjaxSearchPositionTableCode">'+this.markElement(list['code'])+'</td><td align="right" class="AjaxSearchPositionTablePrice">'+list['purchase_price']+' '+list['currency_symbol']+'<span style="color:black"> - </span><b>'+list['selling_price']+' '+list['currency_symbol']+'</b></td></tr><tr><td colspan="2" class="AjaxSearchPositionTableName">'+this.markElement(list['name'])+'</td></tr></table>';
|
||||
this.divList.appendChild(position);
|
||||
if((position.offsetTop+position.offsetHeight) > 300) this.divList.style.height = '300px'; else this.divList.style.height = '';
|
||||
}
|
||||
|
||||
this.markElement = function(str) {
|
||||
var s = "("+this.inputSearch.value+")";
|
||||
var regExp = new RegExp(s,'gi');
|
||||
return str.replace(regExp,"<b>$1</b>");
|
||||
}
|
||||
|
||||
this.AjaxSearchFrozen = false;
|
||||
this.AjaxSearchGetSettings = function () {
|
||||
var AjaxSearchToReq = this;
|
||||
YAHOO.util.Connect.asyncRequest(
|
||||
'POST',
|
||||
'index.php',
|
||||
{
|
||||
success: function(response) {
|
||||
if(response.responseText) {
|
||||
var str = response.responseText;
|
||||
var obj = eval(str);
|
||||
if(obj && obj[0]) {
|
||||
obj = obj[0];
|
||||
//if(obj.frozen) {
|
||||
AjaxSearchToReq.div.style.left = obj.pos_left;
|
||||
AjaxSearchToReq.div.style.top = obj.pos_top;
|
||||
AjaxSearchToReq.AjaxSearchFrozen = !(obj.frozen == "true" ? true : false);
|
||||
AjaxSearchToReq.AjaxSearchFreezePosition(true);
|
||||
//}
|
||||
}
|
||||
}
|
||||
},
|
||||
failure: function(response) {}
|
||||
},
|
||||
'module=Home&action=EcmAjaxSearchSettings&function=GetSettings&to_pdf=1&from_module='+this.module
|
||||
);
|
||||
}
|
||||
this.AjaxSearchSaveSettings = function () {
|
||||
YAHOO.util.Connect.asyncRequest(
|
||||
'POST',
|
||||
'index.php',
|
||||
{
|
||||
success: function(response) {},
|
||||
failure: function(response) {}
|
||||
},
|
||||
'module=Home&action=EcmAjaxSearchSettings&function=SaveSettings&to_pdf=1&from_module='+this.module+'&pos_top='+this.div.style.top+'&pos_left='+this.div.style.left+'&frozen='+this.AjaxSearchFrozen
|
||||
);
|
||||
}
|
||||
this.AjaxSearchFreezePosition = function (dontSave) {
|
||||
var img = document.getElementById('AjaxSearchPin');
|
||||
if(this.AjaxSearchFrozen) {
|
||||
img.src='modules/'+this.module+'/AjaxSearch/AjaxSearchPinOff.gif';
|
||||
this.AjaxSearchFrozen = false;
|
||||
} else {
|
||||
img.src='modules/'+this.module+'/AjaxSearch/AjaxSearchPinOn.gif';
|
||||
this.AjaxSearchFrozen = true;
|
||||
}
|
||||
if(!dontSave) this.AjaxSearchSaveSettings();
|
||||
}
|
||||
|
||||
this.createForm = function() {
|
||||
/*
|
||||
var div = document.createElement('div');
|
||||
div.className = 'AjaxSearch';
|
||||
div.AjaxSearch = this;
|
||||
*/
|
||||
var tmp = document.createElement('div');
|
||||
var div = "<div></div>";
|
||||
tmp.innerHTML = div;
|
||||
div = tmp.firstChild;
|
||||
|
||||
div.className = 'AjaxSearch';
|
||||
div.AjaxSearch = this;
|
||||
div.onMouseMoveEvent = function(ev) {
|
||||
if(!this.isOnMouseDown) return;
|
||||
ev = ev || window.event;
|
||||
var x = 0; var y = 0;
|
||||
if(ev.pageX || ev.pageY) {
|
||||
x = ev.pageX;
|
||||
y = ev.pageY;
|
||||
} else {
|
||||
x = ev.clientX + document.body.scrollLeft - document.body.clientLeft,
|
||||
y = ev.clientY + document.body.scrollTop - document.body.clientTop
|
||||
}
|
||||
this.style.left = x-this.MouseX;
|
||||
this.style.top = y-this.MouseY;
|
||||
}
|
||||
div.onMouseDownEvent = function(ev) {
|
||||
if(this.noDrag) { this.noDrag = false; return; }
|
||||
ev = ev || window.event;
|
||||
var x = 0; var y = 0;
|
||||
if(ev.pageX || ev.pageY) {
|
||||
x = ev.pageX;
|
||||
y = ev.pageY;
|
||||
} else {
|
||||
x = ev.clientX + document.body.scrollLeft - document.body.clientLeft,
|
||||
y = ev.clientY + document.body.scrollTop - document.body.clientTop
|
||||
}
|
||||
this.MouseX = x-this.offsetLeft;
|
||||
this.MouseY = y-this.offsetTop;
|
||||
this.isOnMouseDown = true;
|
||||
this.style.cursor = 'move';
|
||||
}
|
||||
div.onmouseup = function() {
|
||||
this.isOnMouseDown = false;
|
||||
this.style.cursor = '';
|
||||
//this.AjaxSearch.AjaxSearchSaveSettings();
|
||||
}
|
||||
//div.onmouseout = function() { this.onmouseup(); }
|
||||
ddiv = document.createElement('div');
|
||||
ddiv.id = 'AjaxSearch_ddiv';
|
||||
ddiv.className = 'AjaxSearch_ddiv';
|
||||
ddiv.appendChild(document.createTextNode('Search Product:'));
|
||||
ddiv.appendChild(document.createElement('br'));
|
||||
div.appendChild(ddiv);
|
||||
/*
|
||||
var inputSearch = document.createElement('input');
|
||||
inputSearch.type = 'text';
|
||||
inputSearch.id = 'as_inputSearch';
|
||||
inputSearch.className = 'AjaxSearchInputSearch';
|
||||
inputSearch.AjaxSearch = this;
|
||||
inputSearch.onkeydown = this.inputSearchOnKeyDown;
|
||||
this.inputSearch = inputSearch;
|
||||
div.appendChild(inputSearch);
|
||||
*/
|
||||
var img = '<img src="modules/'+this.module+'/AjaxSearch/AjaxSearchPinOff.gif" id="AjaxSearchPin" class="AjaxSearchPin" onclick="this.parentNode.AjaxSearch.AjaxSearchFreezePosition();" />';
|
||||
img += '<img src="modules/'+this.module+'/AjaxSearch/AjaxSearchCloseIcon.gif" class="AjaxSearchCloseIcon" onclick="this.parentNode.AjaxSearch.inputSearchOnKeyDown(27);" />';
|
||||
div.innerHTML += img;
|
||||
|
||||
|
||||
var inputSearch = '<input type="text" id="as_inputSearch" class="AjaxSearchInputSearch" onKeyDown="return this.AjaxSearch.inputSearchOnKeyDown(event);">';
|
||||
div.innerHTML = div.innerHTML + inputSearch;
|
||||
this.inputSearch = div.lastChild;
|
||||
this.inputSearch.AjaxSearch = this;
|
||||
this.inputSearch.onmousedown = function() { this.parentNode.noDrag = true; }
|
||||
|
||||
div.appendChild(document.createElement('br'));
|
||||
div.appendChild(document.createElement('br'));
|
||||
|
||||
/*
|
||||
div.appendChild(document.createTextNode('List:'));
|
||||
|
||||
var separator = document.createElement('hr');
|
||||
separator.className = 'AjaxSearchSeparator';
|
||||
div.appendChild(separator);
|
||||
*/
|
||||
|
||||
var divList = document.createElement('div');
|
||||
|
||||
divList.id = 'as_divList';
|
||||
divList.className = 'AjaxSearchDivList';
|
||||
divList.AjaxSearch = this;
|
||||
this.divList = divList;
|
||||
divList.onmousedown = function() { this.parentNode.noDrag = true; }
|
||||
div.appendChild(divList);
|
||||
|
||||
var tmpDiv = document.createElement('div');
|
||||
tmpDiv.style.height = '10px';
|
||||
div.appendChild(tmpDiv);
|
||||
|
||||
this.parentDIV.appendChild(div);
|
||||
this.div = div;
|
||||
|
||||
}
|
||||
|
||||
this.KeyDown = function(e) {
|
||||
|
||||
var keynum;
|
||||
if(window.event) //IE
|
||||
keynum = e.keyCode;
|
||||
else
|
||||
keynum = e.which;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//constructor
|
||||
|
||||
if(AjaxSearchItems) {
|
||||
if(typeof(AjaxSearchItems) == "number")
|
||||
AjaxSearchItem++;
|
||||
else
|
||||
AjaxSearchItem = 0;
|
||||
this.ajaxSearchItem = AjaxSearchItem;
|
||||
}
|
||||
|
||||
this.createForm();
|
||||
|
||||
this.div.AjaxSearch = this;
|
||||
this.div.id = 'AjaxSearch_'+this.AjaxSearchItem;
|
||||
var AjaxSearch_draganddrop = new YAHOO.util.DD(this.div.id);
|
||||
AjaxSearch_draganddrop.AjaxSearch = this;
|
||||
AjaxSearch_draganddrop.endDrag = function(e) {
|
||||
this.AjaxSearch.AjaxSearchSaveSettings();
|
||||
};
|
||||
AjaxSearch_draganddrop.setHandleElId("AjaxSearch_ddiv");
|
||||
this.div.style.left = (screen.availWidth - this.div.offsetWidth) / 2;
|
||||
this.div.style.top = (screen.availHeight - this.div.offsetHeight) / 2;
|
||||
if(displayNone == true) this.div.style.display = 'none';
|
||||
this.AjaxSearchGetSettings();
|
||||
|
||||
|
||||
};
|
||||
205
modules/EcmProducts/Categories.js
Executable file
205
modules/EcmProducts/Categories.js
Executable file
@@ -0,0 +1,205 @@
|
||||
//categories
|
||||
function saveItems3(){
|
||||
document.getElementById('position_list3').value = ItemsList3(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 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 ItemListSave3;
|
||||
var ItemListClear3;
|
||||
var ItemListFil3;
|
||||
var FillText;
|
||||
|
||||
addEvent(
|
||||
window,
|
||||
'load',
|
||||
function() {
|
||||
var paramsTable3 = new paramsMT('itemsTable3');
|
||||
paramsTable3.onCreateRow = function(row) {
|
||||
row.newPos = false;
|
||||
row.noAddNew = true;
|
||||
row.ondblclick = function() {}
|
||||
row.onSelect = function() {
|
||||
}
|
||||
row.onDeselect = function() {
|
||||
}
|
||||
}
|
||||
|
||||
refreshPositionIndex = function() {
|
||||
for(var i=0; i<paramsTable3.rowCount(); i++) {
|
||||
var data = paramsTable3.row(i).getData();
|
||||
data.position = i+1;
|
||||
paramsTable3.row(i).setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
paramsTable3.onCreateCell = function(cell) {
|
||||
|
||||
var i = cell.index;
|
||||
if(i == 0) {
|
||||
|
||||
cell.setData = function(data) {
|
||||
console.log(data);
|
||||
if(data.ecmproductcategory_name) {
|
||||
cell.firstChild.value = data.ecmproductcategory_name;
|
||||
|
||||
cell.getElementsByTagName('input')[1].value = data.ecmproductcategory_id;
|
||||
if (data.id)
|
||||
cell.getElementsByTagName('input')[2].value = data.id;
|
||||
}
|
||||
};
|
||||
cell.getData = function(data) {
|
||||
data.ecmproductcategory_name = cell.firstChild.value;
|
||||
data.ecmproductcategory_id = cell.getElementsByTagName('input')[1].value;
|
||||
data.id = cell.getElementsByTagName('input')[2].value;
|
||||
}
|
||||
|
||||
cell.onSelect = function() {
|
||||
var cn = this.getElementsByTagName('input');
|
||||
cn[0].name = 'name_p';
|
||||
cn[0].id = 'name_p';
|
||||
|
||||
cn[1].name = 'id_p';
|
||||
cn[1].id = 'id_p';
|
||||
}
|
||||
cell.onDeselect = function() {
|
||||
ERROR = false;
|
||||
var data = new Object();
|
||||
this.getData(data);
|
||||
if(!ERROR) {
|
||||
data.product_group = data.product_group;
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
var cn = this.getElementsByTagName('input');
|
||||
cn[0].name = '';
|
||||
cn[0].id = '';
|
||||
|
||||
cn[1].name = '';
|
||||
cn[1].id = '';
|
||||
}
|
||||
//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);
|
||||
var edit = document.createElement('input');
|
||||
edit.setAttribute('type','hidden');
|
||||
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);
|
||||
var img = document.createElement('img');
|
||||
img.setAttribute('alt',MOD['LBL_IMG_SEARCH']);
|
||||
img.setAttribute('src','modules/EcmQuotes/images/search.gif');
|
||||
img.style.cursor = 'pointer';
|
||||
img.onclick = function() {
|
||||
var ecmpopup = open_popup( "EcmProductCategories", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"EditView","field_to_name_array":{"id":"id_p","name":"name_p"}}, "single", true );
|
||||
setTimeout(function(){ecmpopup.focus();},200);
|
||||
}
|
||||
cell.appendChild(img);
|
||||
}
|
||||
if(i == 1) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
ItemsList3 = function(json) {
|
||||
var data = '';
|
||||
for(var i=0; i<paramsTable3.rowCount(); i++) {
|
||||
var tmp = paramsTable3.row(i).getData();
|
||||
tmp['position'] = i;
|
||||
console.log(tmp);
|
||||
data = data + '||||' + JSON.stringifyNoSecurity(tmp);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
if(paramsTable3.rowCount() == 0) {paramsTable3.addRow();};
|
||||
paramsTable3.onSetCellData = function(row,cell,data) {
|
||||
if(cell.innerHTML == '') cell.innerHTML = ' ';
|
||||
}
|
||||
|
||||
ItemListFill3 = function() {
|
||||
var pl;
|
||||
pl = document.getElementById('position_list3').value;
|
||||
console.log(pl);
|
||||
if(pl && pl != '') {
|
||||
try {
|
||||
pl = eval(pl);
|
||||
for(x in pl) { var pl_row = pl[x]; if (pl_row.template=='') continue; paramsTable3.addRow().setData(pl_row); }
|
||||
} catch(err) { pl = null; };
|
||||
}
|
||||
}
|
||||
|
||||
ItemListClear3 = function(noNew,save) {
|
||||
if(typeof(save)=="string") ItemListSave3(null,save);
|
||||
while(paramsTable3.rowCount()>0) paramsTable3.row(0).deleteRow(noNew);
|
||||
}
|
||||
|
||||
ItemListClear3();
|
||||
ItemListFill3();
|
||||
}
|
||||
);
|
||||
98
modules/EcmProducts/Menu/ecmproducts.js
Executable file
98
modules/EcmProducts/Menu/ecmproducts.js
Executable file
@@ -0,0 +1,98 @@
|
||||
//<2F>Xara Ltd
|
||||
if(typeof(loc)=="undefined"||loc==""){var loc="";if(document.body&&document.body.innerHTML){var tt=document.body.innerHTML;var ml=tt.match(/["']([^'"]*)ecmproducts.js["']/i);if(ml && ml.length > 1) loc=ml[1];}}
|
||||
|
||||
var bd=1
|
||||
document.write("<style type=\"text/css\">");
|
||||
document.write("\n<!--\n");
|
||||
document.write(".ecmproducts_menu {z-index:999;border-color:#adc6d6;border-style:solid;border-width:"+bd+"px "+bd+"px "+bd+"px "+bd+"px;background-color:#f7f7f7;position:absolute;left:0px;top:0px;visibility:hidden;}");
|
||||
document.write(".ecmproducts_plain, a.ecmproducts_plain:link, a.ecmproducts_plain:visited{text-align:left;background-color:#f7f7f7;color:#000000;text-decoration:none;border-color:#adc6d6;border-style:solid;border-width:"+bd+"px "+bd+"px "+bd+"px "+bd+"px;padding:2px 2px 2px 2px;cursor:hand;display:block;font-size:8pt;font-weight:bold;font-family:Arial, Helvetica, sans-serif;}");
|
||||
document.write("a.ecmproducts_plain:hover, a.ecmproducts_plain:active{background-color:#adc6d6;color:#ffffff;text-decoration:bolder;border-color:#adc6d6;border-style:solid;border-width:"+bd+"px "+bd+"px "+bd+"px "+bd+"px;padding:2px 2px 2px 2px;cursor:hand;display:block;font-size:8pt;font-weight:bold;font-family:Arial, Helvetica, sans-serif;}");
|
||||
document.write("a.ecmproducts_l:link, a.ecmproducts_l:visited{text-align:left;background:#f7f7f7 url("+loc+"ecmproducts_l.png) no-repeat right;color:#000000;text-decoration:none;border-color:#adc6d6;border-style:solid;border-width:"+bd+"px "+bd+"px "+bd+"px "+bd+"px;padding:2px 2px 2px 2px;cursor:hand;display:block;font-size:8pt;font-weight:bold;font-family:Arial, Helvetica, sans-serif;}");
|
||||
document.write("a.ecmproducts_l:hover, a.ecmproducts_l:active{background:#adc6d6 url("+loc+"ecmproducts_l2.png) no-repeat right;color: #ffffff;text-decoration:none;border-color:#adc6d6;border-style:solid;border-width:"+bd+"px "+bd+"px "+bd+"px "+bd+"px;padding:2px 2px 2px 2px;cursor:hand;display:block;font-size:8pt;font-weight:bold;font-family:Arial, Helvetica, sans-serif;}");
|
||||
document.write("\n-->\n");
|
||||
document.write("</style>");
|
||||
|
||||
var fc=0x000000;
|
||||
var bc=0xadc6d6;
|
||||
if(typeof(frames)=="undefined"){var frames=0;}
|
||||
|
||||
startMainMenu("",0,0,2,0,0)
|
||||
mainMenuItem("ecmproducts_b1",".png",23,117,loc+"../../../index.php?module=EcmProducts&action=index","","Products",2,2,"ecmproducts_plain");
|
||||
mainMenuItem("ecmproducts_b2",".png",23,117,loc+"../../../index.php?module=EcmVendors&action=index","","Vendors",2,2,"ecmproducts_plain");
|
||||
mainMenuItem("ecmproducts_b3",".png",23,117,loc+"../../../index.php?module=EcmPriceBooks&action=index","","Price Books",2,2,"ecmproducts_plain");
|
||||
mainMenuItem("ecmproducts_b4",".png",23,117,loc+"../../../index.php?module=EcmProductCategorys&action=index","","Product Category",2,2,"ecmproducts_plain");
|
||||
mainMenuItem("ecmproducts_b5",".png",23,117,loc+"../../../index.php?module=EcmProductExchangeRates&action=index","","Exchange Rate",2,2,"ecmproducts_plain");
|
||||
mainMenuItem("ecmproducts_b6",".png",23,117,"javascript:;","","Additional Information",2,2,"ecmproducts_plain");
|
||||
endMainMenu("",0,0);
|
||||
|
||||
startSubmenu("ecmproducts_b6_7","ecmproducts_menu",44);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmGlAccounts&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmGlAccounts&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b6_7");
|
||||
|
||||
startSubmenu("ecmproducts_b6_6","ecmproducts_menu",44);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProductUsageUnits&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProductUsageUnits&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b6_6");
|
||||
|
||||
startSubmenu("ecmproducts_b6_5","ecmproducts_menu",44);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProductPackingTypes&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProductPackingTypes&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b6_5");
|
||||
|
||||
startSubmenu("ecmproducts_b6_4","ecmproducts_menu",44);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProductBasiss&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProductBasis&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b6_4");
|
||||
|
||||
startSubmenu("ecmproducts_b6_3","ecmproducts_menu",44);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProductLines&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProductLines&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b6_3");
|
||||
|
||||
startSubmenu("ecmproducts_b6_2","ecmproducts_menu",44);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProductTaxs&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProductTaxs&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b6_2");
|
||||
|
||||
startSubmenu("ecmproducts_b6_1","ecmproducts_menu",44);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProductManufacturers&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProductManufacturers&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b6_1");
|
||||
|
||||
startSubmenu("ecmproducts_b6","ecmproducts_menu",117);
|
||||
mainMenuItem("ecmproducts_b6_1","Manufacturers",0,0,loc+"../../../index.php?module=EcmProductManufacturers&action=index","","",1,1,"ecmproducts_l");
|
||||
mainMenuItem("ecmproducts_b6_2","Tax Rate",0,0,loc+"../../../index.php?module=EcmProductTaxs&action=index","","",1,1,"ecmproducts_l");
|
||||
mainMenuItem("ecmproducts_b6_3","Product Lines",0,0,loc+"../../../index.php?module=EcmProductLines&action=index","","",1,1,"ecmproducts_l");
|
||||
mainMenuItem("ecmproducts_b6_4","FOB Basis",0,0,loc+"../../../index.php?module=EcmProductBasis&action=index","","",1,1,"ecmproducts_l");
|
||||
mainMenuItem("ecmproducts_b6_5","Packing Type",0,0,loc+"../../../index.php?module=EcmProductPackingTypes&action=index","","",1,1,"ecmproducts_l");
|
||||
mainMenuItem("ecmproducts_b6_6","Usage Unit",0,0,loc+"../../../index.php?module=EcmProductUsageUnits&action=index","","",1,1,"ecmproducts_l");
|
||||
mainMenuItem("ecmproducts_b6_7","GL Accounts",0,0,loc+"../../../index.php?module=EcmGlAccounts&action=index","","",1,1,"ecmproducts_l");
|
||||
endSubmenu("ecmproducts_b6");
|
||||
|
||||
startSubmenu("ecmproducts_b5","ecmproducts_menu",117);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProductExchangeRates&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProductExchangeRates&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b5");
|
||||
|
||||
startSubmenu("ecmproducts_b4","ecmproducts_menu",117);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProductCategorys&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProductCategorys&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b4");
|
||||
|
||||
startSubmenu("ecmproducts_b3","ecmproducts_menu",117);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProducts&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProducts&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b3");
|
||||
|
||||
startSubmenu("ecmproducts_b2","ecmproducts_menu",117);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmVendors&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmVendors&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b2");
|
||||
|
||||
startSubmenu("ecmproducts_b1","ecmproducts_menu",117);
|
||||
submenuItem("Create",loc+"../../../index.php?module=EcmProducts&action=EditView","","ecmproducts_plain");
|
||||
submenuItem("List",loc+"../../../index.php?module=EcmProducts&action=index","","ecmproducts_plain");
|
||||
endSubmenu("ecmproducts_b1");
|
||||
|
||||
loc="";
|
||||
1
modules/EcmProducts/Menu/xaramenu.js
Executable file
1
modules/EcmProducts/Menu/xaramenu.js
Executable file
File diff suppressed because one or more lines are too long
172
modules/EcmProducts/Prices.js
Executable file
172
modules/EcmProducts/Prices.js
Executable file
@@ -0,0 +1,172 @@
|
||||
//categories
|
||||
function saveItems4(){
|
||||
document.getElementById('position_list4').value = ItemsList4(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 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 ItemListSave4;
|
||||
var ItemListClear4;
|
||||
var ItemListFil4;
|
||||
var FillText;
|
||||
|
||||
addEvent(
|
||||
window,
|
||||
'load',
|
||||
function() {
|
||||
var paramsTable4 = new paramsMT('itemsTable4');
|
||||
paramsTable4.onCreateRow = function(row) {
|
||||
row.newPos = false;
|
||||
row.noAddNew = true;
|
||||
row.ondblclick = function() {}
|
||||
row.onSelect = function() {
|
||||
}
|
||||
row.onDeselect = function() {
|
||||
}
|
||||
}
|
||||
|
||||
refreshPositionIndex = function() {
|
||||
for(var i=0; i<paramsTable4.rowCount(); i++) {
|
||||
var data = paramsTable4.row(i).getData();
|
||||
data.position = i+1;
|
||||
paramsTable4.row(i).setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
paramsTable4.onCreateCell = function(cell) {
|
||||
|
||||
var i = cell.index;
|
||||
if(i == 0) {
|
||||
|
||||
cell.setData = function(data) {
|
||||
if(data.pricebook_name) {
|
||||
cell.firstChild.value = data.pricebook_name;
|
||||
|
||||
cell.getElementsByTagName('input')[1].value = data.pricebook_id;
|
||||
}
|
||||
};
|
||||
cell.getData = function(data) {
|
||||
data.ecmpricebook_name = cell.firstChild.value;
|
||||
data.ecmpricebook_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.getData = function(data) {
|
||||
var cn = this.getElementsByTagName('input');
|
||||
data.price = UnformatNumber(cn[0].value);
|
||||
}
|
||||
cell.setData = function(data) {
|
||||
var cn = this.getElementsByTagName('input');
|
||||
console.log(data.price);
|
||||
console.log(FormatNumber(data.price));
|
||||
cn[0].value = FormatNumber(data.price);
|
||||
}
|
||||
cell.onDeselect = function() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
var edit = document.createElement('input');
|
||||
edit.setAttribute('type','text');
|
||||
edit.setAttribute('style','text-align:right;');
|
||||
edit.setAttribute('tabIndex',1);
|
||||
edit.setAttribute('onChange','$(this).val(FormatNumber($(this).val(),2));');
|
||||
edit.className = 'inputs';
|
||||
cell.appendChild(edit);
|
||||
}
|
||||
if(i == 2) {
|
||||
cell.getData = function(data) {
|
||||
var cn = this.getElementsByTagName('input');
|
||||
data.currency = cn[0].value;
|
||||
}
|
||||
cell.setData = function(data) {
|
||||
var cn = this.getElementsByTagName('input');
|
||||
cn[0].value = data.currency;
|
||||
}
|
||||
cell.onDeselect = function() {
|
||||
ERROR = false;
|
||||
var data = new Object();
|
||||
this.getData(data);
|
||||
if(!ERROR) {
|
||||
data.currency = data.currency;
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
var edit = document.createElement('input');
|
||||
edit.setAttribute('type','text');
|
||||
edit.setAttribute('tabIndex',1);
|
||||
edit.className = 'inputs';
|
||||
cell.appendChild(edit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ItemsList4 = function(json) {
|
||||
var data = '';
|
||||
for(var i=0; i<paramsTable4.rowCount(); i++) {
|
||||
console.log(paramsTable4.row(i).getData());
|
||||
data = data + '||||' + JSON.stringifyNoSecurity(paramsTable4.row(i).getData());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
//if(paramsTable4.rowCount() == 0) {paramsTable4.addRow();};
|
||||
paramsTable4.onSetCellData = function(row,cell,data) {
|
||||
if(cell.innerHTML == '') cell.innerHTML = ' ';
|
||||
}
|
||||
|
||||
ItemListFill4 = function() {
|
||||
var pl;
|
||||
pl = document.getElementById('position_list4').value;
|
||||
if(pl && pl != '') {
|
||||
try {
|
||||
pl = eval(pl);
|
||||
for(x in pl) { var pl_row = pl[x];if (pl_row.pricebook_name=='') continue; paramsTable4.addRow().setData(pl_row); }
|
||||
} catch(err) { pl = null; };
|
||||
}
|
||||
}
|
||||
|
||||
ItemListClear4 = function(noNew,save) {
|
||||
if(typeof(save)=="string") ItemListSave4(null,save);
|
||||
while(paramsTable4.rowCount()>0) paramsTable4.row(0).deleteRow(noNew);
|
||||
}
|
||||
|
||||
ItemListClear4();
|
||||
ItemListFill4();
|
||||
}
|
||||
);
|
||||
242
modules/EcmProducts/helper.js
Executable file
242
modules/EcmProducts/helper.js
Executable file
@@ -0,0 +1,242 @@
|
||||
function insert_selected(U){
|
||||
//alert(parent.opener.document.PositionList);
|
||||
var arr=new Array();
|
||||
var ajs=new Array();
|
||||
var lv=document.getElementById('list_view');
|
||||
var is=lv.getElementsByTagName('input');
|
||||
var l=0;
|
||||
var id;
|
||||
for(var i=0;i<is.length;i++) {
|
||||
if(is[i].type=='checkbox' && is[i].name=='mass[]' && is[i].checked==true) {
|
||||
arr[l]=is[i].value;
|
||||
|
||||
id=associated_javascript_data[is[i].value];
|
||||
ajs[l]=associated_javascript_data[is[i].value];
|
||||
ajs[l].code=id['CODE'];
|
||||
ajs[l].name=id['NAME'];
|
||||
ajs[l].price=id['SELLING_PRICE'];
|
||||
ajs[l].unit_id=id['UNIT_ID'];
|
||||
|
||||
ajs[l].vat_value=23;
|
||||
ajs[l].ecmvat_value=23;
|
||||
ajs[l].vat_name='23%';
|
||||
ajs[l].ecmvat_name='23%';
|
||||
ajs[l].vat_id='28079566-b825-e38f-9993-4ccc7b781de5';
|
||||
ajs[l].ecmvat_id='28079566-b825-e38f-9993-4ccc7b781de5';
|
||||
|
||||
ajs[l].total=id['SELLING_PRICE'];
|
||||
ajs[l].id=is[i].value;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
var pl = ajs;
|
||||
if(pl && pl != '') {
|
||||
pl = eval(pl);
|
||||
for(x in pl) {
|
||||
var pl_row = pl[x];
|
||||
// if(pl_row.vat_id)
|
||||
U.addRow().setData(pl_row);
|
||||
}
|
||||
}
|
||||
|
||||
if(U.rowCount() == 0) U.addRow();
|
||||
|
||||
window.close();
|
||||
}
|
||||
function showdescription(id,title,desc,minus,object)
|
||||
{
|
||||
if(!minus)minus=0;
|
||||
var sum=17-minus;
|
||||
document.getElementById("desc").style.display="inline";
|
||||
document.getElementById("desc-title").innerHTML=title;
|
||||
document.getElementById("desc-desc").innerHTML=desc;
|
||||
posy=findPosY(object)+sum;
|
||||
posx=findPosX(object);
|
||||
moveDiv(document.getElementById("desc"),posy,posx);
|
||||
}
|
||||
function hidedescription()
|
||||
{
|
||||
document.getElementById("desc").style.display="none";
|
||||
}
|
||||
function mintajaxget(url,tag)
|
||||
{
|
||||
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : url,
|
||||
dataType : "html",
|
||||
async : false,
|
||||
success : function(data) {
|
||||
|
||||
$('#'+tag).html(data);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
function mintajaxpost(url,tag,form)
|
||||
{
|
||||
var req=mint.Request();
|
||||
req.OnSuccess=function(){$(tag).innerHTML=this.responseText;}
|
||||
req.OnLoading=function(){$(tag).innerHTML='<img src="themes/default/images/loading.gif" border="0">';}
|
||||
req.SendForm(form);
|
||||
}
|
||||
function moveDiv(obj, mvTop, mvLeft) {
|
||||
obj.style.position = "absolute";
|
||||
obj.style.top = mvTop;
|
||||
obj.style.left = mvLeft;
|
||||
}
|
||||
function getPos(inputElement) {
|
||||
var coords = new Object();
|
||||
coords.x = 0;
|
||||
coords.y = 0;
|
||||
try {
|
||||
targetElement = inputElement;
|
||||
if(targetElement.x && targetElement.y) {
|
||||
coords.x = targetElement.x;
|
||||
coords.y = targetElement.y;
|
||||
} else {
|
||||
if(targetElement.offsetParent) {
|
||||
coords.x += targetElement.offsetLeft;
|
||||
coords.y += targetElement.offsetTop;
|
||||
while(targetElement = targetElement.offsetParent) {
|
||||
coords.x += targetElement.offsetLeft;
|
||||
coords.y += targetElement.offsetTop;
|
||||
}
|
||||
} else {
|
||||
//alert("Could not find any reference for coordinate positioning.");
|
||||
}
|
||||
}
|
||||
return coords;
|
||||
} catch(error) {
|
||||
//alert(error.msg);
|
||||
return coords;
|
||||
}
|
||||
}
|
||||
|
||||
function findPosX(obj)
|
||||
{
|
||||
var curleft = 0;
|
||||
if(obj.offsetParent)
|
||||
while(1)
|
||||
{
|
||||
curleft += obj.offsetLeft;
|
||||
if(!obj.offsetParent)
|
||||
break;
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
else if(obj.x)
|
||||
curleft += obj.x;
|
||||
return curleft;
|
||||
//return getPos(obj).x;
|
||||
}
|
||||
|
||||
function findPosY(obj)
|
||||
{
|
||||
var curtop = 0;
|
||||
if(obj.offsetParent)
|
||||
while(1)
|
||||
{
|
||||
curtop += obj.offsetTop;
|
||||
if(!obj.offsetParent)
|
||||
break;
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
else if(obj.y)
|
||||
curtop += obj.y;
|
||||
return curtop;
|
||||
//return getPos(obj).y;
|
||||
}
|
||||
function showdiv(id,div,minusy,minusx)
|
||||
{
|
||||
document.getElementById(div).style.display="inline";
|
||||
posy=findPosY(document.getElementById(id))-minusy;
|
||||
posx=findPosX(document.getElementById(id))-minusx;
|
||||
moveDiv(document.getElementById(div),posy,posx);
|
||||
}
|
||||
|
||||
function hidediv(div)
|
||||
{
|
||||
document.getElementById(div).style.display="none";
|
||||
}
|
||||
function showprice(id,price,purchase_price,margin,remarks_pl,remarks_en,remarks_de,order_by,sorder,recipient_code)
|
||||
{
|
||||
document.getElementById('price').value=price;
|
||||
document.getElementById('purchase_price').value=purchase_price;
|
||||
document.getElementById('margin').value=margin;
|
||||
document.getElementById('recipient_code').value=recipient_code;
|
||||
document.getElementById('remarks_pl').value=remarks_pl;
|
||||
document.getElementById('remarks_en').value=remarks_en;
|
||||
document.getElementById('remarks_de').value=remarks_de;
|
||||
document.getElementById('product_id').value=id;
|
||||
document.getElementById('order_by').value=order_by;
|
||||
document.getElementById('sorder').value=sorder;
|
||||
document.getElementById('price-block').style.display="block";
|
||||
}
|
||||
function getPrice(id,type)
|
||||
{
|
||||
var purchase_price=document.getElementById('purchase_price_'+id).value;
|
||||
var margin_rate=document.getElementById('margin_rate_'+id).value;
|
||||
var list_price;
|
||||
|
||||
list_price=parseFloat(purchase_price)/(1-parseFloat(margin_rate)/100);
|
||||
|
||||
if(!isNaN(list_price))document.getElementById('list_price_'+id).value=roundNumber(list_price,2);
|
||||
|
||||
}
|
||||
function getPricePricebook()
|
||||
{
|
||||
var purchase_price=document.getElementById('purchase_price').value;
|
||||
var margin_rate=document.getElementById('margin').value;
|
||||
var list_price;
|
||||
margin_rate=margin_rate.replace(".","");
|
||||
margin_rate=margin_rate.replace(",",".");
|
||||
purchase_price=purchase_price.replace(".","");
|
||||
purchase_price=purchase_price.replace(",",".");
|
||||
list_price=parseFloat(purchase_price)/(1-parseFloat(margin_rate)/100);
|
||||
|
||||
if(!isNaN(list_price))document.getElementById('price').value=CurrencyFormatted(list_price);
|
||||
|
||||
}
|
||||
function CurrencyFormatted(amount)
|
||||
{
|
||||
var i = parseFloat(amount);
|
||||
if(isNaN(i)) { i = 0.00; }
|
||||
var minus = '';
|
||||
if(i < 0) { minus = '-'; }
|
||||
i = Math.abs(i);
|
||||
i = parseInt((i + .005) * 100);
|
||||
i = i / 100;
|
||||
s = new String(i);
|
||||
if(s.indexOf('.') < 0) { s += ',00'; }
|
||||
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
|
||||
s = minus + s;
|
||||
s=s.replace(".",",");
|
||||
return s;
|
||||
}
|
||||
function roundN(rnum,rlength)
|
||||
{
|
||||
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
|
||||
return newnumber;
|
||||
}
|
||||
function roundNumber(num, dec)
|
||||
{
|
||||
if(!isNaN(num))return CurrencyFormatted(roundN(parseFloat(num),dec));
|
||||
else return "";
|
||||
}
|
||||
function ShowHideBlock(id)
|
||||
{
|
||||
if(document.getElementById(id).style.display=="block")
|
||||
{
|
||||
document.getElementById(id).style.display="none"
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById(id).style.display="block"
|
||||
}
|
||||
}
|
||||
|
||||
function generateEAN() {
|
||||
alert('Coming soon! :)');
|
||||
}
|
||||
501
modules/EcmProducts/javascript/DetailViewDocumentReady.js
Executable file
501
modules/EcmProducts/javascript/DetailViewDocumentReady.js
Executable file
@@ -0,0 +1,501 @@
|
||||
$(document).ready(function () {
|
||||
InitializeTableCost();
|
||||
InitializeTableComponents();
|
||||
});
|
||||
|
||||
function trigerDocumentsPZ($this){
|
||||
$this = $($this);
|
||||
$this.closest('tr').next().find('div').toggle(400);
|
||||
}
|
||||
function trigerStockOperations($this){
|
||||
$this = $($this);
|
||||
$this.closest('tr').next().next().find('div').toggle(400);
|
||||
}
|
||||
function InitializeTableCost() {
|
||||
// Initialize appendGrid
|
||||
$('#tableTimeEdit').appendGrid({
|
||||
hideRowNumColumn: false,
|
||||
initRows: 1,
|
||||
initData: $.parseJSON($("input[name='action_list']").val()),
|
||||
columns: [
|
||||
{
|
||||
name: 'indeks',
|
||||
display: 'Indeks',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {
|
||||
'width': '80px',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black',
|
||||
}
|
||||
}, {
|
||||
name: 'name',
|
||||
display: 'Nazwa',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black',
|
||||
}
|
||||
}, {
|
||||
name: 'category',
|
||||
display: 'Kategoria',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {
|
||||
'width': '20%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black',
|
||||
},
|
||||
}, {
|
||||
name: 'unit_id',
|
||||
display: SUGAR.language.get("app_strings", "LBL_JM"),
|
||||
type: 'custom',
|
||||
displayCss: {
|
||||
'width': '5%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
customBuilder: function (parent, idPrefix, name, uniqueIndex) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
var ctrl = document.createElement('span');
|
||||
$(ctrl).attr({id: ctrlId, name: ctrlId}).appendTo(parent);
|
||||
$(parent).css({'text-align': 'right'});
|
||||
},
|
||||
customSetter: function (idPrefix, name, uniqueIndex, value) {
|
||||
var tmp = SUGAR.language.get("app_list_strings", "ecmproducts_unit_dom");
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
$('#' + ctrlId).html(tmp[value]);
|
||||
},
|
||||
customGetter: function (idPrefix, name, uniqueIndex) {
|
||||
return '';
|
||||
},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
}, {
|
||||
name: 'quantity',
|
||||
display: 'Ilość',
|
||||
type: 'text',
|
||||
ctrlCss: {'text-align': 'right'},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black',
|
||||
},
|
||||
}, {
|
||||
name: 'price',
|
||||
display: 'Koszt',
|
||||
type: 'custom',
|
||||
ctrlCss: {'text-align': 'right'},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black',
|
||||
},
|
||||
customBuilder: function (parent, idPrefix, name, uniqueIndex) {
|
||||
// Tworzenie Id dla inputow
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
//kontener
|
||||
var ctrl = document.createElement('span');
|
||||
//dodajemy kontener do komorki w tabeli
|
||||
$(ctrl).attr({id: ctrlId, name: ctrlId}).appendTo(parent);
|
||||
//Tworzymy pierwszy input dla ceny jednostkowej
|
||||
var Single = $('<input/>', {type: 'text', id: ctrlId + '_Single', name: ctrlId + '_Single', class: 'inputs', readonly: 'readonly'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Single).val('0,00');
|
||||
//dodajemy do kontenera
|
||||
$(Single).appendTo(ctrl);
|
||||
//oddzielamy widoczna linia
|
||||
var hr = document.createElement('hr');
|
||||
$(hr).css('margin', '0em').appendTo(ctrl);
|
||||
//Tworzymy drugi input dla sumy
|
||||
var Summary = $('<input/>', {type: 'text', id: ctrlId + '_Summary', name: ctrlId + '_Summary', class: 'inputs', readonly: 'readonly'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Summary).val('0,00');
|
||||
$(Summary).appendTo(ctrl);
|
||||
return ctrl;
|
||||
},
|
||||
customGetter: function (idPrefix, name, uniqueIndex) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
var Single = $('#' + ctrlId + '_Single').val();
|
||||
var Summary = $('#' + ctrlId + '_Summary').val();
|
||||
return {Single: Single, Summary: Summary};
|
||||
},
|
||||
customSetter: function (idPrefix, name, uniqueIndex, value) {
|
||||
if (value != null) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
$('#' + ctrlId + '_Single').val(value['Single'] == null ? '0,00' : FormatNumber(value['Single']));
|
||||
$('#' + ctrlId + '_Summary').val(value['Summary'] == null ? '0,00' : FormatNumber(value['Summary'],6));
|
||||
}
|
||||
},
|
||||
}, ],
|
||||
i18n: {
|
||||
rowEmpty: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWEMPTY"),
|
||||
},
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
append: true,
|
||||
insert: true,
|
||||
remove: true,
|
||||
moveUp: true,
|
||||
moveDown: true
|
||||
}
|
||||
});
|
||||
$('#tableTimeEdit_price_td_head').html('Cena<br>Wartość');
|
||||
var count = $('#tableTimeEdit').appendGrid('getRowCount');
|
||||
for (var i = 0; i < count; i++) {
|
||||
var value = $('#tableTimeEdit').appendGrid('getCtrlValue', 'quantity', i);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', i, FormatNumber(value,6));
|
||||
}
|
||||
//Podsumowanie
|
||||
var data = $('#tableTimeEdit').appendGrid('getAllValue');
|
||||
var sumPriceSingle = 0;
|
||||
var sumPriceTotal = 0;
|
||||
$.each(data, function (index, value) {
|
||||
sumPriceTotal += parseFloat(UnformatNumber(value.price.Summary,6));
|
||||
});
|
||||
$('#tableTimeEdit').find('tfoot tr:last').after('<tr><td colspan="6" style="vertical-align: middle;border-top: 1px solid black">Suma:</td><td style="text-align: right;border-top: 1px solid black">' + FormatNumber(sumPriceTotal,6) + '</td></tr>');
|
||||
}
|
||||
|
||||
function InitializeTableComponents() {
|
||||
// Initialize appendGrid
|
||||
$('#tableComponents').appendGrid({
|
||||
hideRowNumColumn: false,
|
||||
initRows: 1,
|
||||
initData: $.parseJSON($("input[name='component_list']").val()),
|
||||
columns: [
|
||||
{
|
||||
name: 'code',
|
||||
display: SUGAR.language.get("app_strings", "LBL_INDEX"),
|
||||
type: 'text',
|
||||
displayCss: {
|
||||
'width': '150px',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
ctrlClass: 'inputs'
|
||||
}, {
|
||||
name: 'name',
|
||||
display: SUGAR.language.get("app_strings", "LBL_NAME"),
|
||||
type: 'text',
|
||||
displayCss: {
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
ctrlClass: 'inputs',
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
}, {
|
||||
name: 'product_category_name',
|
||||
display: SUGAR.language.get("app_strings", "LBL_CATEGORY"),
|
||||
type: 'text',
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
ctrlAttr: {
|
||||
readonly: 'readonly'
|
||||
},
|
||||
}, {
|
||||
name: 'unit_id',
|
||||
display: SUGAR.language.get("app_strings", "LBL_JM"),
|
||||
type: 'custom',
|
||||
displayCss: {
|
||||
'width': '3%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
customBuilder: function (parent, idPrefix, name, uniqueIndex) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
var ctrl = document.createElement('span');
|
||||
$(ctrl).attr({id: ctrlId, name: ctrlId}).appendTo(parent);
|
||||
$(parent).css({'text-align': 'right'});
|
||||
},
|
||||
customSetter: function (idPrefix, name, uniqueIndex, value) {
|
||||
var tmp = SUGAR.language.get("app_list_strings", "ecmproducts_unit_dom");
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
$('#' + ctrlId).html(tmp[value]);
|
||||
},
|
||||
customGetter: function (idPrefix, name, uniqueIndex) {
|
||||
return '';
|
||||
},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
}, {
|
||||
name: 'quantity_recipe',
|
||||
display: SUGAR.language.get("app_strings", "LBL_QUANTITY_RECIPE"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0.00000000',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
}, {
|
||||
name: 'divider',
|
||||
display: SUGAR.language.get("app_strings", "LBL_DIVIDER"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0,00',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
}, {
|
||||
name: 'quantity',
|
||||
display: SUGAR.language.get("app_strings", "LBL_QUANTITY"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0.000000',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
}, {
|
||||
name: 'price',
|
||||
display: 'Cena / Wartość',
|
||||
type: 'custom',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle',
|
||||
'text-align': 'center',
|
||||
'background-color': 'rgb(224,240,255)',
|
||||
'border': '1px solid rgb(48,192,255)',
|
||||
'height': '0px',
|
||||
'font-family': 'Arial',
|
||||
'font-size': '12px',
|
||||
'color': 'black'
|
||||
},
|
||||
customBuilder: function (parent, idPrefix, name, uniqueIndex) {
|
||||
// Tworzenie Id dla inputow
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
//kontener
|
||||
var ctrl = document.createElement('span');
|
||||
//dodajemy kontener do komorki w tabeli
|
||||
$(ctrl).attr({id: ctrlId, name: ctrlId}).appendTo(parent);
|
||||
//Tworzymy pierwszy input dla ceny jednostkowej
|
||||
var Single = $('<input/>', {type: 'text', id: ctrlId + '_Single', name: ctrlId + '_Single', class: 'inputs', readonly: 'readonly'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Single).val('0,00');
|
||||
|
||||
//dodajemy do kontenera
|
||||
$(Single).appendTo(ctrl);
|
||||
//oddzielamy widoczna linia
|
||||
var hr = document.createElement('hr');
|
||||
$(hr).css('margin', '0em').appendTo(ctrl);
|
||||
//Tworzymy drugi input dla sumy
|
||||
var Summary = $('<input/>', {type: 'text', id: ctrlId + '_Summary', name: ctrlId + '_Summary', class: 'inputs', readonly: 'readonly'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Summary).val('0,00');
|
||||
$(Summary).appendTo(ctrl);
|
||||
return ctrl;
|
||||
},
|
||||
customGetter: function (idPrefix, name, uniqueIndex) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
var Single = $('#' + ctrlId + '_Single').val();
|
||||
var Summary = $('#' + ctrlId + '_Summary').val();
|
||||
return {Single: Single, Summary: Summary};
|
||||
},
|
||||
customSetter: function (idPrefix, name, uniqueIndex, value) {
|
||||
if (value != null) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
$('#' + ctrlId + '_Single').val(value['Single'] == null ? '0,00' : FormatNumber(value['Single']));
|
||||
$('#' + ctrlId + '_Summary').val(value['Summary'] == null ? '0,00' : FormatNumber(value['Summary'],6));
|
||||
}
|
||||
},
|
||||
}, {
|
||||
name: 'ecmcomponent_id',
|
||||
display: 'ecmcomponent_id',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'product_category_id',
|
||||
display: 'product_category_id',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
},
|
||||
],
|
||||
i18n: {
|
||||
append: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_APPEND"),
|
||||
remove: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVE"),
|
||||
insert: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_INSERT"),
|
||||
moveUp: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEUP"),
|
||||
moveDown: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEDOWN"),
|
||||
removeLast: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVELAST"),
|
||||
rowEmpty: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWEMPTY"),
|
||||
rowDrag: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWDRAG"),
|
||||
},
|
||||
customGridButtons: {
|
||||
insert: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/add_position.gif';
|
||||
return button;
|
||||
},
|
||||
remove: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/deleterow.gif';
|
||||
return button;
|
||||
},
|
||||
moveUp: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowup.gif';
|
||||
return button;
|
||||
},
|
||||
moveDown: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowdown.gif';
|
||||
return button;
|
||||
},
|
||||
},
|
||||
afterRowRemoved: function (caller, rowIndex) {
|
||||
var quantity = $('#tableComponents').appendGrid(
|
||||
'getRowCount');
|
||||
if (quantity == 0) {
|
||||
$('#tableComponents').appendGrid('appendRow', 1);
|
||||
}
|
||||
},
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
append: true,
|
||||
insert: true,
|
||||
remove: true,
|
||||
moveUp: true,
|
||||
moveDown: true
|
||||
}
|
||||
});
|
||||
$('#tableComponents_price_td_head').html('Cena<br>Wartość');
|
||||
var count = $('#tableComponents').appendGrid('getRowCount');
|
||||
for (var i = 0; i < count; i++) {
|
||||
var value = $('#tableComponents').appendGrid('getCtrlValue', 'quantity', i);
|
||||
var divider = $('#tableComponents').appendGrid('getCtrlValue', 'divider', i);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', i, QuantityFormat(value,6));
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'divider', i, FormatNumber(divider,2));
|
||||
}
|
||||
//Podsumowanie
|
||||
var html = '<tr><td colspan="8" style="vertical-align: middle;border-top: 1px solid black">Suma:</td><td style="text-align: right;border-top: 1px solid black"><span id="sumComponentsPriceTotal">0,00</span></td></tr>';
|
||||
$('#tableComponents').find('tfoot tr:last').after(html);
|
||||
updateSumComponents();
|
||||
}
|
||||
function updateSumComponents() {
|
||||
var data = $('#tableComponents').appendGrid('getAllValue');
|
||||
var sumPriceSingle = 0;
|
||||
var sumPriceTotal = 0;
|
||||
$.each(data, function (index, value) {
|
||||
|
||||
sumPriceTotal += parseFloat(UnformatNumber(value.price.Summary,6));
|
||||
});
|
||||
$('#sumComponentsPriceTotal').html(FormatNumber(sumPriceTotal,6));
|
||||
}
|
||||
1438
modules/EcmProducts/javascript/EcmProduct.js
Executable file
1438
modules/EcmProducts/javascript/EcmProduct.js
Executable file
File diff suppressed because it is too large
Load Diff
1478
modules/EcmProducts/javascript/EcmProductDetailView.js
Executable file
1478
modules/EcmProducts/javascript/EcmProductDetailView.js
Executable file
File diff suppressed because it is too large
Load Diff
1429
modules/EcmProducts/javascript/EcmProductQuickCreate.js
Executable file
1429
modules/EcmProducts/javascript/EcmProductQuickCreate.js
Executable file
File diff suppressed because it is too large
Load Diff
888
modules/EcmProducts/javascript/EditViewDocumentReady44.js
Executable file
888
modules/EcmProducts/javascript/EditViewDocumentReady44.js
Executable file
@@ -0,0 +1,888 @@
|
||||
$(document).ready(function () {
|
||||
InitializeTableCost();
|
||||
if ($('#tableTimeEdit').appendGrid('getRowCount') === 0) {
|
||||
$('#tableTimeEdit').appendGrid('appendRow', 1);
|
||||
}
|
||||
InitializeTableComponents();
|
||||
if ($('#tableComponents').appendGrid('getRowCount') === 0) {
|
||||
$('#tableComponents').appendGrid('appendRow', 1);
|
||||
}
|
||||
var tmp = $("select[name=select_ecmaction_category]");
|
||||
tmp.append($('<option>', {value: ""})
|
||||
.text(""));
|
||||
tmp.val('');
|
||||
|
||||
$('#srp_price').on('click',function(){
|
||||
$('#srp_price').select();
|
||||
});
|
||||
|
||||
$('#srp_price').on('change',function(){
|
||||
$('#srp_price').val(FormatNumber($('#srp_price').val(),2));
|
||||
|
||||
srp_price_replace
|
||||
|
||||
var r = confirm("Czy podmienić cenę w komponentach?");
|
||||
if (r == true) {
|
||||
$('#srp_price_replace').val(1);
|
||||
} else {
|
||||
$('#srp_price_replace').val(0);
|
||||
}
|
||||
});
|
||||
|
||||
$('#price_msh').on('click',function(){
|
||||
$('#price_msh').select();
|
||||
});
|
||||
|
||||
$('#price_msh').on('change',function(){
|
||||
$('#price_msh').val(FormatNumber($('#price_msh').val(),2));
|
||||
});
|
||||
|
||||
|
||||
$('#cena_produkcyjna').on('click',function(){
|
||||
$('#cena_produkcyjna').select();
|
||||
});
|
||||
|
||||
$('#cena_produkcyjna').on('change',function(){
|
||||
$('#cena_produkcyjna').val(FormatNumber($('#cena_produkcyjna').val(),2));
|
||||
});
|
||||
// rozszerzenie kolumn do maksa
|
||||
var trki = $("#LBL_TIME_TABLE").children('table').children('tbody').children('tr');
|
||||
$.each(trki, function (index, value) {
|
||||
if (index == 1) {
|
||||
var tmp = $(value).children('td').attr('colspan');
|
||||
$(value).children('td').attr('colspan', (tmp + 1));
|
||||
}
|
||||
});
|
||||
var trki = $("#LBL_COMPONENTS").children('table').children('tbody').children('tr');
|
||||
$.each(trki, function (index, value) {
|
||||
if (index == 1) {
|
||||
var tmp = $(value).children('td').attr('colspan');
|
||||
$(value).children('td').attr('colspan', (tmp + 1));
|
||||
}
|
||||
});
|
||||
});
|
||||
$["ui"]["autocomplete"].prototype["_renderItem"] = function (ul, item) {
|
||||
return $("<li></li>").data("item.autocomplete", item).append(
|
||||
$("<a></a>").html(item.label)).appendTo(ul);
|
||||
};
|
||||
|
||||
function InitializeTableCost() {
|
||||
// Initialize appendGrid
|
||||
$('#tableTimeEdit').appendGrid({
|
||||
hideRowNumColumn: false,
|
||||
initRows: 1,
|
||||
initData: $.parseJSON($("input[name='action_list']").val()),
|
||||
columns: [
|
||||
{
|
||||
name: 'indeks',
|
||||
display: SUGAR.language.get("app_strings", "LBL_INDEX"),
|
||||
type: 'ui-autocomplete',
|
||||
displayCss: {
|
||||
'width': '80px',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
uiOption: {
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchEcmActionsAutocomplite",
|
||||
term: request.term,
|
||||
source: 'indeks',
|
||||
},
|
||||
success: function (data) {
|
||||
response(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 3,
|
||||
select: function (event, ui) {
|
||||
var uniqueid = $(event.target).attr('id');
|
||||
uniqueid = uniqueid.substring('tableTimeEdit_indeks_'.length);
|
||||
var rowIndex = $('#tableTimeEdit').appendGrid('getRowIndex', uniqueid);
|
||||
if (ui.item.id != '') {
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'name', rowIndex, ui.item.name);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', rowIndex, '1,00');
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'ecmactionid', rowIndex, ui.item.id);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'category', rowIndex, ui.item.category);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'price', rowIndex, ui.item.price);
|
||||
}
|
||||
},
|
||||
},
|
||||
ctrlClass: 'inputs'
|
||||
}, {
|
||||
name: 'name',
|
||||
display: SUGAR.language.get("app_strings", "LBL_NAME"),
|
||||
type: 'ui-autocomplete',
|
||||
displayCss: {
|
||||
// 'width': '40%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
uiOption: {
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchEcmActionsAutocomplite",
|
||||
term: request.term,
|
||||
source: 'name',
|
||||
},
|
||||
success: function (data) {
|
||||
response(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 3,
|
||||
select: function (event, ui) {
|
||||
var uniqueid = $(event.target).attr('id');
|
||||
uniqueid = uniqueid.substring('tableTimeEdit_name_'.length);
|
||||
var rowIndex = $('#tableTimeEdit').appendGrid('getRowIndex', uniqueid);
|
||||
if (ui.item.id != '') {
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'indeks', rowIndex, ui.item.indeks);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', rowIndex, '1,00');
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'ecmactionid', rowIndex, ui.item.id);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'category', rowIndex, ui.item.category);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'price', rowIndex, ui.item.price);
|
||||
}
|
||||
},
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
}, {
|
||||
name: 'category',
|
||||
display: SUGAR.language.get("app_strings", "LBL_CATEGORY"),
|
||||
type: 'text',
|
||||
displayCss: {
|
||||
'width': '15%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
ctrlAttr: {
|
||||
disabled: 'disabled',
|
||||
readonly: 'readonly'
|
||||
},
|
||||
}, {
|
||||
name: 'unit_id',
|
||||
display: SUGAR.language.get("app_strings", "LBL_JM"),
|
||||
type: 'select',
|
||||
ctrlOptions: SUGAR.language.get("app_list_strings", "ecmproducts_unit_dom"),
|
||||
displayCss: {
|
||||
'width': '5%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
}, {
|
||||
name: 'quantity',
|
||||
display: SUGAR.language.get("app_strings", "LBL_QUANTITY"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0,00',
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
onChange: function (evt, rowIndex) {
|
||||
var row = $('#tableTimeEdit').appendGrid('getRowValue', rowIndex);
|
||||
var formatedQuantity = FormatNumber(row.quantity);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', rowIndex, formatedQuantity);
|
||||
var Quantity = UnformatNumber(formatedQuantity);
|
||||
var PriceSingle = UnformatNumber(row.price.Single);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'price', rowIndex, {Single: row.price.Single, Summary: Quantity * PriceSingle});
|
||||
updateSumEcmAction();
|
||||
}
|
||||
}, {
|
||||
name: 'price',
|
||||
display: 'Cena / Wartość',
|
||||
type: 'custom',
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
customBuilder: function (parent, idPrefix, name, uniqueIndex) {
|
||||
// Tworzenie Id dla inputow
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
//kontener
|
||||
var ctrl = document.createElement('span');
|
||||
//dodajemy kontener do komorki w tabeli
|
||||
$(ctrl).attr({id: ctrlId, name: ctrlId}).appendTo(parent);
|
||||
//Tworzymy pierwszy input dla ceny jednostkowej
|
||||
var Single = $('<input/>', {type: 'text', id: ctrlId + '_Single', name: ctrlId + '_Single', class: 'inputs'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Single).val('0,00');
|
||||
//Akacja wywolywana podczas zmiany wartosci oraz formatuje
|
||||
// oblicza (ilosc*cena jednostkowa) i wstawia
|
||||
$(Single).change(function () {
|
||||
var SingleFormated = FormatNumber($(this).val());
|
||||
$(this).val(SingleFormated);
|
||||
var qunatity = UnformatNumber($('#' + idPrefix + '_quantity_' + uniqueIndex).val());
|
||||
$('#' + ctrlId + '_Summary').val(FormatNumber(qunatity * UnformatNumber(SingleFormated)));
|
||||
updateSumEcmAction();
|
||||
});
|
||||
//dodajemy do kontenera
|
||||
$(Single).appendTo(ctrl);
|
||||
//oddzielamy widoczna linia
|
||||
var hr = document.createElement('hr');
|
||||
$(hr).css('margin', '0em').appendTo(ctrl);
|
||||
//Tworzymy drugi input dla sumy
|
||||
var Summary = $('<input/>', {type: 'text', id: ctrlId + '_Summary', name: ctrlId + '_Summary', class: 'inputs'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Summary).val('0,00');
|
||||
//Akacja wywolywana podczas zmiany wartosci oraz formatuje
|
||||
// oblicza (suma / ilosc) i wstawia
|
||||
$(Summary).change(function () {
|
||||
var SummaryFormated = FormatNumber($(this).val());
|
||||
$(this).val(SummaryFormated);
|
||||
var qunatity = UnformatNumber($('#' + idPrefix + '_quantity_' + uniqueIndex).val());
|
||||
$('#' + ctrlId + '_Single').val(FormatNumber(UnformatNumber(SummaryFormated) / qunatity));
|
||||
updateSumEcmAction();
|
||||
});
|
||||
$(Summary).appendTo(ctrl);
|
||||
return ctrl;
|
||||
},
|
||||
customGetter: function (idPrefix, name, uniqueIndex) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
var Single = $('#' + ctrlId + '_Single').val();
|
||||
var Summary = $('#' + ctrlId + '_Summary').val();
|
||||
return {Single: Single, Summary: Summary};
|
||||
},
|
||||
customSetter: function (idPrefix, name, uniqueIndex, value) {
|
||||
if (value != null) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
$('#' + ctrlId + '_Single').val(value['Single'] == null ? '0,00' : FormatNumber(value['Single']));
|
||||
$('#' + ctrlId + '_Summary').val(value['Summary'] == null ? '0,00' : FormatNumber(value['Summary']));
|
||||
}
|
||||
},
|
||||
}, {
|
||||
name: 'ecmactionid',
|
||||
display: 'ecmactionid',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
},
|
||||
],
|
||||
i18n: {
|
||||
append: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_APPEND"),
|
||||
remove: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVE"),
|
||||
insert: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_INSERT"),
|
||||
moveUp: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEUP"),
|
||||
moveDown: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEDOWN"),
|
||||
removeLast: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVELAST"),
|
||||
rowEmpty: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWEMPTY"),
|
||||
rowDrag: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWDRAG"),
|
||||
},
|
||||
customGridButtons: {
|
||||
insert: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/add_position.gif';
|
||||
return button;
|
||||
},
|
||||
remove: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/deleterow.gif';
|
||||
return button;
|
||||
},
|
||||
moveUp: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowup.gif';
|
||||
return button;
|
||||
},
|
||||
moveDown: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowdown.gif';
|
||||
return button;
|
||||
},
|
||||
},
|
||||
afterRowRemoved: function (caller, rowIndex) {
|
||||
var quantity = $('#tableTimeEdit').appendGrid(
|
||||
'getRowCount');
|
||||
if (quantity == 0) {
|
||||
$('#tableTimeEdit').appendGrid('appendRow', 1);
|
||||
}
|
||||
},
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
append: true,
|
||||
moveUp: true,
|
||||
moveDown: true
|
||||
}
|
||||
});
|
||||
$('#tableTimeEdit_price_td_head').html('Cena<br>Wartość');
|
||||
var count = $('#tableTimeEdit').appendGrid('getRowCount');
|
||||
for (var i = 0; i < count; i++) {
|
||||
var value = $('#tableTimeEdit').appendGrid('getCtrlValue', 'quantity', i);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', i, FormatNumber(value));
|
||||
}
|
||||
//Podsumowanie
|
||||
var html = '<tr><td colspan="6" style="vertical-align: middle;border-top: 1px solid black">Suma:</td><td style="text-align: right;border-top: 1px solid black"><span id="sumEcmActionPriceTotal">0,00</span></td></tr>';
|
||||
$('#tableTimeEdit').find('tfoot tr:last').after(html);
|
||||
updateSumEcmAction();
|
||||
}
|
||||
|
||||
function updateSumEcmAction() {
|
||||
var data = $('#tableTimeEdit').appendGrid('getAllValue');
|
||||
var sumPriceSingle = 0;
|
||||
var sumPriceTotal = 0;
|
||||
$.each(data, function (index, value) {
|
||||
sumPriceTotal += parseFloat(UnformatNumber(value.price.Summary));
|
||||
});
|
||||
$('#sumEcmActionPriceTotal').html(FormatNumber(sumPriceTotal));
|
||||
}
|
||||
|
||||
|
||||
function searchActions() {
|
||||
var nazwa = $('#searchEcmActionInput').val();
|
||||
var kategoria = $('select[name=select_ecmaction_category]').find(":selected").val();
|
||||
var wynik = '';
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchActionsList",
|
||||
term: nazwa,
|
||||
category: kategoria,
|
||||
},
|
||||
success: function (data) {
|
||||
wynik = data;
|
||||
}
|
||||
});
|
||||
if (wynik != '') {
|
||||
InitializeSearchtableTable(wynik);
|
||||
$('#ttabble').show();
|
||||
} else {
|
||||
console.log("nie znaleziono wyników");
|
||||
}
|
||||
}
|
||||
|
||||
function InitializeSearchtableTable(data) {
|
||||
// Initialize appendGrid
|
||||
$('#wyszukiwanie').appendGrid({
|
||||
hideRowNumColumn: true,
|
||||
initRows: 0,
|
||||
columns: [
|
||||
{
|
||||
name: 'indeks',
|
||||
display: 'Indeks',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'width': '90px', 'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'name',
|
||||
display: 'Nazwa',
|
||||
//type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'category',
|
||||
display: 'Kategoria',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'width': '130px', 'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'price1',
|
||||
display: 'Koszt',
|
||||
type: 'text',
|
||||
ctrlCss: {'text-align': 'right'},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'width': '70px', 'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'displaytime',
|
||||
display: 'Czas',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'width': '70px', 'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'ecmactionid',
|
||||
display: 'ecmactionid',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'time',
|
||||
display: 'time',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'cost_action',
|
||||
display: 'cost_action',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'cost_hour',
|
||||
display: 'cost_hour',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, ],
|
||||
i18n: {
|
||||
rowEmpty: 'Brak wyników'
|
||||
},
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
append: true,
|
||||
insert: true,
|
||||
remove: true,
|
||||
moveUp: true,
|
||||
moveDown: true
|
||||
},
|
||||
initData: data,
|
||||
});
|
||||
$('thead').removeClass('ui-widget-header');
|
||||
$('td').removeClass('ui-widget-header');
|
||||
$('tbody').removeClass('ui-widget-content');
|
||||
$('td').removeClass('ui-widget-content');
|
||||
$('tfoot').removeClass('ui-widget-header');
|
||||
}
|
||||
|
||||
function dodajDoListy(evt, rowIndex) {
|
||||
var tmp = $('#wyszukiwanie').appendGrid('getRowValue', rowIndex);
|
||||
tmp['price1'] = '0,00';
|
||||
tmp['displaytime'] = '00.00:00';
|
||||
tmp['quantity'] = '0';
|
||||
$('#tableTimeEdit').appendGrid(
|
||||
'insertRow',
|
||||
[{
|
||||
indeks: tmp['indeks'],
|
||||
name: tmp['name'],
|
||||
quantity: '0,00',
|
||||
ecmactionid: tmp['ecmactionid'],
|
||||
category: tmp['category'],
|
||||
cost_action: tmp['cost_action'],
|
||||
cost_hour: tmp['cost_hour'],
|
||||
displaytime: tmp['displaytime'],
|
||||
time: tmp['time'],
|
||||
price1: '0,00'
|
||||
}], 0);
|
||||
$('#ttabble').hide();
|
||||
}
|
||||
|
||||
|
||||
function InitializeTableComponents() {
|
||||
// Initialize appendGrid
|
||||
$('#tableComponents').appendGrid({
|
||||
hideRowNumColumn: false,
|
||||
initRows: 1,
|
||||
initData: $.parseJSON($("input[name='component_list']").val()),
|
||||
columns: [
|
||||
{
|
||||
name: 'code',
|
||||
display: SUGAR.language.get("app_strings", "LBL_INDEX"),
|
||||
type: 'ui-autocomplete',
|
||||
displayCss: {
|
||||
'width': '150px',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
uiOption: {
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchComponentsAutocomplite",
|
||||
term: request.term,
|
||||
source: 'code',
|
||||
},
|
||||
success: function (data) {
|
||||
response(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 3,
|
||||
select: function (event, ui) {
|
||||
var uniqueid = $(event.target).attr('id');
|
||||
uniqueid = uniqueid.substring('tableComponents_code_'.length);
|
||||
var rowIndex = $('#tableComponents').appendGrid('getRowIndex', uniqueid);
|
||||
|
||||
if (ui.item.id != '') {
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'name', rowIndex, ui.item.name);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex, '0.000000');
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'ecmcomponent_id', rowIndex, ui.item.ecmcomponent_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'unit_id', rowIndex, ui.item.unit_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'product_category_id', rowIndex, ui.item.product_category_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'product_category_name', rowIndex, ui.item.product_category_name);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: ui.item.srp_price, Summary: 0.000000});
|
||||
|
||||
}
|
||||
},
|
||||
},
|
||||
ctrlClass: 'inputs'
|
||||
}, {
|
||||
name: 'name',
|
||||
display: SUGAR.language.get("app_strings", "LBL_NAME"),
|
||||
type: 'ui-autocomplete',
|
||||
displayCss: {
|
||||
// 'width': '40%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
uiOption: {
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchComponentsAutocomplite",
|
||||
term: request.term,
|
||||
source: 'name',
|
||||
},
|
||||
success: function (data) {
|
||||
|
||||
console.log(data);
|
||||
response(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 3,
|
||||
select: function (event, ui) {
|
||||
var uniqueid = $(event.target).attr('id');
|
||||
uniqueid = uniqueid.substring('tableComponents_name_'.length);
|
||||
var rowIndex = $('#tableComponents').appendGrid('getRowIndex', uniqueid);
|
||||
if (ui.item.id != '') {
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'code', rowIndex, ui.item.code);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex, '0.000000');
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'ecmcomponent_id', rowIndex, ui.item.ecmcomponent_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'unit_id', rowIndex, ui.item.unit_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'product_category_id', rowIndex, ui.item.product_category_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'product_category_name', rowIndex, ui.item.product_category_name);
|
||||
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: ui.item.srp_price, Summary: 0.000000});
|
||||
}
|
||||
},
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
}, {
|
||||
name: 'product_category_name',
|
||||
display: SUGAR.language.get("app_strings", "LBL_CATEGORY"),
|
||||
type: 'text',
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
ctrlAttr: {
|
||||
disabled: 'disabled',
|
||||
readonly: 'readonly'
|
||||
},
|
||||
}, {
|
||||
name: 'unit_id',
|
||||
display: SUGAR.language.get("app_strings", "LBL_JM"),
|
||||
type: 'select',
|
||||
ctrlOptions: SUGAR.language.get("app_list_strings", "ecmproducts_unit_dom"),
|
||||
displayCss: {
|
||||
'width': '3%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
}, {
|
||||
name: 'quantity_recipe',
|
||||
display: SUGAR.language.get("app_strings", "LBL_QUANTITY_RECIPE"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0.00000000',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
onClick: function (evt, rowIndex) {
|
||||
|
||||
|
||||
$('#tableComponents_quantity_recipe_'+(rowIndex+1)).select();
|
||||
},
|
||||
onChange: function (evt, rowIndex) {
|
||||
var row = $('#tableComponents').appendGrid('getRowValue', rowIndex);
|
||||
var formatedQuantity = QuantityFormat(row.quantity_recipe,8);
|
||||
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity_recipe', rowIndex, formatedQuantity);
|
||||
var Quantity=formatedQuantity;
|
||||
var PriceSingle = (row.price.Single);
|
||||
|
||||
var Divider = UnformatNumber(row.divider);
|
||||
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex,QuantityFormat(Quantity/Divider,8));
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: row.price.Single, Summary: (Quantity/Divider) * PriceSingle});
|
||||
|
||||
updateSumComponents();
|
||||
}
|
||||
}, {
|
||||
name: 'divider',
|
||||
display: SUGAR.language.get("app_strings", "LBL_DIVIDER"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '1,0',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
onClick: function (evt, rowIndex) {
|
||||
|
||||
|
||||
$('#tableComponents_divider_'+(rowIndex+1)).select();
|
||||
},
|
||||
onChange: function (evt, rowIndex) {
|
||||
var row = $('#tableComponents').appendGrid('getRowValue', rowIndex);
|
||||
var formatedQuantity = FormatNumber(row.divider,2);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'divider', rowIndex, formatedQuantity);
|
||||
var Quantity = UnformatNumber(formatedQuantity);
|
||||
var PriceSingle = (row.price.Single);
|
||||
var Divider = row.quantity_recipe;
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex,QuantityFormat(Divider/Quantity,6));
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: row.price.Single, Summary: (Divider/Quantity) * PriceSingle});
|
||||
|
||||
updateSumComponents();
|
||||
}
|
||||
}, {
|
||||
name: 'quantity',
|
||||
display: SUGAR.language.get("app_strings", "LBL_QUANTITY"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0.000000',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
onClick: function (evt, rowIndex) {
|
||||
|
||||
|
||||
$('#tableComponents_quantity_'+(rowIndex+1)).select();
|
||||
},
|
||||
ctrlAttr: { 'readonly': 'readonly' },
|
||||
onChange: function (evt, rowIndex) {
|
||||
var row = $('#tableComponents').appendGrid('getRowValue', rowIndex);
|
||||
var formatedQuantity = QuantityFormat(row.quantity,6);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex, formatedQuantity);
|
||||
var Quantity = formatedQuantity;
|
||||
var PriceSingle = (row.price.Single);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: row.price.Single, Summary: Quantity * PriceSingle});
|
||||
|
||||
updateSumComponents();
|
||||
}
|
||||
}, {
|
||||
name: 'price',
|
||||
display: 'Cena / Wartość',
|
||||
type: 'custom',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
customBuilder: function (parent, idPrefix, name, uniqueIndex) {
|
||||
// Tworzenie Id dla inputow
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
//kontener
|
||||
var ctrl = document.createElement('span');
|
||||
//dodajemy kontener do komorki w tabeli
|
||||
$(ctrl).attr({id: ctrlId, name: ctrlId}).appendTo(parent);
|
||||
//Tworzymy pierwszy input dla ceny jednostkowej
|
||||
var Single = $('<input/>', {type: 'text', id: ctrlId + '_Single', name: ctrlId + '_Single', class: 'inputs'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Single).val('0,00');
|
||||
//Akacja wywolywana podczas zmiany wartosci oraz formatuje
|
||||
// oblicza (ilosc*cena jednostkowa) i wstawia
|
||||
$(Single).change(function () {
|
||||
var SingleFormated = FormatNumber($(this).val());
|
||||
$(this).val(SingleFormated);
|
||||
var qunatity = ($('#' + idPrefix + '_quantity_' + uniqueIndex).val());
|
||||
$('#' + ctrlId + '_Summary').val(FormatNumber(qunatity * UnformatNumber(SingleFormated),6));
|
||||
updateSumComponents();
|
||||
});
|
||||
$(Single).on('click',function () {
|
||||
$('#tableComponents_price_'+(uniqueIndex)+"_Single").select();
|
||||
});
|
||||
//dodajemy do kontenera
|
||||
$(Single).appendTo(ctrl);
|
||||
//oddzielamy widoczna linia
|
||||
var hr = document.createElement('hr');
|
||||
$(hr).css('margin', '0em').appendTo(ctrl);
|
||||
//Tworzymy drugi input dla sumy
|
||||
var Summary = $('<input/>', {type: 'text', id: ctrlId + '_Summary', name: ctrlId + '_Summary', class: 'inputs'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Summary).val('0,000000');
|
||||
//Akacja wywolywana podczas zmiany wartosci oraz formatuje
|
||||
// oblicza (suma / ilosc) i wstawia
|
||||
$(Summary).change(function () {
|
||||
var SummaryFormated = FormatNumber($(this).val(),6);
|
||||
$(this).val(SummaryFormated);
|
||||
var qunatity = ($('#' + idPrefix + '_quantity_' + uniqueIndex).val());
|
||||
$('#' + ctrlId + '_Single').val(FormatNumber(UnformatNumber(SummaryFormated) / qunatity));
|
||||
updateSumComponents();
|
||||
});
|
||||
$(Summary).appendTo(ctrl);
|
||||
return ctrl;
|
||||
},
|
||||
customGetter: function (idPrefix, name, uniqueIndex) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
var Single = UnformatNumber($('#' + ctrlId + '_Single').val());
|
||||
var Summary = UnformatNumber($('#' + ctrlId + '_Summary').val());
|
||||
return {Single: Single, Summary: Summary};
|
||||
},
|
||||
customSetter: function (idPrefix, name, uniqueIndex, value) {
|
||||
console.log(value);
|
||||
if (value != null) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
$('#' + ctrlId + '_Single').val(value['Single'] == null ? '0,00' : FormatNumber(value['Single']));
|
||||
$('#' + ctrlId + '_Summary').val(value['Summary'] == null ? '0,000000' : FormatNumber(value['Summary'],6));
|
||||
}
|
||||
},
|
||||
}, {
|
||||
name: 'ecmcomponent_id',
|
||||
display: 'ecmcomponent_id',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'product_category_id',
|
||||
display: 'product_category_id',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
},
|
||||
],
|
||||
i18n: {
|
||||
append: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_APPEND"),
|
||||
remove: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVE"),
|
||||
insert: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_INSERT"),
|
||||
moveUp: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEUP"),
|
||||
moveDown: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEDOWN"),
|
||||
removeLast: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVELAST"),
|
||||
rowEmpty: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWEMPTY"),
|
||||
rowDrag: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWDRAG"),
|
||||
},
|
||||
customGridButtons: {
|
||||
insert: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/add_position.gif';
|
||||
return button;
|
||||
},
|
||||
remove: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/deleterow.gif';
|
||||
return button;
|
||||
},
|
||||
moveUp: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowup.gif';
|
||||
return button;
|
||||
},
|
||||
moveDown: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowdown.gif';
|
||||
return button;
|
||||
},
|
||||
},
|
||||
afterRowRemoved: function (caller, rowIndex) {
|
||||
var quantity = $('#tableComponents').appendGrid(
|
||||
'getRowCount');
|
||||
if (quantity == 0) {
|
||||
$('#tableComponents').appendGrid('appendRow', 1);
|
||||
}
|
||||
},
|
||||
afterRowAppended: function(caller, parentRowIndex, addedRowIndex){
|
||||
|
||||
$('#tableComponents_name_'+(addedRowIndex+1)).focus();
|
||||
},
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
append: false,
|
||||
insert: false,
|
||||
moveUp: true,
|
||||
moveDown: true
|
||||
}
|
||||
});
|
||||
var buttonSelect = document.createElement('img');
|
||||
buttonSelect.src = 'modules/EcmQuotes/images/search.gif';
|
||||
$(buttonSelect).addClass('selectComponent');
|
||||
$(buttonSelect).on('click', selectComponent);
|
||||
//$("#tableComponents").find("tbody").find(".last").append(buttonSelect);
|
||||
$('#tableComponents_price_td_head').html('Cena<br>Wartość');
|
||||
var count = $('#tableComponents').appendGrid('getRowCount');
|
||||
for (var i = 0; i < count; i++) {
|
||||
var value = $('#tableComponents').appendGrid('getCtrlValue', 'quantity', i);
|
||||
var divider = $('#tableComponents').appendGrid('getCtrlValue', 'divider', i);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', i, QuantityFormat(value,6));
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'divider', i, FormatNumber(divider,2));
|
||||
}
|
||||
//Podsumowanie
|
||||
var html = '<tr><td colspan="8" style="vertical-align: middle;border-top: 1px solid black">Suma:</td><td style="text-align: right;border-top: 1px solid black"><span id="sumComponentsPriceTotal">0,000000</span></td></tr>';
|
||||
$('#tableComponents').find('tfoot tr:last').after(html);
|
||||
updateSumComponents();
|
||||
}
|
||||
|
||||
function selectComponent(){
|
||||
var id = $(this).closest('tr').find("input[name^='tableComponents_ecmcomponent_id_']").attr('id');
|
||||
var name = $(this).closest('tr').find("input[name^='tableComponents_name_']").attr('id');
|
||||
var code = $(this).closest('tr').find("input[name^='tableComponents_code_']").attr('id');
|
||||
var unit_id = $(this).closest('tr').find("select[name^='tableComponents_unit_id']").attr('id');
|
||||
|
||||
var window = open_popup('EcmProducts', 600, 400, '', true, false,{'call_back_function': 'testms', 'form_name': 'EditView', 'field_to_name_array':{'id': id, 'name': name ,'code' : code ,'unit_id' : unit_id}}, 'single', true);
|
||||
}
|
||||
function testms(dane1,dane2){
|
||||
console.log(dane1);
|
||||
console.log(dane2);
|
||||
}
|
||||
function updateSumComponents() {
|
||||
var data = $('#tableComponents').appendGrid('getAllValue');
|
||||
var sumPriceSingle = 0;
|
||||
var sumPriceTotal = 0;
|
||||
$.each(data, function (index, value) {
|
||||
console.log(value.price.Single);
|
||||
console.log(parseFloat(value.price.Single));
|
||||
sumPriceTotal += parseFloat(value.price.Summary);
|
||||
});
|
||||
$('#sumComponentsPriceTotal').html(FormatNumber(sumPriceTotal,6));
|
||||
}
|
||||
910
modules/EcmProducts/javascript/MyTable.js
Executable file
910
modules/EcmProducts/javascript/MyTable.js
Executable file
@@ -0,0 +1,910 @@
|
||||
var reg = /[\s]/g;
|
||||
|
||||
function findPos(obj) {
|
||||
var curleft = curtop = 0;
|
||||
if (obj.offsetParent)
|
||||
do {
|
||||
curleft += obj.offsetLeft;
|
||||
curtop += obj.offsetTop;
|
||||
} while (obj = obj.offsetParent);
|
||||
return [curleft, curtop];
|
||||
}
|
||||
|
||||
function generateSelectOptions(arr, selected) {
|
||||
var tmp = '';
|
||||
for (x in arr) {
|
||||
tmp += '<option value="' + x + '" ' + ((arr[x] === selected) ? 'selected' : '') + '>' + arr[x] + '</option>';
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
function NumberToUserFormatNumber(number, add, len, zeros) {
|
||||
if (!number)
|
||||
number = 0;
|
||||
if (!len) {
|
||||
len = 2;
|
||||
zeros = 2;
|
||||
}
|
||||
number = parseFloat(number);
|
||||
//var tmp = number.toFixed(OPT['dec_len']);
|
||||
var tmp = number.toFixed(len);
|
||||
//var s1 = tmp.substring(0,tmp.length-1-OPT['dec_len']);
|
||||
var s1 = tmp.substring(0, tmp.length - 1 - len);
|
||||
if (zeros == true)
|
||||
return s1;
|
||||
//var s2 = tmp.substring(tmp.length-OPT['dec_len'],tmp.length);
|
||||
var s2 = tmp.substring(tmp.length - 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;
|
||||
tmp = s1.substring(i - 3, i) + tmp;
|
||||
if (i > 3)
|
||||
tmp = '.' + tmp;
|
||||
}
|
||||
s1 = tmp;
|
||||
if (s2.length > zeros) {
|
||||
var cut = s2.length;
|
||||
for (var i = s2.length - 1; i > zeros - 1; i--) {
|
||||
if (s2[i] == '0')
|
||||
cut--;
|
||||
else
|
||||
break;
|
||||
}
|
||||
s2 = s2.substring(0, cut);
|
||||
}
|
||||
//console.log(s2);
|
||||
//return (s1+OPT['dec_sep']+s2).toString()+((add)?add:'');
|
||||
return (s1 + ',' + 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 keyPressed = function(e, method) {
|
||||
var keynumkey = PressedNumber(e);
|
||||
if((keynum == 9) || (keynum == 13)) {
|
||||
//this.calculateTotal();
|
||||
//if(this.selectedCell.lp == 1) setTimeout( function() { N.selectNextCell(); } , 100);
|
||||
//this.selectNextCell();
|
||||
return false;
|
||||
}
|
||||
//if(keynum == 40) this.selectNextRow();
|
||||
//if(keynum == 38) this.selectPreviousRow();
|
||||
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 == 13) //enter
|
||||
|| (keynum == 0) //special keys with FF
|
||||
|| (keynum == 37) //left arrow
|
||||
|| (keynum == 39) //right arrow
|
||||
|| (keynum == 188) //,
|
||||
|| (keynum >= 95 && keynum <= 105) //numeric keyboard
|
||||
|| (keynum == 110);
|
||||
}
|
||||
*/
|
||||
function MyTable(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.divParent;
|
||||
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.deleteRow = function(row) {
|
||||
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);
|
||||
if(!row) return;
|
||||
if(row.nextSibling) this.selectNextRow();
|
||||
else if(row.previousSibling) this.selectPreviousRow();
|
||||
this.tbody.removeChild(row);
|
||||
this.deselectRow();
|
||||
this.deselectCell();
|
||||
if(this.rowCount() == 0)
|
||||
setTimeout( function() { N.insertRow(); } , 1000);
|
||||
}
|
||||
this.changeRowMode = function(row) {
|
||||
row.isnew = !row.isnew;
|
||||
this.setEditNames(row,!row.isnew);
|
||||
var img = row.firstChild.nextSibling.lastChild.previousSibling.previousSibling;
|
||||
if(row.isnew)
|
||||
img.setAttribute('src','modules/EcmInvoiceOuts/images/newproductset.gif');
|
||||
else
|
||||
img.setAttribute('src','modules/EcmInvoiceOuts/images/newproduct.gif');
|
||||
}
|
||||
*/
|
||||
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) {
|
||||
if (this.rowCount() > 0) {
|
||||
try {
|
||||
if (typeof (i) != "undefined") {
|
||||
var r = i;
|
||||
if (typeof (i) == "object") {
|
||||
} else if (typeof (i) == "number")
|
||||
r = this.tbody.rows.item(i - 1);
|
||||
if (this.isProductLoaded(r.cells.item(0)) == false) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
var row = this.createRow();
|
||||
if (this.selectedRow)
|
||||
this.selectedRow.deselect();
|
||||
if (this.selectedCell)
|
||||
this.selectedCell.deselect();
|
||||
row.myTable = this;
|
||||
if (typeof (i) == "number")
|
||||
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();
|
||||
if (this.myTable.divParent)
|
||||
if (((this.offsetTop + this.offsetHeight - this.myTable.divParent.scrollTop) > (this.myTable.divParent.offsetHeight + 5)) || ((this.offsetTop - this.myTable.divParent.scrollTop) < (-10)))
|
||||
this.myTable.divParent.scrollTop = this.offsetTop;
|
||||
}
|
||||
}
|
||||
row.deselect = function () {
|
||||
if (this.myTable.selectedRow === this) {
|
||||
this.className = '';
|
||||
this.myTable.selectedRow = '';
|
||||
if (row.onDeselect)
|
||||
row.onDeselect();
|
||||
}
|
||||
};
|
||||
row.calculateTotal = function () {
|
||||
};
|
||||
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.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();
|
||||
}, 1000);
|
||||
}
|
||||
this.myTable.tbody.removeChild(this);
|
||||
this.myTable.refreshRowIndex();
|
||||
calculateTotal();
|
||||
}
|
||||
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);
|
||||
}
|
||||
//this.calculateTotal();
|
||||
}
|
||||
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.cellCodeIndex = 1;
|
||||
this.isProductLoaded = function (cell) {
|
||||
if (this.selectedRow && typeof (this.selectedRow) != "undefined" && this.selectedRow === cell.parentNode) {
|
||||
var data = this.selectedRow.getData();
|
||||
if (data.id && data.id != "" && data.code && data.code != "") {
|
||||
} else {
|
||||
if (this.selectedCell !== cell && cell === this.selectedRow.cells.item(1)) {
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
if (cell.parentNode.cells.item(1).firstChild.focus && !cell.parentNode.cells.item(1).noSelect)
|
||||
setSelectionRange(cell.parentNode.cells.item(1).firstChild);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (typeof (cell) != "undefined" && cell.index != this.cellCodeIndex) {
|
||||
cell.parentNode.select();
|
||||
cell.parentNode.cells.item(1).select();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
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.isProductLoaded(this) == false)
|
||||
return;
|
||||
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 (this.onDeselect)
|
||||
cell.onDeselect();
|
||||
if (this.onDeselect2)
|
||||
cell.onDeselect2();
|
||||
this.className = '';
|
||||
this.selected = false;
|
||||
this.myTable.selectedCell = '';
|
||||
this.parentNode.calculateTotal();
|
||||
}
|
||||
};
|
||||
cell.selectNext = function () {
|
||||
this.deselect();
|
||||
if (this.nextSibling)
|
||||
this.nextSibling.select();
|
||||
else {
|
||||
if (!this.parentNode.nextSibling)
|
||||
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.setEditNames = function (row, isset) {
|
||||
if (isset)
|
||||
for (var i = 0; i < row.cells.length; i++) {
|
||||
if (i != 0 && i != 6 && i != 7) {
|
||||
var c = row.cells.item(i).firstChild;
|
||||
if (c.parentNode.lp == 1) {
|
||||
c.name = 'parent_wi';
|
||||
c.id = 'parent_wi';
|
||||
c = c.nextSibling.nextSibling.nextSibling.nextSibling;
|
||||
c.name = 'parent_name_wi';
|
||||
c.id = 'parent_name_wi';
|
||||
c.className = 'sqsEnabled';
|
||||
//alert(c);
|
||||
c = c.nextSibling;
|
||||
c.name = 'parent_id_wi';
|
||||
c.id = 'parent_id_wi';
|
||||
/*
|
||||
c=c.nextSibling;
|
||||
c.name = 'vat_id_p'; c.id = 'vat_id_p';
|
||||
c=c.nextSibling;
|
||||
c.name = 'category_id_p'; c.id = 'category_id_p';
|
||||
*/
|
||||
}
|
||||
/*
|
||||
if(c.parentNode.lp == 2) { c.name = 'name_p'; c.id = 'name_p'; c.className = 'sqsEnabled'; }
|
||||
if(c.parentNode.lp == 3) { c.name = 'quantity_p'; c.id = 'quantity_p'; }
|
||||
if(c.parentNode.lp == 4) { c.name = 'price_p'; c.id = 'price_p'; }
|
||||
if(c.parentNode.lp == 5) { c.name = 'discount_p'; c.id = 'discount_p'; }
|
||||
*/
|
||||
}
|
||||
}
|
||||
else
|
||||
for (var i = 0; i < row.cells.length; i++) {
|
||||
if (i != 0 && i != 5) {
|
||||
var c = row.cells.item(i).firstChild;
|
||||
c.name = '';
|
||||
c.id = '';
|
||||
if (i == 1) {
|
||||
c = c.nextSibling.nextSibling.nextSibling.nextSibling;
|
||||
c.name = '';
|
||||
c.id = '';
|
||||
c = c.nextSibling;
|
||||
c.name = '';
|
||||
c.id = '';
|
||||
/*
|
||||
c=c.nextSibling;
|
||||
c.name = ''; c.id = '';
|
||||
c=c.nextSibling;
|
||||
c.name = ''; c.id = ''; */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.deselectRow = function () {
|
||||
if (!this.selectedRow)
|
||||
return;
|
||||
this.setEditNames(this.selectedRow, false);
|
||||
this.selectedRow.className = '';
|
||||
this.deselectCell();
|
||||
this.selectedRow = null;
|
||||
}
|
||||
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.calculateSubtotal = function (row, sub) {
|
||||
if (!row)
|
||||
if (this.selectedRow)
|
||||
row = this.selectedRow;
|
||||
else
|
||||
return 0;
|
||||
if (row.cells.item(4).err || row.cells.item(5).err) {
|
||||
row.cells.item(6).firstChild.value = NumberToUserFormatNumber(0);
|
||||
row.cells.item(6).firstChild.style.color = 'red';
|
||||
row.title = 'Bad number format';
|
||||
} else if (row.cells.item(2).firstChild.value == '' && UserFormatNumberToNumber(row.cells.item(4).firstChild.value) != 0 && !row.cells.item(4).err) {
|
||||
row.cells.item(6).firstChild.style.color = 'red';
|
||||
row.title = 'Position have price, but didin\'t have a description';
|
||||
} else {
|
||||
var quantity = parseInt(row.cells.item(3).firstChild.value);
|
||||
if (row.cells.item(1).firstChild.nextSibling.nextSibling.value == 3)
|
||||
quantity = 1;
|
||||
var price = UserFormatNumberToNumber(tmp = row.cells.item(4).firstChild.value);
|
||||
var discount = UserFormatNumberToNumber(row.cells.item(5).firstChild.value, "%");
|
||||
var total = NumberToUserFormatNumber(quantity * price - quantity * price * (discount / 100));
|
||||
row.cells.item(6).firstChild.value = total;
|
||||
row.cells.item(6).firstChild.style.color = 'black';
|
||||
row.title = '';
|
||||
}
|
||||
//if(!sub) this.calculateTotal();
|
||||
}
|
||||
this.calculateTotal = function () {
|
||||
var vats = new Object();
|
||||
var subtotal = 0;
|
||||
var total = 0;
|
||||
for (var i = 0; i < this.rowCount(); i++) {
|
||||
if (!OPT['to_is_vat_free']) {
|
||||
var v_tmp = this.tbody.rows.item(i).cells.item(1).firstChild.nextSibling.nextSibling.nextSibling.value;
|
||||
if (v_tmp && this.tbody.rows.item(i).cells.item(2).firstChild.value != '') {
|
||||
if (typeof (vats[v_tmp]) != "object") {
|
||||
vats[v_tmp] = new Object();
|
||||
vats[v_tmp]['vat'] = 0;
|
||||
}
|
||||
vats[v_tmp]['vat'] += UserFormatNumberToNumber(this.tbody.rows.item(i).cells.item(6).firstChild.value);
|
||||
}
|
||||
} else if (typeof (vats['0.00']) != "object") {
|
||||
vats['0.00'] = new Object();
|
||||
vats['0.00']['vat'] = 0;
|
||||
}
|
||||
subtotal += UserFormatNumberToNumber(this.tbody.rows.item(i).cells.item(6).firstChild.value);
|
||||
}
|
||||
total = subtotal;
|
||||
var rt = document.getElementById('result_table');
|
||||
for (var i = 1; i < rt.rows.length - 1; i++) {
|
||||
if (!vats[rt.rows.item(i).id]) {
|
||||
rt.deleteRow(i);
|
||||
--i;
|
||||
} else
|
||||
vats[rt.rows.item(i).id]['node'] = rt.rows.item(i);
|
||||
}
|
||||
for (x in vats) {
|
||||
vats[x]['vat'] = vats[x]['vat'] * (parseFloat(x) / 100);
|
||||
total += vats[x]['vat'];
|
||||
var txL = 'VAT' + ' (' + NumberToUserFormatNumber(parseFloat(x), '%') + ')';
|
||||
var txF = NumberToUserFormatNumber(vats[x]['vat']);
|
||||
if (vats[x]['node']) {
|
||||
vats[x]['node'].id = x;
|
||||
vats[x]['node'].cells.item(0).innerHTML = txL;
|
||||
vats[x]['node'].cells.item(1).innerHTML = txF;
|
||||
} else {
|
||||
rt.insertRow(1);
|
||||
rt.rows.item(1).id = x;
|
||||
rt.rows.item(1).insertCell(0);
|
||||
rt.rows.item(1).cells.item(0).className = 'positionsLabel';
|
||||
rt.rows.item(1).cells.item(0).innerHTML = txL;
|
||||
rt.rows.item(1).insertCell(1);
|
||||
rt.rows.item(1).cells.item(1).className = 'positionsField';
|
||||
rt.rows.item(1).cells.item(1).innerHTML = txF;
|
||||
}
|
||||
}
|
||||
document.getElementById('subtotal_span').innerHTML = NumberToUserFormatNumber(subtotal);
|
||||
document.getElementById('subtotal').value = NumberToUserFormatNumber(subtotal);
|
||||
total = ((iType == "correct") ? '-' : '') + NumberToUserFormatNumber(total).toString();
|
||||
document.getElementById('total_span').innerHTML = total;
|
||||
document.getElementById('total').value = total;
|
||||
}
|
||||
this.deselectCell = function () {
|
||||
if (!this.selectedCell)
|
||||
return;
|
||||
var tmp = 0;
|
||||
var c = this.selectedCell;
|
||||
/*
|
||||
if(c.lp == 4)
|
||||
if(c.firstChild.value != "") {
|
||||
tmp = UserFormatNumberToNumber(this.selectedCell.firstChild.value);
|
||||
if(tmp == -1) {
|
||||
alert('Error with format number: '+c.firstChild.value);
|
||||
c.err = true;
|
||||
c.firstChild.style.color = 'red';
|
||||
}
|
||||
else {
|
||||
c.firstChild.value = NumberToUserFormatNumber(tmp);
|
||||
c.firstChild.style.color = 'black';
|
||||
c.err = false;
|
||||
}
|
||||
}
|
||||
if(c.lp == 5)
|
||||
if(c.firstChild.value != "") {
|
||||
tmp = UserFormatNumberToNumber(this.selectedCell.firstChild.value,"%");
|
||||
if(tmp == -1) {
|
||||
alert('Error with format number: '+c.firstChild.value);
|
||||
c.err = true;
|
||||
c.firstChild.style.color = 'red';
|
||||
}
|
||||
else {
|
||||
c.firstChild.value = NumberToUserFormatNumber(tmp,"%");
|
||||
c.firstChild.style.color = 'black';
|
||||
c.err = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
//this.calculateSubtotal(c.parentNode);
|
||||
this.selectedCell.className = '';
|
||||
this.selectedCell = null;
|
||||
}
|
||||
this.selectCell = function (cell) {
|
||||
if (this.selectedCell === cell)
|
||||
return;
|
||||
if (this.selectedCell)
|
||||
this.deselectCell();
|
||||
this.selectedCell = cell;
|
||||
if (!cell.noSelect) {
|
||||
this.selectedCell.className = this.cellSelectedClass;
|
||||
this.setCellFocus(this.selectedCell);
|
||||
}
|
||||
}
|
||||
this.selectNextCell = function () {
|
||||
if (!this.selectedCell)
|
||||
return;
|
||||
if (this.selectedCell.lp == 4) {
|
||||
this.selectNextRow();
|
||||
this.selectCell(this.selectedRow.firstChild.nextSibling);
|
||||
} else
|
||||
this.selectCell(this.selectedCell.nextSibling);
|
||||
}
|
||||
this.setCellFocus = function (cell, input) {
|
||||
if (typeof (cell) == 'number') {
|
||||
cell = this.selectedRow.cells.item(cell);
|
||||
}
|
||||
var edit = ((input) ? input : cell.firstChild);
|
||||
if (edit && typeof (edit) == "object" && (edit.type == "text" || edit.type == "textarea")) {
|
||||
if (edit.createTextRange) {
|
||||
var range = edit.createTextRange();
|
||||
range.moveStart("character", 0);
|
||||
range.moveEnd("character", edit.value.lengh - 1);
|
||||
range.select();
|
||||
} else {
|
||||
if (edit.setSelectionRange) {
|
||||
edit.setSelectionRange(0, edit.value.length);
|
||||
}
|
||||
}
|
||||
edit.focus();
|
||||
}
|
||||
if (edit && typeof (edit) == "object" && edit.options) {
|
||||
edit.focus();
|
||||
}
|
||||
}
|
||||
this.fillWithDefaultData = function (row) {
|
||||
//this.setCellData(3,1,row);
|
||||
//this.setCellData(5,0,row);
|
||||
//this.setCellData(6,0,row);
|
||||
}
|
||||
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.setCellData = function(i,data,row) {
|
||||
if(!row) if(this.selectedRow) row = this.selectedRow; else return null;
|
||||
//if(i == 3) { row.firstChild.nextSibling.nextSibling.nextSibling.firstChild.value = data; }
|
||||
//if(i == 5) { row.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.value = NumberToUserFormatNumber(data,"%"); }
|
||||
//if(i == 6) { row.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.value = NumberToUserFormatNumber(data); }
|
||||
}
|
||||
*/
|
||||
this.insertRowFromArray = function (arr) {
|
||||
var row = this.insertRow();
|
||||
row.cells.item(1).firstChild.value = arr['code'];
|
||||
row.cells.item(1).firstChild.nextSibling.value = arr['id'];
|
||||
row.cells.item(1).firstChild.nextSibling.nextSibling.value = arr['unit_id'];
|
||||
row.cells.item(1).firstChild.nextSibling.nextSibling.nextSibling.value = arr['vat_id'];
|
||||
row.cells.item(1).firstChild.nextSibling.nextSibling.nextSibling.nextSibling.value = arr['category_id'];
|
||||
row.cells.item(2).firstChild.value = arr['name'];
|
||||
row.cells.item(3).firstChild.value = arr['quantity'];
|
||||
row.cells.item(4).firstChild.value = NumberToUserFormatNumber(arr['price']);
|
||||
row.cells.item(5).firstChild.value = NumberToUserFormatNumber(arr['discount'], '%');
|
||||
row.cells.item(6).firstChild.value = NumberToUserFormatNumber(arr['total']);
|
||||
}
|
||||
this.getRowData = function (row) {
|
||||
if (typeof (row) == "number")
|
||||
row = this.tbody.rows.item(row);
|
||||
var rData = new Object();
|
||||
rData['id'] = row.cells.item(1).firstChild.nextSibling.value;
|
||||
rData['unit_id'] = row.cells.item(1).firstChild.nextSibling.nextSibling.value;
|
||||
if (!rData['unit_id'])
|
||||
rData['unit_id'] = OPT['default_unit']; //szt
|
||||
rData['vat_id'] = row.cells.item(1).firstChild.nextSibling.nextSibling.nextSibling.value;
|
||||
if (!rData['vat_id'])
|
||||
rData['vat_id'] = OPT['default_vat']; //standard
|
||||
rData['category_id'] = row.cells.item(1).firstChild.nextSibling.nextSibling.nextSibling.nextSibling.value;
|
||||
if (!rData['category_id'])
|
||||
rData['category_id'] = OPT['default_category']; //no category
|
||||
rData['code'] = row.cells.item(1).firstChild.value;
|
||||
rData['name'] = row.cells.item(2).firstChild.value;
|
||||
rData['quantity'] = row.cells.item(3).firstChild.value;
|
||||
rData['price'] = UserFormatNumberToNumber(row.cells.item(4).firstChild.value);
|
||||
rData['discount'] = UserFormatNumberToNumber(row.cells.item(5).firstChild.value, '%');
|
||||
rData['total'] = UserFormatNumberToNumber(row.cells.item(6).firstChild.value);
|
||||
if (rData['code'] == '' && rData['name'] == '')
|
||||
return '';
|
||||
else
|
||||
return rData;
|
||||
}
|
||||
this.prepareToSend = function (json) {
|
||||
var rData = new Object();
|
||||
var l = 0,
|
||||
tmp;
|
||||
for (var i = 0; i < this.rowCount(); i++) {
|
||||
//this.calculateSubtotal(this.tbody.rows.item(i),true);
|
||||
tmp = this.getRowData(i);
|
||||
if (tmp != '') {
|
||||
rData[l.toString()] = tmp;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
//this.calculateTotal();
|
||||
if (!json)
|
||||
return JSON.stringifyNoSecurity(rData);
|
||||
else
|
||||
return rData;
|
||||
}
|
||||
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, noArrow) {
|
||||
var keynum;
|
||||
if (window.event) //IE
|
||||
keynum = e.keyCode;
|
||||
else
|
||||
keynum = e.which;
|
||||
if ((keynum == 9) || (keynum == 13 && cell.index != 2)) {
|
||||
//this.calculateTotal();
|
||||
//if(this.selectedCell.lp == 1) setTimeout( function() { N.selectNextCell(); } , 100);
|
||||
//this.selectNextCell();
|
||||
if (cell.index == 1 || cell.index == 2)
|
||||
cell.parentNode.calculateTotal();
|
||||
cell.selectNext();
|
||||
return false;
|
||||
}
|
||||
if (!noArrow) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
} else
|
||||
return true;
|
||||
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) //,
|
||||
|| (keynum >= 95 && keynum <= 105) //numeric keyboard
|
||||
|| (keynum == 110);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
// var N;
|
||||
var parent_options;
|
||||
/*
|
||||
function ItemListSave(json) {
|
||||
if(N.selectedCell) N.selectedCell.deselect();
|
||||
if(N.selectedRow) N.selectedRow.deselect();
|
||||
var data = new Object();
|
||||
for(var i=0; i<N.rowCount(); i++) {
|
||||
data[i.toString()] = N.row(i).getData();
|
||||
}
|
||||
return json ? JSON.stringifyNoSecurity(data) : data;
|
||||
}
|
||||
function ItemListClear() {
|
||||
while(N.rowCount()>0) N.row(0).deleteRow();
|
||||
}
|
||||
*/
|
||||
function ItemListFill(list) {
|
||||
/*
|
||||
var start_list_count = 6;
|
||||
var count = 0;
|
||||
var arr = '';
|
||||
if(list)
|
||||
arr = list;
|
||||
else
|
||||
if(document.getElementById('position_list').value!="")
|
||||
arr = eval(document.getElementById('position_list').value);
|
||||
if(arr != '')
|
||||
for(x in arr) {
|
||||
N.insertRowFromArray(arr[x]);
|
||||
count++;
|
||||
}
|
||||
for(var i=count; i<start_list_count; i++) N.insertRow();
|
||||
N.calculateTotal();
|
||||
*/
|
||||
}
|
||||
25
modules/EcmProducts/javascript/autoIndeks.js
Executable file
25
modules/EcmProducts/javascript/autoIndeks.js
Executable file
@@ -0,0 +1,25 @@
|
||||
var startCode;
|
||||
|
||||
$(document).ready(function () {
|
||||
startCode = $('#code').val();
|
||||
if ($('#code').val() == '') {
|
||||
$('#code').val(genereteCode());
|
||||
}
|
||||
});
|
||||
|
||||
function genereteCode() {
|
||||
var code;
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=indeksIncrement&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "generateCode",
|
||||
},
|
||||
success: function (data) {
|
||||
code = data;
|
||||
}
|
||||
});
|
||||
return code;
|
||||
}
|
||||
90
modules/EcmProducts/javascript/formloader.js
Executable file
90
modules/EcmProducts/javascript/formloader.js
Executable file
@@ -0,0 +1,90 @@
|
||||
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 my_popup(module, field_array, call_back_function, form_name) {
|
||||
if (!call_back_function) call_back_function = "set_return";
|
||||
if (!form_name) form_name = "EditView";
|
||||
return open_popup(module, 900, 700, "", true, false, {
|
||||
"call_back_function": call_back_function,
|
||||
"form_name": form_name,
|
||||
"field_to_name_array": field_array
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
function FormLoader() {
|
||||
this.module;
|
||||
this.createModule;
|
||||
this.fieldName;
|
||||
this.buttonName = 'FormLoaderButton';
|
||||
this.load = function(module, createModule, fieldName) {
|
||||
this.module = module;
|
||||
this.createModule = createModule;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
this.createButton = function() {
|
||||
var b = document.createElement('input');
|
||||
b.type = 'button';
|
||||
b.className = 'button';
|
||||
b.name = this.buttonName;
|
||||
b.value = 'Create';
|
||||
b.FL = this;
|
||||
b.onclick = function() {
|
||||
if (this.FL.createModule == '') return;
|
||||
if (this.FL.onButtonClick) var data = this.FL.onButtonClick();
|
||||
window.open("index.php?module=" + this.FL.module + "&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName=" + this.FL.fieldName + "&createModule=" + this.FL.createModule + (data ? data : ''), "Create10" + this.FL.module, "resizable=yes,scrollbars=no,status=no,height=540,width=700").focus();
|
||||
}
|
||||
return b;
|
||||
}
|
||||
this.setEditDblClick = function(edit) {
|
||||
edit.FL = this;
|
||||
edit.ondblclick = this.editDblClick;
|
||||
}
|
||||
this.editDblClick = function() {
|
||||
if (this.FL.createModule == '') return;
|
||||
if (this.FL.onEditDblClick) var data = this.FL.onEditDblClick();
|
||||
window.open("index.php?module=" + this.FL.module + "&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName=" + this.FL.fieldName + "&createModule=" + this.FL.createModule + (data ? data : ''), "Create10" + this.FL.module, "resizable=yes,scrollbars=no,status=no,height=540,width=700").focus();
|
||||
}
|
||||
this.responseData = function(data) {
|
||||
if (this.onResponseData) this.onResponseData(data);
|
||||
}
|
||||
this.onResponseData;
|
||||
this.addPostData = function() {
|
||||
if (this.onAddPostData)
|
||||
return this.onAddPostData();
|
||||
else
|
||||
return '';
|
||||
}
|
||||
this.onAddPostData;
|
||||
this.onButtonClick;
|
||||
}
|
||||
2
modules/EcmProducts/mintajaxToDelete.js
Executable file
2
modules/EcmProducts/mintajaxToDelete.js
Executable file
File diff suppressed because one or more lines are too long
381
modules/EcmProducts/paramsMT.js
Executable file
381
modules/EcmProducts/paramsMT.js
Executable file
@@ -0,0 +1,381 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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.getUnformatData = function() {
|
||||
var data = new Object();
|
||||
for(var i=0; i<this.myTable.colCount(); i++) {
|
||||
if(this.cells.item(i).getUnformatData) this.cells.item(i).getUnformatData(data,true);
|
||||
}
|
||||
return 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); }
|
||||
}
|
||||
Reference in New Issue
Block a user