var GEN_APPLY = ["Anwenden","Apply","Aplicar"]; var GEN_CANCEL = ["Abbrechen","Cancel","Cancelar"]; var GEN_DEL = ["Löschen","Remove","Removar"]; var GEN_DIRECTION = ["Verschieben","Move","Mover"]; var MAN_ROOM_PRINTER_NO = ["Kategorieeinstellung","Category setting","Configuración/categoria"]; var MAN_ROOM_PRINTER_1 = ["Drucker 1","Printer 1","Imprimadora 1"]; var MAN_ROOM_PRINTER_2 = ["Drucker 2","Printer 2","Imprimadora 2"]; var MAN_ROOM_PRINTER_TXT = ["Arbeitsdrucker","Work printer","Imprimadora de trabajo"]; var MAN_ROOM_ABBR_TXT = ["Kürzel","Abbr.","Abbr."]; var MAN_CREATENEWROOM = ["Neuer Raum","New Room","Nueva habitación"]; var MAN_SAMPLEROOMNAME = ["Raum","Room","Habitación"]; function Groundplan() { this.rooms = []; this.insertRoomFieldDataFromServer = function(roomfield_json) { var roomfield = roomfield_json.roomfield; this.rooms = []; for (var room_index = 0; room_index < roomfield.length; room_index++) { var aRoom = roomfield[room_index]; this.rooms[this.rooms.length] = new Room(aRoom); }; this.repaintGround(); showTableMap(); }; this.sortRoomsBySorting = function() { this.rooms = this.rooms.sort(function(a,b) { return a.sorting - b.sorting; }); }; this.repaintGround = function() { this.sortRoomsBySorting(); this.render(); var roomMap = new Roommap("#tablemaps"); }; this.responseFromServer = function(answer) { if (answer.status != "OK") { alert("Es ist ein Fehler aufgetreten: " + answer.msg); } else { alert("Aktion durchgeführt"); this.insertRoomFieldDataFromServer(answer); $('html, body').animate({ scrollTop: $("#dbactionroomconfig").offset().top }, 1000); } }; this.init = function() { var instance = this; doAjax("GET","php/contenthandler.php?module=roomtables&command=getRoomfieldAlsoInactive",null,instance.insertRoomFieldDataFromServer.bind(instance),"Raumplan",true); }; this.renderCancelApplyBtn = function() { var txt = ""; txt += ''; txt += '
'; txt += '
'; txt += '
'; txt += '
'; return txt; }; this.bindRoomChanges = function() { var instance = this; for (var i=0;i max) { max = maxValOfEntry; } } return parseInt(max); }; this.getMaxSorting = function () { return this.getMaxPropValue(0,"sorting"); }; this.getMaxId = function () { return this.getMaxPropValue(0,"id"); }; this.applyValues = function(roomid,doRerender) { var htmlId = "#room_" + roomid + "_"; var name = $(htmlId + "name").val(); var abbr = $(htmlId + "abbreviation").val(); var printer = $(htmlId + "printer").val(); var room = this.getRoomWithId(roomid); room.name = name; room.abbreviation = abbr; room.printer = printer; if (doRerender) { this.repaintGround(); } }; this.up = function(roomid) { var currentRoom = this.getRoomWithId(roomid); var currentSorting = currentRoom.sorting; if (currentSorting != 1) { var objBefore = this.getRoomWithSorting(currentSorting-1); objBefore.sorting = currentSorting; currentRoom.sorting = currentSorting-1; } this.repaintGround(); }; this.delete = function(roomid) { var currentRoom = this.getRoomWithId(roomid); var currentSorting = parseInt(currentRoom.sorting); var currentIndex = parseInt(this.getRoomIndexWithId(roomid)); var maxSort = this.getMaxSorting(); this.rooms.splice(currentIndex,1); if (maxSort != currentSorting) { for (var sort=(currentSorting+1);sort<=maxSort;sort++) { var aRoom = this.getRoomWithSorting(sort); aRoom.sorting = (sort-1); } } this.repaintGround(); }; this.createNewRoom = function() { var newId = genUID("RR"); var sort = this.getMaxSorting() + 1; var roomname = MAN_SAMPLEROOMNAME[lang] + " " + sort; var roomSpec = {roomid: newId, tables: [], roomname: roomname, abbreviation: "", printer: 0, sorting: sort, tableclassname: "roomtables_" + newId }; this.rooms[this.rooms.length] = new Room(roomSpec); this.repaintGround(); }; } function Room(jsonRoom) { this.tables = []; this.roomid = jsonRoom.roomid; this.name = jsonRoom.roomname; this.abbreviation = jsonRoom.abbreviation; this.printer = jsonRoom.printer; this.sorting = jsonRoom.sorting; this.tableclassname = "roomtables_" + this.roomid; for (var tableIndex = 0; tableIndex < jsonRoom.tables.length;tableIndex++) { this.tables[this.tables.length] = new Resttable(jsonRoom.tables[tableIndex],this.roomid,this.tableclassname); }; this.sortTablesBySorting = function() { this.tables = this.tables.sort(function(a,b) { return a.sorting - b.sorting; }); }; this.sortTablesBySorting(); this.renderTablesArea = function() { var staticTable = new Resttable(null,null,''); var txt = "

"; txt += staticTable.renderHeader(); for (var i=0;i'; txt += this.renderTablesArea(); txt += this.createCollapsibleEnd(); return txt; }; this.createRoomHtml = function() { var htmlId = "room_" + this.roomid; var txt = "
"; txt += ""; txt += "
Raumname" + MAN_ROOM_ABBR_TXT[lang] + "" + MAN_ROOM_PRINTER_TXT[lang] + "" + GEN_DIRECTION[lang] + "" + GEN_DEL[lang] + "
" + createGenericInputField(htmlId + "_name", this.name,"roomvalue_" + this.roomid + "_text"); txt += "" + createGenericInputField(htmlId + "_abbreviation", this.abbreviation,"roomvalue_" + this.roomid + "_text"); var printerOptions = [ { name: MAN_ROOM_PRINTER_NO[lang], value: 0}, { name: MAN_ROOM_PRINTER_1[lang], value: 1}, { name: MAN_ROOM_PRINTER_2[lang], value: 2} ]; txt += "" + createGenericSelectBox(htmlId + "_printer",printerOptions,this.printer,"roomvalue_" + this.roomid + "_printer"); txt += ""; txt += ""; txt += "
"; return txt; }; this.createCollapsibleStart = function(headerText,isCollapsed) { var txt = '

'; txt += '

' + toHtml(headerText) + '

'; return txt; }; this.createCollapsibleEnd = function() { return "

"; }; this.binding = function() { var instance = this; $("." + this.tableclassname + "_up").off("click").on("click", function (e) { e.stopImmediatePropagation(); e.preventDefault(); var resttableid = this.id.split("_")[2]; instance.up.call(instance,resttableid); }); $("." + this.tableclassname + "_delete").off("click").on("click", function (e) { e.stopImmediatePropagation(); e.preventDefault(); hideTableMap(); var resttableid = this.id.split("_")[2]; instance.delete.call(instance,resttableid); }); $(".tablevalue_" + this.roomid).off("keyup").on("keyup", function (e) { e.stopImmediatePropagation(); e.preventDefault(); hideTableMap(); var resttableid = this.id.split("_")[2]; instance.applyValues.call(instance,resttableid); }); $(".tablevalue_" + this.roomid).off("change").on("change", function (e) { e.stopImmediatePropagation(); e.preventDefault(); hideTableMap(); var resttableid = this.id.split("_")[2]; instance.applyValues.call(instance,resttableid); instance.rerenderTablesArea.call(instance); }); $(".createnewtable_" + this.roomid).off("click").on("click", function (e) { e.stopImmediatePropagation(); e.preventDefault(); hideTableMap(); instance.createNewTable.call(instance); instance.rerenderTablesArea.call(instance); }); }; this.applyValues = function(tableid) { var htmlId = "#table_" + this.roomid + "_" + tableid + "_"; var tablename = $(htmlId + "tablename").val(); var name = $(htmlId + "name").val(); var code = $(htmlId + "code").val(); var active = $(htmlId + "active").val(); var allowoutorder = $(htmlId + "allowoutorder").val(); var table = this.getTableWithId(tableid); table.tablename = tablename; table.name = name; table.active = active; table.code = code; table.allowoutorder = allowoutorder; }; this.up = function(tableid) { var currentTable = this.getTableWithId(tableid); var currentSorting = currentTable.sorting; if (currentSorting != 1) { var tableBefore = this.getTableWithSorting(currentSorting-1); tableBefore.sorting = currentSorting; currentTable.sorting = currentSorting-1; } this.rerenderTablesArea(); }; this.delete = function(tableid) { var currentTable = this.getTableWithId(tableid); var currentSorting = parseInt(currentTable.sorting); var currentIndex = parseInt(this.getTableIndexWithId(tableid)); var maxSort = this.getMaxSorting(); this.tables.splice(currentIndex,1); if (maxSort != currentSorting) { for (var sort=(currentSorting+1);sort<=maxSort;sort++) { var aTable = this.getTableWithSorting(sort); aTable.sorting = (sort-1); } } this.rerenderTablesArea(); }; this.createNewTable = function() { var newId = genUID("R" + this.roomid); var sort = this.getMaxSorting() + 1; var tbltablename = $("#newtablename_" + this.roomid).val().trim(); var tblname = $("#newname_" + this.roomid).val().trim(); var tblactive = $("#newactive_" + this.roomid).val(); var tblcode = $("#newcode_" + this.roomid).val(); var tblallowoutorder = $("#newallowoutorder_" + this.roomid).val(); if (tbltablename == "") { alert("Tischname wurde nicht eingegeben!"); } else { var json = {id: newId, roomid: this.roomid, tablename: tbltablename, name: tblname, active: tblactive, code: tblcode, allowoutorder: tblallowoutorder, sorting: sort }; var restTable = new Resttable(json,this.roomid,this.tableclassname); this.tables[this.tables.length] = restTable; } }; this.getTableWithId = function (tableid) { for (var i=0;i max) { max = maxValOfEntry; } } return parseInt(max); }; this.getMaxSorting = function () { return this.getMaxPropValue(0,"sorting"); }; this.getMaxId = function () { return this.getMaxPropValue(0,"id"); }; this.exportObject = function() { var exportObj = { roomid: this.roomid, name: this.name, abbreviation: this.abbreviation, printer: this.printer, sorting: this.sorting, tables: [] }; var tablesArr = []; this.tables.forEach(function(table,i) { tablesArr[tablesArr.length] = table.exportObject(); }); exportObj.tables = tablesArr; return exportObj; }; } function Resttable(json,roomid,classname) { this.id = ""; this.roomid = ""; this.tablename = ""; this.name = ""; this.active = 1; this.code = ""; this.allowoutorder = ""; this.sorting = 1; this.classname = ""; if (json != null) { this.id = json.id, this.roomid = roomid, this.tablename = json.tablename, this.name = json.name, this.active = json.active, this.code = json.code, this.allowoutorder = json.allowoutorder, this.sorting = json.sorting, this.classname = classname } this.render = function() { var htmlId = "table_" + roomid + "_" + this.id; var txt = ""; txt += "" + createGenericInputField(htmlId + "_tablename",this.tablename,"tablevalue_" + roomid); txt += "" + createGenericInputField(htmlId + "_name",this.name,"tablevalue_" + roomid); txt += "" + createGenericSelectBox(htmlId + "_active",[{name: "Ja",value: 1},{name: "Nein", value: 0}],this.active,"tablevalue_" + roomid); txt += "" + createGenericInputField(htmlId + "_code",this.code,"tablevalue_" + roomid); txt += "" + createGenericSelectBox(htmlId + "_allowoutorder",[{name: "Ja",value: 1},{name: "Nein", value: 0}],this.allowoutorder,"tablevalue_" + roomid); txt += ""; txt += ""; txt += ""; return txt; }; this.renderHeader = function() { var txt = "Tischname (intern)Tischname (extern)AktivCodeGastbestellung" + GEN_DIRECTION[lang] + "" + GEN_DEL[lang] + ""; return txt; }; this.renderNewEntry = function(id) { var txt = ""; txt += "" + createGenericInputField("newtablename_" + id,""); txt += "" + createGenericInputField("newname_" + id,""); txt += "" + createGenericSelectBox("newactive_" + id,[{name: "Ja",value: 1},{name: "Nein", value: 0}],1); txt += "" + createGenericInputField("newcode_" + id,""); txt += "" + createGenericSelectBox("newallowoutorder_" + id,[{name: "Ja",value: 1},{name: "Nein", value: 0}],0); txt += " "; txt += ""; return txt; }; this.exportObject = function() { return { id: this.id, roomid: this.roomid, tablename: this.tablename, name: this.name, active: this.active, code: this.code, allowoutorder: this.allowoutorder, sorting: this.sorting }; }; } function createGenericSelectBox(id,options,value,theclass) { var txt = ""; return txt; } function createGenericInputField(id,value,theclass) { var txt = ""; return txt; } function genUID(prefix) { return prefix + Math.floor((1 + Math.random()) * 0x10000) .toString(10) .substring(1); } function hideTableMap() { $("#tablemap").hide(); } function showTableMap() { $("#tablemap").show(); }