/******************************************************************************* * ATTRIBUTES * ****************************************************************************/ var rouvenfo_tables = []; var rouvenfo_valuelists = []; function RouvenfoTableObj(){ this.table_id = null; this.column_template_id = null; this.api_url = null; this.columns = []; this.selected_row_index = -1; this.filtertext = null; this.row_doubleclicked_function = null; this.row_edit_function = null; this.row_delete_function = null; this.table_data = null; this.id_columnname = "id"; this.after_load_callback = null; this.filter_column = null; this.filter_direction_asc = true; this.show_edit_row = false; this.show_delete_row = false; this.is_new_record = false; this.table_row_clicked = null; this.visible = true; this.table_row_class = null; this.page = 1; this.page_size = 100; this.page_no_more_data = false; this.get_filter = null; this.beforeSave = null; } function RouvenfoColumnObj(dataname, headertext, type, format, valuelist_id, template, classnames, width, click, visible, enablefilter, inlineedit){ this.dataname = dataname; this.headertext = headertext; this.type = type; this.format = format; this.valuelist_id = valuelist_id; this.template = template; this.classnames = classnames; this.width = width; this.click = click; this.visible = visible; this.enablefilter = enablefilter; this.inlineedit = inlineedit; this.filteractive = false; this.filtertext = null; this.filtervalue = null; } const ROUVENFO_COLUMN_TYPES = { INT: 1, DECIMAL: 2, TEXT: 3, DATETIME: 4, CURRENCY: 5, BOOLEAN: 6, DATE: 7}; const ROUVENFO_TABLE_HEADER = "rouvenfo-table-header"; const ROUVENFO_TABLE_HEADER_CONTAINER = "rouvenfo-table-header-container"; const ROUVENFO_TABLE_DATA_CLASS = "rouvenfo-table-data"; const ROUVENFO_TABLE_DATA_SCROLL_CLASS = "rouvenfo-table-data-scrollbar"; const ROUVENFO_TABLE_DATA_CONTAINER_CLASS = "rouvenfo-table-data-container"; /******************************************************************************* * rouvenfo_add_table * * Adds a new Table * * @param rouvenfoTableObj -> Parameter Object with all configurations * * ****************************************************************************/ function rouvenfo_table_add_table(tableObj, loadData){ rouvenfo_table_create_table_structure(tableObj); rouvenfo_table_add_columns(tableObj); $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_SCROLL_CLASS).scroll(function(){ var position = $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_SCROLL_CLASS).scrollLeft(); $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER_CONTAINER).css("transform", "translateX(-" + position + "px)"); }); $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER_CONTAINER + " > span").click(rouvenfo_table_header_clicked); rouvenfo_tables.push(tableObj); if(loadData){ rouvenfo_table_load_data(tableObj); } } /******************************************************************************* * rouvenfo_table_add_columns * * Creats the table columns * * @param tableObj * * ****************************************************************************/ function rouvenfo_table_add_columns(tableObj){ var cols = $("#" + tableObj.column_template_id + " > span"); for(var i = 0; i < cols.length; i++){ rouvenfo_table_add_column_to_tableobj(tableObj, cols[i]); } if(tableObj.show_edit_row){ rouvenfo_table_add_column_edit(tableObj); } if(tableObj.show_delete_row){ rouvenfo_table_add_column_delete(tableObj); } } /******************************************************************************* * rouvenfo_table_add_column_to_tableobj * * Adds the column to the tableObj * * @param tableObj * @param element * * ****************************************************************************/ function rouvenfo_table_add_column_to_tableobj(tableObj, element){ var name = element.getAttribute("rouvenfo-data"); var type = element.getAttribute("rouvenfo-type"); var format = element.getAttribute("rouvenfo-format"); var valuelist = element.getAttribute("rouvenfo-valuelist"); var template = element.innerHTML; var headertext = element.getAttribute("rouvenfo-headertext"); var width = element.getAttribute("rouvenfo-width"); var click = element.getAttribute("rouvenfo-click"); var classList = element.classList; var classnames = ""; var enablefilter = element.getAttribute("rouvenfo-filter"); var visible = element.getAttribute("rouvenfo-visible"); var inlineedit = element.getAttribute("rouvenfo-inline-edit"); classList.forEach(function(el){ classnames += el + " "; }); if(!type){ type = ROUVENFO_COLUMN_TYPES.TEXT; } if(!enablefilter){ enablefilter = false; } if(!inlineedit){ inlineedit = false; } if(visible == "false"){ visible = false; } else{ visible = true; } var column = new RouvenfoColumnObj(name, headertext, type, format, valuelist, template, classnames, width, click, visible, enablefilter, inlineedit); tableObj.columns.push(column); rouvenfo_table_add_column_to_header(tableObj, column); } function rouvenfo_table_add_column_edit(tableObj){ var item = $(document.createElement("span")); item.append(""); var column = new RouvenfoColumnObj("", null, null, null, null, item[0].innerHTML, "col-edit col-fa-img", 30, null, true, false); tableObj.columns.push(column); rouvenfo_table_add_column_to_header(tableObj, column); } function rouvenfo_table_add_column_delete(tableObj){ var item = $(document.createElement("span")); item.append(""); var column = new RouvenfoColumnObj("", null, null, null, null, item[0].innerHTML, "col-delete col-fa-img", 30, null, true, false); tableObj.columns.push(column); rouvenfo_table_add_column_to_header(tableObj, column); } /******************************************************************************* * rouvenfo_table_add_column_to_header * * Adds the column to the DOM table-header * * @param tableObj * @param element * * ****************************************************************************/ function rouvenfo_table_add_column_to_header(tableObj, columnObj){ if(!columnObj.visible){ return; } var item = $(document.createElement("span")); item.addClass(columnObj.classnames); item.addClass("rouvenfo-table-header-" + columnObj.dataname); item.attr("rouvenfo-data", columnObj.dataname); if(columnObj.width){ item.css("width", columnObj.width + "px"); } if(columnObj.headertext){ item.text(columnObj.headertext); } else{ item.append(" "); } if(columnObj.enablefilter){ item.append(""); } $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER_CONTAINER).append(item); } function rouvenfo_table_get_header_text(tableObj, columnId){ for(var i = 0; i < tableObj.columns.length; i++){ if(tableObj.columns[i].dataname == columnId){ return tableObj.columns[i].headertext; } } return ""; } /******************************************************************************* * rouvenfo_table_create_table_structure * * Creats the table structure in the DOM * * @param tableObj * * ****************************************************************************/ function rouvenfo_table_create_table_structure(tableObj){ rouvenfo_append_element_div_class_if_not_exists("#" + tableObj.table_id, ROUVENFO_TABLE_HEADER); rouvenfo_append_element_div_class_if_not_exists("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER, ROUVENFO_TABLE_HEADER_CONTAINER); rouvenfo_append_element_div_class_if_not_exists("#" + tableObj.table_id, ROUVENFO_TABLE_DATA_CLASS); rouvenfo_append_element_div_class_if_not_exists("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_CLASS, ROUVENFO_TABLE_DATA_SCROLL_CLASS); rouvenfo_append_element_div_class_if_not_exists("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_SCROLL_CLASS, ROUVENFO_TABLE_DATA_CONTAINER_CLASS); $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_SCROLL_CLASS).on( "scroll", {tableObj: tableObj}, function(event) { var scrollHeight = $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_CONTAINER_CLASS).height(); var scrollPosition = $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_SCROLL_CLASS).height() + $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_SCROLL_CLASS).scrollTop(); if ( scrollHeight - scrollPosition === 0 && !event.data.tableObj.page_no_more_data) { event.data.tableObj.page ++; rouvenfo_table_load_data(event.data.tableObj, true); } }); } /******************************************************************************* * rouvenfo_table_get_tableobj_by_id * * Gets the tableObj from the id * * @param table_id * * ****************************************************************************/ function rouvenfo_table_get_tableobj_by_id(table_id){ for(var i = 0; i < rouvenfo_tables.length; i++){ if(rouvenfo_tables[i].table_id == table_id){ return rouvenfo_tables[i]; } } return null; } /******************************************************************************* * rouvenfo_get_valuelist_byid * * Gets the valuelist from the id * * @param valuelist_id * * ****************************************************************************/ function rouvenfo_get_valuelist_byid(valuelist_id){ for(var i = 0; i < rouvenfo_valuelists.length; i++){ if(rouvenfo_valuelists[i].id == valuelist_id){ return rouvenfo_valuelists[i]; } } return null; } /******************************************************************************* * rouvenfo_table_load_data * * Loads the data from the api * * @param tableObj * @param appendData * * ****************************************************************************/ function rouvenfo_table_load_data(tableObj, appendData){ if(!appendData){ tableObj.page = 1; tableObj.page_no_more_data = false; } var url = tableObj.api_url; url += "?page_size=" + tableObj.page_size + "&page=" + tableObj.page; if(tableObj.get_filter){ url += "&" + tableObj.get_filter; } if(tableObj.filtertext){ url += "&filter=" + tableObj.filtertext; } for(var i = 0; i < tableObj.columns.length; i++){ if(tableObj.columns[i].filteractive && tableObj.columns[i].filtertext){ url += "&"; url += tableObj.columns[i].dataname + "=" + tableObj.columns[i].filtertext; isFilter = true; } else if(tableObj.columns[i].filteractive && tableObj.columns[i].filtervalue){ url += "&"; if(tableObj.columns[i].type == ROUVENFO_COLUMN_TYPES.DATE){ var dateParts = tableObj.columns[i].filtervalue.split('-'); if(dateParts[0] != "" && dateParts[1] != "" && dateParts[2] != ""){ url += tableObj.columns[i].dataname + "=" + tableObj.columns[i].filtervalue; } else{ var parts = []; if(dateParts[0] != ""){ parts.push(tableObj.columns[i].dataname + "_y=" + dateParts[0]); } if(dateParts[1] != ""){ parts.push(tableObj.columns[i].dataname + "_m=" + dateParts[1]); } if(dateParts[2] != ""){ parts.push(tableObj.columns[i].dataname + "_d=" + dateParts[2]); } url += parts.join("&"); } } else{ url += tableObj.columns[i].dataname + "=" + tableObj.columns[i].filtervalue; } } } $.get({ url: url, contentType: "application/json", success: function(data){ rouvenfo_table_show_data(data, tableObj, appendData); } }); } /******************************************************************************* * rouvenfo_table_show_data * * Shows the data * * @param data * @param tableObj * @param appendData * * ****************************************************************************/ function rouvenfo_table_show_data(data, tableObj, appendData){ if(!appendData){ $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_DATA_CONTAINER_CLASS).empty(); } if(tableObj.filter_column){ data = rouvenfo_table_data_sort(data, tableObj.filter_column, tableObj.filter_direction_asc, tableObj); rouvenfo_table_set_sort_icon(tableObj); } rouvenfo_table_set_filter_icon(tableObj); tableObj.table_data = data; for(i = 0; i < data.length; i++){ rouvenfo_table_add_row_element(tableObj, data[i]); } if(data.length < tableObj.page_size){ tableObj.page_no_more_data = true; } rouvenfo_table_select_current_row(tableObj); if(tableObj.after_load_callback){ tableObj.after_load_callback(); } } function rouvenfo_table_set_sort_icon(tableObj){ $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER_CONTAINER + " .rouvenfo-table-sort-icon").remove(); if(tableObj.filter_column){ if(tableObj.filter_direction_asc){ $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER_CONTAINER + " span.rouvenfo-table-header-" + tableObj.filter_column).append(""); } else{ $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER_CONTAINER + " span.rouvenfo-table-header-" + tableObj.filter_column).append(""); } } } function rouvenfo_table_set_filter_icon(tableObj){ for(var i = 0; i < tableObj.columns.length; i++){ if(tableObj.columns[i].filteractive){ $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER_CONTAINER + " span.rouvenfo-table-header-" + tableObj.columns[i].dataname + " .rouvenfo-header-filter-icon").css("display", "inline-block"); } else{ $("#" + tableObj.table_id + " ." + ROUVENFO_TABLE_HEADER_CONTAINER + " span.rouvenfo-table-header-" + tableObj.columns[i].dataname + " .rouvenfo-header-filter-icon").css("display", ""); } } } function rouvenfo_table_add_row_element(tableObj, rowdata){ var row = $(document.createElement("div")); row.addClass("rouvenfo-table-row"); if(tableObj.table_row_clicked){ row.click(tableObj.table_row_clicked); } else{ row.click(rouvenfo_table_row_clicked); } if(tableObj.row_doubleclicked_function){ row.on('dblclick', tableObj.row_doubleclicked_function); } for(var c = 0; c < tableObj.columns.length; c++){ var columnObj = tableObj.columns[c]; if(!columnObj.visible){ continue; } var split = columnObj.dataname.split("."); var apiValue = rowdata; while(split.length > 0){ apiValue = apiValue[split.shift()]; } if(columnObj.type == ROUVENFO_COLUMN_TYPES.DATE){ if(apiValue && !(apiValue instanceof Date)){ rowdata[columnObj.dataname] = new Date(apiValue); apiValue = rowdata[columnObj.dataname]; } } var valueToShow = rouvenfo_table_get_column_value(columnObj, apiValue); var col = $(document.createElement("span")); col.addClass(columnObj.classnames); col.addClass("rouvenfo-data-" + columnObj.dataname); if(columnObj.valuelist_id){ col.addClass("rouvenfo-data-" + columnObj.dataname + "-" + apiValue); } if(columnObj.width){ col.css("width", columnObj.width + "px"); } if(columnObj.click){ col.click([columnObj.click]); } if(columnObj.template){ col.append(columnObj.template); } else if(columnObj.inlineedit && columnObj.type == 6){ var checkbox = $(document.createElement("input")); checkbox.attr("type", "checkbox"); checkbox.css("cursor", "pointer"); checkbox.prop('checked', apiValue); checkbox.change({table_id: tableObj.table_id, columnname: columnObj.dataname, id: rowdata[tableObj.id_columnname]}, function(event) { var tableObj = rouvenfo_table_get_tableobj_by_id(event.data.table_id); var value = $(event.target).is(":checked"); var rowData = null; for(var i = 0; i < tableObj.table_data.length; i++){ if(tableObj.table_data[i][tableObj.id_columnname] == event.data.id){ rowData = tableObj.table_data[i]; i = tableObj.table_data.length; } } rowData[event.data.columnname] = value; console.log(rowData); $.ajax({ type: "PUT", url: tableObj.api_url + "/" + event.data.id, data: JSON.stringify(rowData) }); }); col.append(checkbox); } else{ col.html(valueToShow); } row.append(col); } if(tableObj.table_row_class){ row.addClass(tableObj.table_row_class(rowdata)); } $("#" + tableObj.table_id + " .rouvenfo-table-data-container").append(row); } function rouvenfo_table_get_column_value(columnObj, value){ if(columnObj.valuelist_id){ return rouvenfo_get_valuelist_value(columnObj.valuelist_id, value); } if(columnObj.type == ROUVENFO_COLUMN_TYPES.CURRENCY){ return Intl.NumberFormat('de-CH', { style: 'currency', currency: 'CHF' }).format(value); } else if(columnObj.type == ROUVENFO_COLUMN_TYPES.BOOLEAN){ if(value){ return ""; } else{ return ""; } } else if(columnObj.type == ROUVENFO_COLUMN_TYPES.DATE){ if(value){ return ("0" + value.getDate()).slice(-2) + "." + ("0"+(value.getMonth()+1)).slice(-2) + "." + value.getFullYear(); } return ""; } return value; } /******************************************************************************* * rouvenfo_table_data_sort * * Sorts the data with the given column name * * @param data * @param column_name * @param sort_asc * * ****************************************************************************/ function rouvenfo_table_data_sort(data, column_name, sort_asc, tableObj){ var columnObj = null; for(var c = 0; c < tableObj.columns.length; c++){ if(tableObj.columns[c].dataname == column_name){ columnObj = tableObj.columns[c]; } } for(var i = 0; i < data.length; i++){ for(var k = i + 1; k < data.length; k++){ if(data[i][column_name] > data[k][column_name] && sort_asc || data[i][column_name] < data[k][column_name] && !sort_asc){ var temp = data[i]; data[i] = data[k]; data[k] = temp; } } } return data; } /******************************************************************************* * rouvenfo_get_valuelist_value * * Gets the value of the valuelist * * @param valuelist_id * @param id * * ****************************************************************************/ function rouvenfo_get_valuelist_value(valuelist_id, id){ var valuelist = rouvenfo_get_valuelist_byid(valuelist_id); if(valuelist == null) return ""; for(var k = 0; k < valuelist.data.length; k++){ if(valuelist.data[k].id == id){ return valuelist.data[k].value; } } return ""; } function rouvenfo_table_select_current_row(tableObj){ var rows = $("#" + tableObj.table_id + " .rouvenfo-table-row"); if(tableObj.selected_row_index >= rows.length){ tableObj.selected_row_index = -1; } if(tableObj.selected_row_index == -1 && rows.length > 0){ tableObj.selected_row_index = 0; } if(tableObj.selected_row_index >= 0){ rows[tableObj.selected_row_index].classList.add("selected-row"); if(tableObj.table_row_clicked){ tableObj.table_row_clicked(); } } } function rouvenfo_table_row_clicked(el){ var id = ""; var parent = el.target.parentNode; while(parent !== null && (parent.classList === null || !parent.classList.contains("rouvenfo-table"))){ parent = parent.parentNode; } if(!parent){ return; } var tableObj = rouvenfo_table_get_tableobj_by_id(parent.id); rouvenfo_table_clear_selected_rows(tableObj); parent = el.target; while(parent !== null && (parent.classList === null || !parent.classList.contains("rouvenfo-table-row"))){ parent = parent.parentNode; } tableObj.selected_row_index = rouvenfo_get_child_index(parent); parent.classList.add("selected-row"); } function rouvenfo_table_save_record(tableObj, contentId){ var obj = rouvenfo_table_get_record_object(tableObj, contentId); if(tableObj.beforeSave){ tableObj.beforeSave(obj); } if(tableObj.is_new_record){ $.ajax({ type: "POST", url: tableObj.api_url, data: JSON.stringify(obj), success: function(){ rouvenfo_close_current_window(); tableObj.is_new_record = false; rouvenfo_table_load_data(tableObj); } }); } else{ var dataRow = tableObj.table_data[tableObj.selected_row_index]; for(var c = 0; c < tableObj.columns.length; c++){ var columnName = tableObj.columns[c].dataname; if(obj[columnName] !== undefined){ dataRow[columnName] = obj[columnName]; } } $.ajax({ type: "PUT", url: tableObj.api_url + "/" + dataRow[tableObj.id_columnname], data: JSON.stringify(dataRow), success: function(){ rouvenfo_close_current_window(); rouvenfo_table_load_data(tableObj); } }); } } function rouvenfo_table_clear_selected_rows(tableObj){ var rows = $("#" + tableObj.table_id + " .rouvenfo-table-row"); rows.removeClass("selected-row"); } function rouvenfo_table_bind_window_data(tableObj, contentId){ var el = $("#" + contentId); var dataRow = tableObj.table_data[tableObj.selected_row_index]; for(var c = 0; c < tableObj.columns.length; c++){ rouvenfo_table_window_bind_set_column_value(el, tableObj.columns[c], dataRow[tableObj.columns[c].dataname]); } tableObj.is_new_record = false; } function rouvenfo_delete_selected_record(tableObj){ show_dialog_yes_no("Löschen", "Bist du sicher, dass du diesen Datensatz löschen möchtest?", "rouvenfo_delete_selected_record_yes('" + tableObj.table_id + "')", "rouvenfo_delete_selected_record_no('" + tableObj.table_id + "')"); } function rouvenfo_delete_selected_record_yes(tableId){ rouvenfo_close_current_window(); var tableObj = rouvenfo_table_get_tableobj_by_id(tableId); console.log(tableObj); $.ajax({ type: "DELETE", url: tableObj.api_url + "/" + tableObj.table_data[tableObj.selected_row_index][tableObj.id_columnname], success: function(){ rouvenfo_table_load_data(tableObj); } }); console.log(tableObj.selected_row_index); } function rouvenfo_delete_selected_record_no(tableId){ rouvenfo_close_current_window(); } function rouvenfo_clear_record(tableObj, contentId){ var el = $("#" + contentId); for(var c = 0; c < tableObj.columns.length; c++){ rouvenfo_table_window_bind_set_column_value(el, tableObj.columns[c], null); } } function rouvenfo_table_get_record_object(tableObj, contentId){ var el = $("#" + contentId); var obj = {}; for(var c = 0; c < tableObj.columns.length; c++){ var val = rouvenfo_table_window_bind_get_column_value(el, tableObj.columns[c]); if(val != null){ obj[tableObj.columns[c].dataname] = val; } } return obj; } function rouvenfo_table_window_bind_get_element(windowElement, columnObj){ if(!columnObj.dataname){ return null; } var element = windowElement.find("input[rouvenfo-data='" + columnObj.dataname + "']"); if(element.length > 0){ return element; } element = windowElement.find("span[rouvenfo-data='" + columnObj.dataname + "']"); if(element.length > 0){ return element; } element = windowElement.find("div[rouvenfo-data='" + columnObj.dataname + "'].rouvenfo-combobox"); if(element.length > 0){ return element; } element = windowElement.find("div[rouvenfo-data='" + columnObj.dataname + "'].rouvenfo-typeahead"); if(element.length > 0){ return element; } element = windowElement.find("div[rouvenfo-data='" + columnObj.dataname + "']"); if(element.length > 0){ return element; } return null; } function rouvenfo_table_window_bind_get_column_value(windowElement, columnObj){ var element = rouvenfo_table_window_bind_get_element(windowElement, columnObj); if(!element){ return null; } if(element.hasClass("rouvenfo-combobox")){ return rouvenfo_get_combobox_current_id(element.attr("id")); } if(element.hasClass("rouvenfo-typeahead")){ return rouvenfo_get_combobox_current_id(element.attr("id")); } if(element.is(':checkbox')){ return element.is(":checked"); } if(columnObj.type == ROUVENFO_COLUMN_TYPES.DATE){ var date = element.val(); if(!date){ return null; } var dateSplit = date.split("."); if(dateSplit.length != 3){ return null; } return dateSplit[2] + "-" + dateSplit[1] + "-" + dateSplit[0]; } return element.val(); } function rouvenfo_table_window_bind_set_column_value(windowElement, columnObj, value){ var element = rouvenfo_table_window_bind_get_element(windowElement, columnObj); if(!element){ return; } if(element.hasClass("rouvenfo-combobox")){ rouvenfo_set_combobox_current_id(element.attr("id"), value); return; } if(element.hasClass("rouvenfo-typeahead")){ rouvenfo_set_combobox_current_id(element.attr("id"), value); return; } if(element.is(':checkbox')){ element.prop('checked', value); return; } if(columnObj.type == ROUVENFO_COLUMN_TYPES.DATE){ if(!value){ element.val(value); return; } element.val(("0" + value.getDate()).slice(-2) + "." + ("0"+(value.getMonth()+1)).slice(-2) + "." + value.getFullYear()); return; } element.val(value); } function rouvenfo_table_header_clicked(event){ var col = event.target.getAttribute("rouvenfo-data"); if(!col){ return; } var tableObj = rouvenfo_table_get_tableobj_from_element(event.target); if(tableObj.filter_column == col){ tableObj.filter_direction_asc = !tableObj.filter_direction_asc; } else{ tableObj.filter_column = col; tableObj.filter_direction_asc = true; } rouvenfo_table_show_data(tableObj.table_data, tableObj); } function rouvenfo_table_get_tableobj_from_element(element){ var id = ""; while(element !== null && (element.classList === null || !element.classList.contains("rouvenfo-table"))){ element = element.parentNode; } if(!element){ return null; } return rouvenfo_table_get_tableobj_by_id(element.id); }/******************************************************************************* * ATTRIBUTES * ****************************************************************************/ var rouvenfo_comboboxes = []; const ROUVENFO_COMBOBOX_TYPE = { COMBOBOX: 1, TYPEAHEAD: 2 } /******************************************************************************* * Window Ready * ****************************************************************************/ $(function() { $("body").click(function(event){ rouvenfo_combobox_close_all(); }); }); function rouvenfo_combobox_close_all(){ for(var i=0; i < rouvenfo_comboboxes.length; i++){ if(rouvenfo_comboboxes[i].is_open){ $("#" + rouvenfo_comboboxes[i].id + "-list").hide(); $("#" + rouvenfo_comboboxes[i].id).removeClass("rouvenfo-combobox-focused"); rouvenfo_comboboxes[i].is_open = false; } } } /******************************************************************************* * rouvenfo_add_combobox * * Adds a new Combobox * * @param id -> The html id of the combobox * @param values -> Array of id,values pair {id: string, value: string} * @param init_id -> The value which is selected and shown at beginning * * ****************************************************************************/ function rouvenfo_add_combobox(id, values, init_id, onDataChanged){ var cmb = document.createElement("div"); cmb.classList.add("rouvenfo-combobox-list"); cmb.id = id + "-list"; cmb.style.display = "none"; $("#" + id).append(""); $("#" + id).append(""); $("#" + id).addClass("rouvenfo-combobox"); var init_value = null; for(var i = 0; i < values.length; i++){ if(init_id == values[i].id){ init_value = values[i].value; } } var obj ={ current_id: init_id, current_value: init_value, id: id, is_open: false, values: values, type: ROUVENFO_COMBOBOX_TYPE.COMBOBOX, onDataChanged: onDataChanged }; rouvenfo_comboboxes.push(obj); $("#" + id + " .rouvenfo-combobox-content-text").text(init_value); $("#" + id).click(rouvenfo_combobox_clicked); $("#" + id).after(cmb); rouvenfo_combobox_set_html_items(obj, values); $("#" + id + "-list .rouvenfo-combobox-list-item").click({id: id}, rouvenfo_combobox_list_item_clicked); } function rouvenfo_add_typeahead(id, values, init_id){ var cmb = document.createElement("div"); cmb.classList.add("rouvenfo-typeahead-list"); cmb.id = id + "-list"; cmb.style.display = "none"; $("#" + id).append(""); $("#" + id).addClass("rouvenfo-typeahead"); $("#" + id).on("input", {id: id}, rouvenfo_typeahead_value_changed); $("#" + id).on("focusout", {id: id}, rouvenfo_typeahead_focusout); var init_value = null; for(var i = 0; i < values.length; i++){ if(init_id == values[i].id){ init_value = values[i].value; } } var obj = { current_id: init_id, current_value: init_value, id: id, is_open: false, values: values, type: ROUVENFO_COMBOBOX_TYPE.TYPEAHEAD }; rouvenfo_comboboxes.push(obj); $("#" + id).val(init_value); $("#" + id).click(rouvenfo_combobox_clicked); $("#" + id).on("focusin", {id: id}, rouvenfo_combobox_clicked); $("#" + id).after(cmb); rouvenfo_combobox_set_html_items(obj, values); $("#" + id + "-list .rouvenfo-typeahead-list-item").click({id: id}, rouvenfo_combobox_list_item_clicked); } function rouvenfo_combobox_remove(id){ $("#" + id + "-list").remove(); $("#" + id + " .rouvenfo-combobox-content-text").remove(); $("#" + id + " i").remove(); for(var i = 0; i < rouvenfo_comboboxes.length; i++){ if(rouvenfo_comboboxes[i].id == id){ rouvenfo_comboboxes.splice(i, 1); return; } } } function rouvenfo_combobox_update_values(id, values, newId){ var cmbObj = rouvenfo_get_combobox_by_id(id); cmbObj.values = values; rouvenfo_combobox_set_html_items(cmbObj, values); var init_value = null; for(var i = 0; i < values.length; i++){ if(newId == values[i].id){ init_value = values[i].value; } } cmbObj.values = init_value; cmbObj.current_id = newId; $("#" + id + " .rouvenfo-combobox-content-text").text(init_value); if(cmbObj.onDataChanged){ cmbObj.onDataChanged(cmbObj.current_id, cmbObj.values); } } function rouvenfo_typeahead_value_changed(event){ console.log(event); var currentCombobox = rouvenfo_get_combobox_by_id(event.data.id); if(!currentCombobox){ return; } var value = $("#" + currentCombobox.id).val(); for(var i = 0; i < currentCombobox.values.length; i++){ if(currentCombobox.values[i].value.toLowerCase().startsWith(value.toLowerCase())){ console.log("show"); $("#" + currentCombobox.id + "-list .rouvenfo-typeahead-list-item[id=" + currentCombobox.values[i].id + "]").show(); } else{ console.log("hide"); $("#" + currentCombobox.id + "-list .rouvenfo-typeahead-list-item[id=" + currentCombobox.values[i].id + "]").hide(); } } } function rouvenfo_typeahead_focusout(event){ var currentCombobox = rouvenfo_get_combobox_by_id(event.data.id); if(!currentCombobox){ return; } $("#" + currentCombobox.id).val(currentCombobox.current_value); } function rouvenfo_combobox_set_html_items(cmb, values){ $("#" + cmb.id + "-list").empty(); for(var i = 0; i < values.length; i++){ var item = document.createElement("div"); if(cmb.type == ROUVENFO_COMBOBOX_TYPE.TYPEAHEAD){ item.classList.add("rouvenfo-typeahead-list-item"); } else{ item.classList.add("rouvenfo-combobox-list-item"); } item.innerHTML = values[i].value; item.setAttribute("id", values[i].id); document.getElementById(cmb.id + "-list").appendChild(item); } } /******************************************************************************* * rouvenfo_combobox_clicked * * When on the comobox self is clicked * * @param event * * ****************************************************************************/ function rouvenfo_combobox_clicked(event){ rouvenfo_combobox_close_all(); var currentNode = event.target; while(currentNode && !currentNode.id){ currentNode = currentNode.parentNode; } var currentCombobox = rouvenfo_get_combobox_by_id(currentNode.id); if(!currentCombobox){ return; } if(currentCombobox.type == ROUVENFO_COMBOBOX_TYPE.TYPEAHEAD){ $("#" + currentCombobox.id).val(""); $("#" + currentCombobox.id + "-list .rouvenfo-typeahead-list-item").show(); } $("#" + currentNode.id + "-list").css("left", currentNode.offsetLeft); $("#" + currentNode.id).addClass("rouvenfo-combobox-focused"); for(var i = 0; i < rouvenfo_comboboxes.length; i++){ if(rouvenfo_comboboxes[i].id == currentNode.id){ rouvenfo_comboboxes[i].is_open = true; } } $("#" + currentNode.id + "-list").show(); event.stopPropagation(); } /******************************************************************************* * rouvenfo_combobox_list_item_clicked * * When on a item of the comobox is clicked * * @param event * * ****************************************************************************/ function rouvenfo_combobox_list_item_clicked(event){ var currentCombobox = rouvenfo_get_combobox_by_id(event.data.id); if(!currentCombobox){ return; } if(currentCombobox.type == ROUVENFO_COMBOBOX_TYPE.COMBOBOX){ $("#" + currentCombobox.id + " .rouvenfo-combobox-content-text").text(event.target.innerHTML); } else if(currentCombobox.type == ROUVENFO_COMBOBOX_TYPE.TYPEAHEAD){ $("#" + currentCombobox.id).val(event.target.innerHTML); } for(var i = 0; i < rouvenfo_comboboxes.length; i++){ if(rouvenfo_comboboxes[i].id == event.data.id){ rouvenfo_comboboxes[i].current_id = event.target.id; rouvenfo_comboboxes[i].current_value = event.target.innerHTML; rouvenfo_comboboxes[i].is_open = false; $("#" + rouvenfo_comboboxes[i].id).removeClass("rouvenfo-combobox-focused"); if(rouvenfo_comboboxes[i].onDataChanged){ rouvenfo_comboboxes[i].onDataChanged(rouvenfo_comboboxes[i].current_id, rouvenfo_comboboxes[i].current_value); } } } $("#" + event.data.id + "-list").hide(); } /******************************************************************************* * rouvenfo_get_combobox_current_id * * Gets the current id of the param id combobox * * @param id -> Html Id of the combobox * * ****************************************************************************/ function rouvenfo_get_combobox_current_id(id){ for(var i = 0; i < rouvenfo_comboboxes.length; i++){ if(rouvenfo_comboboxes[i].id == id){ return rouvenfo_comboboxes[i].current_id; } } return null; } function rouvenfo_get_combobox_by_id(id){ for(var i = 0; i < rouvenfo_comboboxes.length; i++){ if(rouvenfo_comboboxes[i].id == id){ return rouvenfo_comboboxes[i]; } } return null; } function rouvenfo_set_combobox_current_id(comboboxId, id){ var currentCombobox = rouvenfo_get_combobox_by_id(comboboxId); if(!currentCombobox){ return; } currentCombobox.current_id = null; currentCombobox.current_value = ""; for(var i = 0; i < currentCombobox.values.length; i++){ if(id == currentCombobox.values[i].id){ currentCombobox.current_id = currentCombobox.values[i].id; currentCombobox.current_value = currentCombobox.values[i].value; } } if(currentCombobox.type == ROUVENFO_COMBOBOX_TYPE.COMBOBOX){ $("#" + comboboxId + " .rouvenfo-combobox-content-text").text(currentCombobox.current_value); } else if(currentCombobox.type == ROUVENFO_COMBOBOX_TYPE.TYPEAHEAD){ $("#" + comboboxId).val(currentCombobox.current_value); } }/******************************************************************************* * ATTRIBUTES * ****************************************************************************/ var rouvenfo_current_window_id = null; /******************************************************************************* * open_new_window * * @param window_id -> Id of the window * @param title -> title of the window * @param height -> optional: height of the window * @param width -> optional: width of the window * * Opens the new window. * * ****************************************************************************/ function rouvenfo_open_new_window(window_id, title, height, width){ if(rouvenfo_current_window_id) return; rouvenfo_current_window_id = window_id; if($("#rouvenfo-window-full-background").length === 0){ $('body').append($('
', { id: 'rouvenfo-window-full-background' })); } if($("#" + rouvenfo_current_window_id).length === 0){ $('body').append($('
', { id: rouvenfo_current_window_id })); } $("#rouvenfo-window-full-background").css("display", "block"); $("#" + rouvenfo_current_window_id).css("display", "block"); if($("#" + rouvenfo_current_window_id + " .rouvenfo-window-title").length === 0){ $("#" + rouvenfo_current_window_id).prepend($('
', { class: 'rouvenfo-window-title' })); } if($("#" + rouvenfo_current_window_id + " .rouvenfo-window-title .rouvenfo-window-title-text").length === 0){ $("#" + rouvenfo_current_window_id + " .rouvenfo-window-title").append($('', { class: 'rouvenfo-window-title-text' })); } if($("#" + rouvenfo_current_window_id + " .rouvenfo-window-title .rouvenfo-window-title-close").length === 0){ $("#" + rouvenfo_current_window_id + " .rouvenfo-window-title").append($('', { class: 'rouvenfo-window-title-close' , onclick: 'rouvenfo_close_current_window()' })); $("#" + rouvenfo_current_window_id + " .rouvenfo-window-title .rouvenfo-window-title-close").append($('', { class: 'far fa-x' })); } $("#" + rouvenfo_current_window_id + " .rouvenfo-window-title .rouvenfo-window-title-text").text(title); $("#" + rouvenfo_current_window_id).addClass("rouvenfo-window"); if(height){ $("#" + rouvenfo_current_window_id).css("height", height); } if(width){ $("#" + rouvenfo_current_window_id).css("width", width); } } /******************************************************************************* * close_window_clicked * * Closes the current window. * * ****************************************************************************/ function rouvenfo_close_current_window(){ if(!rouvenfo_current_window_id) return; $("#rouvenfo-window-full-background").css("display", "none"); $("#" + rouvenfo_current_window_id).css("display", "none"); rouvenfo_current_window_id = null; } function show_dialog_yes_no(title, text, rouvenfo_window_yes_callback, rouvenfo_window_no_callback){ if($("#rouvenfo_yes_no_dialog").length === 0){ $('body').append($('
', { id: 'rouvenfo_yes_no_dialog' })); $("#rouvenfo_yes_no_dialog").append($('
', { class: 'rouvenfo-window-content' })); $("#rouvenfo_yes_no_dialog").append($('
', { class: 'rouvenfo-window-footer' })); $("#rouvenfo_yes_no_dialog .rouvenfo-window-footer").append($('', { class: 'rouvenfo-window-control-no button', onclick: rouvenfo_window_no_callback })); $("#rouvenfo_yes_no_dialog .rouvenfo-window-footer .rouvenfo-window-control-no").text("Nein"); $("#rouvenfo_yes_no_dialog .rouvenfo-window-footer").append($('', { class: 'rouvenfo-window-control-yes button button-primary', onclick: rouvenfo_window_yes_callback })); $("#rouvenfo_yes_no_dialog .rouvenfo-window-footer .rouvenfo-window-control-yes").text("Ja"); } $("#rouvenfo_yes_no_dialog .rouvenfo-window-content").text(text); rouvenfo_open_new_window("rouvenfo_yes_no_dialog", title); } function show_dialog_ok(title, text, rouvenfo_window_ok_callback){ if($("#rouvenfo_yes_no_dialog").length === 0){ $('body').append($('
', { id: 'rouvenfo_ok_dialog' })); $("#rouvenfo_ok_dialog").append($('
', { class: 'rouvenfo-window-content' })); $("#rouvenfo_ok_dialog").append($('
', { class: 'rouvenfo-window-footer' })); $("#rouvenfo_ok_dialog .rouvenfo-window-footer").append($('', { class: 'rouvenfo-window-control-ok button button-primary' })); $("#rouvenfo_ok_dialog .rouvenfo-window-footer .rouvenfo-window-control-ok").text("Ok"); $("#rouvenfo_ok_dialog .rouvenfo-window-footer .rouvenfo-window-control-ok").on( "click", function() { rouvenfo_close_current_window(); if(rouvenfo_window_ok_callback){ rouvenfo_window_ok_callback(); } }); } $("#rouvenfo_ok_dialog .rouvenfo-window-content").text(text); rouvenfo_open_new_window("rouvenfo_ok_dialog", title); }function rouvenfo_filter_column(table_id, column_name){ var tableObj = rouvenfo_table_get_tableobj_by_id(table_id); for(var i = 0; i < tableObj.columns.length; i++){ if(tableObj.columns[i].dataname == column_name){ var text = ""; var value = ""; if(tableObj.columns[i].filtertext){ text = tableObj.columns[i].filtertext; } if(tableObj.columns[i].filtervalue){ value = tableObj.columns[i].filtervalue; } if($("#rouvenfo-window-table-filter").length === 0){ $("body").append($('
', { id: 'rouvenfo-window-table-filter' })); } $("#rouvenfo-window-table-filter").empty(); $("#rouvenfo-window-table-filter").append("
"); if(tableObj.columns[i].valuelist_id != null){ var valueSplit = value.split(";"); if(value == ""){ valueSplit = []; } for(var s = 0; s < valueSplit.length; s++){ $("#rouvenfo-window-table-filter-container").append("
"); rouvenfo_add_combobox("rouvenfo-window-table-filter-valuelist" + s, rouvenfo_get_valuelist_byid(tableObj.columns[i].valuelist_id).data, valueSplit[s]); $("#rouvenfo-window-table-filter-valuelist" + s + "-list").on("click", {valuelist_id: tableObj.columns[i].valuelist_id}, function(event){ onComboboxItemClicked(event); }); } $("#rouvenfo-window-table-filter-container").append("
"); rouvenfo_add_combobox("rouvenfo-window-table-filter-valuelist" + s, rouvenfo_get_valuelist_byid(tableObj.columns[i].valuelist_id).data, null); $("#rouvenfo-window-table-filter-valuelist" + s + "-list").on("click", {valuelist_id: tableObj.columns[i].valuelist_id}, function(event){ onComboboxItemClicked(event); }); } else if(tableObj.columns[i].type == ROUVENFO_COLUMN_TYPES.DATE){ var valueSplit = value.split("-"); if(value == ""){ valueSplit = ["","",""]; } var year = valueSplit[0]; var month = valueSplit[1]; var day = valueSplit[2]; $("#rouvenfo-window-table-filter-container").append("Tag"); $("#rouvenfo-window-table-filter-container").append(""); $("#rouvenfo-window-table-filter-container").append("Monat"); $("#rouvenfo-window-table-filter-container").append(""); $("#rouvenfo-window-table-filter-container").append("Jahr"); $("#rouvenfo-window-table-filter-container").append(""); } else{ $("#rouvenfo-window-table-filter-container").append(""); } var buttonCont = document.createElement("div"); $(buttonCont).addClass("rouvenfo-table-filter-button-container"); $(buttonCont).append(""); $(buttonCont).append(""); $("#rouvenfo-window-table-filter").append(buttonCont); rouvenfo_open_new_window("rouvenfo-window-table-filter", "Filter", null, 240); } } } function rouvenfo_filter_submit(table_id, column_name){ var tableObj = rouvenfo_table_get_tableobj_by_id(table_id); for(var i = 0; i < tableObj.columns.length; i++){ if(tableObj.columns[i].dataname == column_name){ var value = null; var text = null; if(tableObj.columns[i].valuelist_id != null){ var valueList = []; for(var k = 0; k < 100; k++){ if($("#rouvenfo-window-table-filter-valuelist" + k).length != 0){ if(rouvenfo_get_combobox_by_id("rouvenfo-window-table-filter-valuelist" + k).current_id != null){ valueList.push(rouvenfo_get_combobox_by_id("rouvenfo-window-table-filter-valuelist" + k).current_id); } rouvenfo_combobox_remove("rouvenfo-window-table-filter-valuelist" + k); } } value = valueList.join(";"); } else if(tableObj.columns[i].type == ROUVENFO_COLUMN_TYPES.DATE){ var day = $("#rouvenfo-window-table-filter-input-day").val(); var month = $("#rouvenfo-window-table-filter-input-month").val(); var year = $("#rouvenfo-window-table-filter-input-year").val(); value = year + "-" + month + "-" + day; } else{ text = $("#rouvenfo-window-table-filter-input").val(); } if(value != ""){ tableObj.columns[i].filteractive = true; tableObj.columns[i].filtertext = text; tableObj.columns[i].filtervalue = value; } else{ tableObj.columns[i].filteractive = false; tableObj.columns[i].filtertext = null; tableObj.columns[i].filtervalue = null; } } } rouvenfo_close_current_window(); rouvenfo_table_load_data(tableObj); } function rouvenfo_filter_delete(table_id, column_name){ var tableObj = rouvenfo_table_get_tableobj_by_id(table_id); for(var i = 0; i < tableObj.columns.length; i++){ if(tableObj.columns[i].dataname == column_name){ tableObj.columns[i].filteractive = false; tableObj.columns[i].filtertext = null; tableObj.columns[i].filtervalue = null; for(var k = 0; k < 100; k++){ if($("#rouvenfo-window-table-filter-valuelist" + k).length != 0){ rouvenfo_combobox_remove("rouvenfo-window-table-filter-valuelist" + k); } } } } rouvenfo_close_current_window(); rouvenfo_table_load_data(tableObj); } function onComboboxItemClicked(event){ for(var k = 0; k < 100; k++){ if($("#rouvenfo-window-table-filter-valuelist" + k).length == 0){ if(rouvenfo_get_combobox_by_id("rouvenfo-window-table-filter-valuelist" + (k-1)).current_id != null){ $("#rouvenfo-window-table-filter-container").append("
"); rouvenfo_add_combobox("rouvenfo-window-table-filter-valuelist" + k, rouvenfo_get_valuelist_byid(event.data.valuelist_id).data, null); $("#rouvenfo-window-table-filter-valuelist" + k + "-list").on("click", {valuelist_id: event.data.valuelist_id}, function(event){ onComboboxItemClicked(event); }); } k = 100; } } }var crudTableObj = null; function rouvenfo_table_crud_add_form(paramObj, loadData){ crudTableObj = paramObj; if(!crudTableObj.form_id){ crudTableObj.form_id = crudTableObj.id + "-container"; } if(!crudTableObj.column_template_id){ crudTableObj.column_template_id = crudTableObj.id + "-template-columns"; } if(!crudTableObj.edit_template_id){ crudTableObj.edit_template_id = crudTableObj.id + "-template-edit"; } var form = $("#" + paramObj.form_id); rouvenfo_table_crud_add_toolbar(paramObj, form); form.append("
"); crudTableObj.tableObj = new RouvenfoTableObj(); crudTableObj.tableObj.edit_template_id = paramObj.edit_template_id; crudTableObj.tableObj.table_id = "tbl-" + paramObj.form_id; crudTableObj.tableObj.column_template_id = paramObj.column_template_id; crudTableObj.tableObj.api_url = paramObj.api_url; crudTableObj.tableObj.row_doubleclicked_function = rouvenfo_table_crud_open_window_edit; //tableObj.after_load_callback = table_member_after_load; crudTableObj.tableObj.filter_column = paramObj.filter_column; crudTableObj.tableObj.show_edit_row = paramObj.can_edit; crudTableObj.tableObj.show_delete_row = paramObj.can_delete; crudTableObj.tableObj.row_edit_function = "rouvenfo_table_crud_open_window_edit(event)"; crudTableObj.tableObj.row_delete_function = "rouvenfo_delete_selected_record(crudTableObj.tableObj)"; crudTableObj.tableObj.beforeSave = paramObj.beforeSave; crudTableObj.tableObj.get_filter = paramObj.get_filter; //tableObj.table_row_clicked = table_member_row_clicked; //tableObj.table_row_class = table_member_set_row_inactive_class; rouvenfo_table_add_table(crudTableObj.tableObj, loadData == null ? true : loadData); } function rouvenfo_table_crud_open_window_edit(el){ rouvenfo_table_row_clicked(el); rouvenfo_open_new_window(crudTableObj.tableObj.edit_template_id + "-window", "Bearbeiten", null, 540); rouvenfo_table_bind_window_data(crudTableObj.tableObj, crudTableObj.tableObj.edit_template_id + "-content"); } function rouvenfo_table_crud_add_toolbar(paramObj, form){ var toolbar = $(document.createElement("div")); toolbar.addClass("rouvenfo-crud-toolbar"); rouvenfo_table_crud_add_new_button(paramObj, toolbar); rouvenfo_table_crud_add_search(paramObj, toolbar) form.append(toolbar); } function rouvenfo_table_crud_add_new_button(paramObj, toolbar){ if(paramObj.can_add){ var button = $(document.createElement("button")); button.addClass("rouvenfo-crud-toolbar-button"); button.addClass("rouvenfo-crud-toolbar-button-create"); button.on("click", rouvenfo_table_crud_open_create); button.id = "rouvenfo-create-" + paramObj.form_id; var icon = $(document.createElement("i")); icon.addClass("fa-regular fa-plus-circle"); button.append(icon); toolbar.append(button); } } function rouvenfo_table_crud_add_search(paramObj, toolbar){ if(paramObj.can_search){ var search = $(document.createElement("div")); search.attr("id", "rouvenfo-toolbar-search-container"); var input = $(document.createElement("input")); input.attr("id", "rouvenfo-toolbar-tb-search"); input.on("keypress", function(e) { if (e.keyCode == 13) { rouvenfo_table_crud_filter(); } }); search.append(input); var button = $(document.createElement("button")); button.addClass("rouvenfo-crud-toolbar-button button-primary"); button.on("click", rouvenfo_table_crud_filter); button.attr("id", "rouvenfo-toolbar-btn-search"); var icon = $(document.createElement("i")); icon.addClass("fa-regular fa-magnifying-glass"); button.append(icon); search.append(button); toolbar.append(search); } } function rouvenfo_table_crud_open_create(){ rouvenfo_open_new_window(crudTableObj.tableObj.edit_template_id + "-window", "Neuer Datensatz", null, 540); rouvenfo_clear_record(crudTableObj.tableObj, crudTableObj.tableObj.edit_template_id + "-content"); crudTableObj.tableObj.is_new_record = true; if(crudTableObj.afterNewRecord){ crudTableObj.afterNewRecord(); } } function rouvenfo_table_crud_filter(){ crudTableObj.tableObj.filtertext = $("#rouvenfo-toolbar-tb-search").val(); rouvenfo_table_load_data(crudTableObj.tableObj); } function table_member_after_load(){ /*var vlData = rouvenfo_get_valuelist_byid("status"); for(var i = 0; i < vlData.data.length; i++){ $("#table-members .rouvenfo-data-status-" + vlData.data[i].id + " .col-status-inner").css("background", "#" + vlData.data[i].color_code_hex); $("#table-members .rouvenfo-data-status-" + vlData.data[i].id + " .col-status-inner").text(vlData.data[i].value); } $("#table-members .rouvenfo-inactive")*/ } function rouvenfo_table_crud_save(){ rouvenfo_table_save_record(crudTableObj.tableObj, crudTableObj.tableObj.edit_template_id + "-content"); } function export_member(){ /*if(memberTableObj.table_data.length == 0){ return; } var processRow = function (row) { var finalVal = ''; for (var prop in row) { if (Object.prototype.hasOwnProperty.call(row, prop)) { if(row[prop]){ if(prop == "status"){ finalVal += rouvenfo_get_valuelist_value("status", row[prop]) + ";"; } else if(prop == "sex"){ finalVal += rouvenfo_get_valuelist_value("sex", row[prop]) + ";"; } else{ finalVal += row[prop].toString().replaceAll('\n', ',').replaceAll('\r', '') + ";"; } } else{ finalVal += ";"; } } } return finalVal + '\n'; }; var csvFile = "\uFEFF"; //header data for (var prop in memberTableObj.table_data[0]) { if (Object.prototype.hasOwnProperty.call(memberTableObj.table_data[0], prop)) { csvFile += rouvenfo_table_get_header_text(memberTableObj, prop.toString()) + ";"; } } csvFile += "\n"; for (var i = 0; i < memberTableObj.table_data.length; i++) { csvFile += processRow(memberTableObj.table_data[i]); } var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' }); var url = URL.createObjectURL(blob); var link = document.createElement("a"); link.setAttribute("href", url); link.setAttribute("download", "mitglieder.csv"); document.body.appendChild(link); link.click(); document.body.removeChild(link);*/ } function table_member_set_row_inactive_class(rowdata){ /*if(rowdata["is_active"] == 0){ return "member-inactive"; } return "";*/ } function memberStatusChanged(){ //$("#member-edit-stvstatus").val(rouvenfo_get_combobox_by_id("member-edit-status").current_value); }function RouvenfoCrudTableParamObj(){ this.id = null; this.form_id = null; this.column_template_id = null; this.edit_template_id = null; this.api_url = null; this.get_filter = null; this.can_edit = true; this.can_add = true; this.can_delete = true; this.can_export = true; this.can_search = true; this.filter_column = null; this.tableObj = null; }var menuMobileActive = false; var rouvenfo_navigation_items = []; var rouvenfo_navigation_pathList = []; var rouvenfo_navigation_prefix_style = "rouvenfo-navigation"; var rouvenfo_navigation_domain = null; function rouvenfo_navigation_navigateTo(id){ if(rouvenfo_navigation_domain){ window.location.href = rouvenfo_navigation_domain + id; } else{ window.location.href = id; } } function rouvenfo_navigation_showNavigationItemsMobile(){ if(!menuMobileActive){ $("ul." + rouvenfo_navigation_prefix_style + "-list").show(); $("." + rouvenfo_navigation_prefix_style + "-mobile-background").show(); } else{ $("ul." + rouvenfo_navigation_prefix_style + "-list").hide(); $("." + rouvenfo_navigation_prefix_style + "-mobile-background").hide(); } menuMobileActive = !menuMobileActive; } function rouvenfo_navigation_createNavigationStructure(){ var path = window.location.pathname; if(rouvenfo_navigation_domain){ path = path.replace(rouvenfo_navigation_domain, ""); } var currentPath = path.substring(1); rouvenfo_navigation_pathList = currentPath.split("/"); var side = $(document.createElement("div")); side.addClass(rouvenfo_navigation_prefix_style + "-side"); var mobile = $(document.createElement("div")); mobile.addClass(rouvenfo_navigation_prefix_style + "-mobile"); side.append(mobile); var mobileIcon = $(document.createElement("span")); mobileIcon.addClass(rouvenfo_navigation_prefix_style + "-mobile-icon"); mobileIcon.on("click", rouvenfo_navigation_showNavigationItemsMobile); mobile.append(mobileIcon); var mobileFA = $(document.createElement("i")); mobileFA.addClass("fa-solid fa-bars"); mobileIcon.append(mobileFA); var mobileText = $(document.createElement("span")); mobileText.addClass(rouvenfo_navigation_prefix_style + "-mobile-text"); rouvenfo_navigation_createItemsMobile(mobileText, 0); mobile.append(mobileText); var list = $(document.createElement("ul")); list.addClass(rouvenfo_navigation_prefix_style + "-list"); rouvenfo_navigation_addMenuItem(list, rouvenfo_navigation_items, "/", 0); side.append(list); var mobileBackground = $(document.createElement("div")); mobileBackground.addClass(rouvenfo_navigation_prefix_style + "-mobile-background"); side.append(mobileBackground); $("#rouvenfo-navigation").append(side); } function rouvenfo_navigation_createItemsMobile(parent, depth){ for(var i = 0; i < rouvenfo_navigation_items.length; i++){ if(rouvenfo_navigation_items[i].id == rouvenfo_navigation_pathList[depth]){ parent.text(rouvenfo_navigation_items[i].text); } } } function rouvenfo_navigation_addMenuItem(parentElement, children, path, depth){ for(var i = 0; i < children.length; i++){ var item = $(document.createElement("li")); item.addClass(rouvenfo_navigation_prefix_style + "-item"); if(children[i].id != rouvenfo_navigation_pathList[depth]){ item.click({item: children[i], path: path}, function(event){ if(event.data.item.children){ rouvenfo_navigation_navigateTo(path + event.data.item.id + "/" + event.data.item.children[0].id); } else{ rouvenfo_navigation_navigateTo(event.data.path + event.data.item.id); } }); } if(children[i].id == rouvenfo_navigation_pathList[depth]){ item.addClass(rouvenfo_navigation_prefix_style + "-item-active"); } if(children[i].icon != null){ var icon = $(document.createElement("i")); icon.addClass(children[i].icon); item.append(icon); } var text = $(document.createElement("span")); text.addClass(rouvenfo_navigation_prefix_style + "-item-text"); text.text(children[i].text); item.append(text); if(children[i].id == rouvenfo_navigation_pathList[depth] && children[i].children){ console.log(children[i].id); var submenuList = $(document.createElement("ul")); submenuList.addClass(rouvenfo_navigation_prefix_style + "-sublist"); rouvenfo_navigation_addMenuItem(submenuList, children[i].children, path + children[i].id + "/", depth + 1); item.append(submenuList); } parentElement.append(item); } }function rouvenfo_split_add(name, id, panel1, panel2){ $("#" + id).on("mousedown", {name: name, id: id, panel1: panel1, panel2: panel2}, function(event){ $(document).mousemove({name: event.data.name, id: event.data.id, panel1: event.data.panel1, panel2: event.data.panel2}, function(event) { rouvenfo_split_setPosition(event.data.id, event.data.panel1, event.data.panel2, event.pageY); setCookie(event.data.name + "-split", (event.pageY)); }); }); $("#" + id).on("mouseup", function(event){ $(document).off('mousemove'); }); var cookie = getCookie(name + "-split"); if(cookie){ rouvenfo_split_setPosition(id, panel1, panel2, cookie); } } function rouvenfo_split_setPosition(id, panel1, panel2 , y){ $("#" + panel1).css("height", (y - 150) + "px"); $("#" + id).css("top", (y - 50) + "px"); $("#" + panel2).css("top", (y - 45) + "px"); $("#" + panel2).css("height", "calc(100% - " + (Number(y) + 55) + "px)"); } function rouvenfo_get_child_index(node) { return Array.prototype.indexOf.call(node.parentNode.childNodes, node); } function rouvenfo_append_element_div_class_if_not_exists(selector, classname){ var element = $(selector + " ." + classname); if(element.length == 0){ $(selector).append("
"); } } function setCookie(name,value,days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }function rouvenfo_blocker_show(text, showProgressbar, progressbarText){ var blocker = "rouvenfo-blocker-container"; if($("#" + blocker).length == 0){ $('body').append($('
', { id: blocker })); } var blockerTextContainer = "rouvenfo-blocker-text-container"; if($("." + blockerTextContainer).length == 0){ $("#" + blocker).append($('
', { class: blockerTextContainer })); } var blockerSpinner = "rouvenfo-blocker-spinner"; if($("." + blockerSpinner).length == 0){ $("." + blockerTextContainer).append($('
', { class: blockerSpinner })); } var blockerText = "rouvenfo-blocker-text"; if($("." + blockerText).length == 0){ $("." + blockerTextContainer).append($('
', { class: blockerText })); } $("." + blockerText).text(text); var progressbarContainer = "rouvenfo-blocker-progressbar-container"; if(showProgressbar){ if($("." + progressbarContainer).length == 0){ $("#" + blocker).append($('
', { class: progressbarContainer })); } var progressbarLabelPercent = "rouvenfo-blocker-progressbar-label-percent"; if($("." + progressbarLabelPercent).length == 0){ $("." + progressbarContainer).append($('
', { class: progressbarLabelPercent })); } var progressbarLabelText = "rouvenfo-blocker-progressbar-label-text"; if($("." + progressbarLabelText).length == 0){ $("." + progressbarContainer).append($('
', { class: progressbarLabelText })); } var progressbarWrap = "rouvenfo-blocker-progressbar-wrap"; if($("." + progressbarWrap).length == 0){ $("." + progressbarContainer).append($('
', { class: progressbarWrap })); } var progressbarContainerProgress = "rouvenfo-blocker-progressbar-progress"; if($("." + progressbarContainerProgress).length == 0){ $("." + progressbarWrap).append($('
', { class: progressbarContainerProgress })); } rouvenfo_blocker_update_progressbar(0, progressbarText); } else{ $("." + progressbarContainer).hide(); } $("#" + blocker).show(); } function rouvenfo_blocker_update_progressbar(percent, text){ $(".rouvenfo-blocker-progressbar-progress").css("width", percent + "%"); $(".rouvenfo-blocker-progressbar-label-text").text(text); $(".rouvenfo-blocker-progressbar-label-percent").text(percent + " %"); } function rouvenfo_blocker_hide(){ $("#rouvenfo-blocker-container").hide(); } $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append('');