removed deprecated ui script
This commit is contained in:
parent
e30fd12fdb
commit
fa2436eb0b
|
@ -1,424 +0,0 @@
|
|||
// DO NOT USE. DEPRECATED! USE em_eu_templates.js instead!!!
|
||||
// TODO: remove
|
||||
|
||||
let all_checked = false;
|
||||
let all_checked_vehicles = false;
|
||||
let limit = 10;
|
||||
let offset = 0;
|
||||
let page = 1;
|
||||
let total_page_count = 0;
|
||||
let positions_all_checked = false;
|
||||
let current_template_selected;
|
||||
|
||||
$( document ).ready(function() {
|
||||
EventUnitTemplatesModule.load_templates();
|
||||
console.log("Don't use this script you honk! If someone pushed this to production hang him!");
|
||||
//Do not execute code here which relies on templates. Use EventUnitTemplateModule.start function instead
|
||||
});
|
||||
|
||||
// DO NOT USE. DEPRECATED! USE em_eu_templates.js instead!!!
|
||||
|
||||
EventUnitTemplatesModule = ( function() {
|
||||
let templates = {};
|
||||
let vehicle_categories = [];
|
||||
|
||||
let load_templates = function(){
|
||||
$.get("/templates/em_event_unit_templates_template_row.hbs", function(res) {
|
||||
templates.template_row = Handlebars.compile(res);
|
||||
start();
|
||||
});
|
||||
$.get("/templates/em_event_unit_templates_template_detailed.hbs", function(res) {
|
||||
templates.template_detailed = Handlebars.compile(res);
|
||||
start();
|
||||
});
|
||||
$.get("/templates/em_event_unit_templates_vehicle_position_row.hbs", function(res){
|
||||
templates.vehicle_row = Handlebars.compile(res);
|
||||
start();
|
||||
});
|
||||
load_vehicle_category_list();
|
||||
};
|
||||
let start = function(){
|
||||
if(templates.template_row && templates.template_detailed && templates.vehicle_row && vehicle_categories.length > 0){
|
||||
load_eu_template_list();
|
||||
$(".check_all_templates").on("click", function(){
|
||||
$(".eu_templates_checkbox").prop("checked", !all_checked);
|
||||
all_checked = !all_checked
|
||||
});
|
||||
}
|
||||
};
|
||||
let load_eu_template_list = function(){
|
||||
offset = (page-1)*limit;
|
||||
$("#template_list_tbody").html("");
|
||||
$.ajax({
|
||||
url: '/api/events/units/templates?limit='+limit+'&offset='+offset,
|
||||
type: 'GET',
|
||||
contentType: 'application/json',
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
eu_templates = data.templates;
|
||||
total_page_count = Math.ceil(data.total_template_count/limit);
|
||||
$(eu_templates).each(function(){
|
||||
$("#template_list_tbody").append(templates.template_row(this));
|
||||
});
|
||||
$(".template_list_nav_next").on("click", pagination_forward);
|
||||
$(".template_list_nav_back").on("click", pagination_backward);
|
||||
$(".template_list_nav_numbers").on("click", pagination_numbers);
|
||||
$(".templates_delete_button").on("click", delete_templates);
|
||||
$(".template_new_submit").on("click", create_template);
|
||||
pagination_update();
|
||||
$(".eu_template_tr").off("click").on("click", load_detailed_template);
|
||||
}
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
};
|
||||
let pagination_forward = function(){
|
||||
if(page < total_page_count){
|
||||
page++;
|
||||
load_eu_template_list();
|
||||
}
|
||||
};
|
||||
let pagination_backward = function(){
|
||||
if(page > 1){
|
||||
page--;
|
||||
load_eu_template_list();
|
||||
}
|
||||
};
|
||||
let pagination_numbers = function(){
|
||||
page = parseInt($(this).text());
|
||||
load_eu_template_list();
|
||||
};
|
||||
let pagination_update = function(){
|
||||
$(".template_list_nav_numbers").remove();
|
||||
for(let i = total_page_count; i>0;i--){
|
||||
if(page === i){
|
||||
$(".template_list_nav_back_li").after("<li class=\"page-item template_list_nav_numbers disabled\"><a class=\"page-link\" href=\"#\">"+i+"</a></li>");
|
||||
}else {
|
||||
$(".template_list_nav_back_li").after("<li class=\"page-item template_list_nav_numbers\"><a class=\"page-link\" href=\"#\">" + i + "</a></li>");
|
||||
}
|
||||
}
|
||||
$(".template_list_nav_numbers").on("click", pagination_numbers);
|
||||
|
||||
if(page === total_page_count){
|
||||
$(".template_list_nav_next").parent().addClass("disabled");
|
||||
}else{
|
||||
$(".template_list_nav_next").parent().removeClass("disabled");
|
||||
}
|
||||
if(page === 1){
|
||||
$(".template_list_nav_back").parent().addClass("disabled");
|
||||
}else{
|
||||
$(".template_list_nav_back").parent().removeClass("disabled");
|
||||
}
|
||||
};
|
||||
let delete_templates = function(){
|
||||
let template_list = [];
|
||||
$(".eu_template_checkbox").each(function(k, v){
|
||||
if($(v).prop("checked")){
|
||||
template_list.push($(v).data("entity-id"));
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: '/api/events/units/templates/',
|
||||
type: 'DELETE',
|
||||
data: JSON.stringify(template_list),
|
||||
contentType: 'application/json',
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
$(".eu_template_checkbox").each(function(k,v){
|
||||
if(template_list.includes($(v).data("entity-id"))){
|
||||
$(this).parent().parent().remove();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
};
|
||||
let load_detailed_template = async function(){
|
||||
$(".template_detailed_card").show();
|
||||
|
||||
$(".eu_template_tr").removeClass("table-primary");
|
||||
$(this).addClass("table-primary");
|
||||
let entity_id = $(this).data("entity_id");
|
||||
|
||||
$(".template_detailed_card_body").remove();
|
||||
let templ;
|
||||
$(eu_templates).each(function(){
|
||||
if(this.entity_id === entity_id){
|
||||
current_template_selected = entity_id;
|
||||
templ = this;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
await load_positions_for_template(templ);
|
||||
await load_vehicle_positions();
|
||||
$(".template_detailed_card").show();
|
||||
};
|
||||
let load_positions_for_template = async function(templ){
|
||||
const data = await $.ajax({
|
||||
url: '/api/events/units/templates/'+templ.entity_id+'/positions',
|
||||
type: 'GET',
|
||||
contentType: 'application/json',
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
if(is_ok(data)){
|
||||
templ.positions = data;
|
||||
console.log(templ);
|
||||
$(".template_detailed_card").append(templates.template_detailed(templ));
|
||||
$(".template_detailed_check_all_positions").off("click").on("click", function(){
|
||||
$($(".template_detailed_position_checkbox")).prop("checked", !positions_all_checked);
|
||||
positions_all_checked = !positions_all_checked;
|
||||
});
|
||||
var position_search = new MiniSearchbar("add_position_search", add_position_search_callback);
|
||||
position_search.setup();
|
||||
|
||||
$(".templates_detailed_delete_position_button").off("click").on("click", delete_positions_from_template);
|
||||
$(".template_detailed_submit").off("click").on("click", function(){
|
||||
let template = {};
|
||||
template.name = $("#template_detailed_name").val();
|
||||
if($("#template_detailed_description").val().length > 1){
|
||||
template.description = $("#template_detailed_description").val();
|
||||
}
|
||||
template.entity_id = $("#template_detailed_entity_id").val();
|
||||
if(template.name.length === 0){
|
||||
alert("Bitte Namen angeben!");
|
||||
}else{
|
||||
update_template(template);
|
||||
}
|
||||
});
|
||||
$(".template_detailed_vehicle_add").off("click").on("click", add_vehicle_position);
|
||||
$(".templates_detailed_delete_vehicle_button").off("click").on("click", delete_vehicle_positions);
|
||||
$(".template_detailed_check_all_vehicles").off("click").on("click", function(){
|
||||
$(".eu_vehicle_position_checkbox").prop("checked", !all_checked_vehicles);
|
||||
all_checked_vehicles = !all_checked_vehicles;
|
||||
});
|
||||
$(vehicle_categories).each(function(){
|
||||
$("#template_detailed_vehicle_category_select").append("<option value='"+this.id+"'>"+this.name+"</option>")
|
||||
});
|
||||
}
|
||||
};
|
||||
let add_position_search_callback = function(sr){
|
||||
$.ajax({
|
||||
url: '/api/events/units/templates/'+current_template_selected+'/positions/'+$(sr).data("entity-id")+"/times/1",
|
||||
type: 'PUT',
|
||||
contentType: 'application/json',
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
let entity_id = $(sr).data("entity-id");
|
||||
let description = "";
|
||||
if($(sr).data("description")){
|
||||
description = $(sr).data("description");
|
||||
}
|
||||
let name = $(sr).data("name");
|
||||
|
||||
$(".template_detailed_positions_tbody").append("<tr>\n" +
|
||||
" <td><input type=\"checkbox\" class=\"template_detailed_position_checkbox\" data-position-id=\""+entity_id+"\">\n" +
|
||||
" </td>\n" +
|
||||
" <td>"+name+"</td>\n" +
|
||||
" <td>"+description+"</td>\n" +
|
||||
" </tr>");
|
||||
}
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
};
|
||||
let delete_positions_from_template = function(){
|
||||
let positions = [];
|
||||
|
||||
$(".template_detailed_position_checkbox").each(function(){
|
||||
if($(this).prop("checked")){
|
||||
positions.push($(this).data("position-id"));
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: '/api/events/units/templates/'+current_template_selected+'/positions/',
|
||||
type: 'DELETE',
|
||||
data: JSON.stringify(positions),
|
||||
contentType: 'application/json',
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
$(".template_detailed_position_checkbox").each(function(){
|
||||
if($.inArray($(this).data("position-id", positions))){
|
||||
$(this).parent().parent().remove();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
let create_template = function(){
|
||||
let pdata = {};
|
||||
if(!$("#template_new_name").val()){
|
||||
alert("Bitte alle Felder ausfüllen!");
|
||||
return
|
||||
}else{
|
||||
pdata.name = $("#template_new_name").val();
|
||||
}
|
||||
|
||||
if($("#template_new_description").val().length > 0){
|
||||
pdata.description = $("#template_new_description").val();
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: '/api/events/units/templates',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(pdata),
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
};
|
||||
let update_template = function(template){
|
||||
console.log(template);
|
||||
$.ajax({
|
||||
url: '/api/events/units/templates/'+template.entity_id,
|
||||
type: 'PUT',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(template),
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
console.log(data);
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
};
|
||||
let load_vehicle_category_list = function(){
|
||||
$.ajax({
|
||||
url: '/api/resources/vehicles/categories',
|
||||
type: 'GET',
|
||||
contentType: 'application/json',
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
vehicle_categories = data;
|
||||
start();
|
||||
}
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
};
|
||||
let add_vehicle_position = function(){
|
||||
let vehicle_position = {};
|
||||
vehicle_position.name = $("#template_detailed_vehicle_name").val();
|
||||
vehicle_position.description = $("#template_detailed_vehicle_description").val();
|
||||
vehicle_position.template_id = current_template_selected;
|
||||
vehicle_position.required_vehicle_category = $("#template_detailed_vehicle_category_select").val();
|
||||
|
||||
if(!vehicle_position.name || !vehicle_position.template_id || !vehicle_position.required_vehicle_category){
|
||||
alert("Bitte geben Sie eine Bezeichnung sowie die Fahrzeugkategorie an!");
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: '/api/events/units/vehicle_positions',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(vehicle_position),
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
data.required_vehicle_category_name = resolve_vehicle_category(data.required_vehicle_category).name;
|
||||
$(".template_detailed_vehicles_tbody").append(templates.vehicle_row(data));
|
||||
}
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
};
|
||||
let resolve_vehicle_category = function(category_id){
|
||||
let cat;
|
||||
$(vehicle_categories).each(function(){
|
||||
if(this.id === category_id){
|
||||
cat = this;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return cat;
|
||||
};
|
||||
let load_vehicle_positions = async function(){
|
||||
const res = await $.ajax({
|
||||
url: '/api/events/units/templates/'+current_template_selected+'/vehicle_positions',
|
||||
type: 'GET',
|
||||
contentType: 'application/json',
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
if (is_ok(res)) {
|
||||
$(res).each(function(){
|
||||
let entry = this;
|
||||
entry.required_vehicle_category_name = resolve_vehicle_category(entry.required_vehicle_category).name;
|
||||
$(".template_detailed_vehicles_tbody").append(templates.vehicle_row(entry));
|
||||
});
|
||||
}
|
||||
};
|
||||
let delete_vehicle_positions = function(){
|
||||
let delete_list = [];
|
||||
$(".eu_vehicle_position_checkbox").each(function(){
|
||||
if($(this).prop("checked")){
|
||||
delete_list.push($(this).data("entity-id"));
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: '/api/events/units/vehicle_positions',
|
||||
type: 'DELETE',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(delete_list),
|
||||
success: function (data) {
|
||||
if (is_ok(data)) {
|
||||
$(".eu_vehicle_position_tr").each(function(){
|
||||
if($.inArray($(this).data("entity_id"), delete_list) !== -1){
|
||||
console.log(this);
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Es ist ein Fehler aufgetreten!");
|
||||
}
|
||||
});
|
||||
};
|
||||
return{
|
||||
load_templates: load_templates,
|
||||
start: start,
|
||||
};
|
||||
}());
|
Loading…
Reference in New Issue