From 79f5e879cc6f10c5413c11a2188a8a44f1f54ed8 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Mon, 18 Nov 2019 13:37:10 +0100 Subject: [PATCH] WIP Alerts --- pandora_console/include/javascript/alert.js | 118 ++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 pandora_console/include/javascript/alert.js diff --git a/pandora_console/include/javascript/alert.js b/pandora_console/include/javascript/alert.js new file mode 100644 index 0000000000..d293e247d8 --- /dev/null +++ b/pandora_console/include/javascript/alert.js @@ -0,0 +1,118 @@ +/* eslint-disable no-unused-vars */ +/* global $, load_modal, generalShowMsg, confirmDialog */ + +function allowDrop(ev) { + ev.preventDefault(); +} + +function drag(ev) { + ev.dataTransfer.setData("html", ev.target.outerHTML); +} + +function drop(ev) { + ev.preventDefault(); + var data = document.createElement("span"); + var content = ev.dataTransfer.getData("html"); + if (content.includes("nexo")) { + content = "
" + content; + } + data.innerHTML = content; + document.getElementById(ev.target.id).appendChild(data); +} + +function add_alert_action(settings) { + load_modal({ + target: $("#modal-add-action-form"), + form: "modal_form_add_actions", + url: settings.url_ajax, + modal: { + title: settings.title, + cancel: settings.btn_cancel, + ok: settings.btn_text + }, + onshow: { + page: settings.url, + method: "addAlertActionForm", + extradata: { + id: settings.id + } + }, + onsubmit: { + page: settings.url, + method: "addAlertAction", + dataType: "json" + }, + ajax_callback: add_alert_action_acept, + idMsgCallback: "msg-add-action" + }); +} + +function add_alert_action_acept(data, idMsg) { + if (data.error === 1) { + console.log(data.text); + return; + } + + if ($("#emptyli-al-" + data.id_alert).length > 0) { + $("#emptyli-al-" + data.id_alert).remove(); + } + + $.ajax({ + method: "post", + url: data.url, + data: { + page: data.page, + method: "addRowActionAjax", + id_alert: data.id_alert, + id_action: data.id_action + }, + dataType: "html", + success: function(li) { + $(".ui-dialog-content").dialog("close"); + $("#ul-al-" + data.id_alert).append(li); + }, + error: function(error) { + console.log(error); + } + }); +} + +function delete_alert_action(settings) { + confirmDialog({ + title: settings.title, + message: settings.msg, + onAccept: function() { + $.ajax({ + method: "post", + url: settings.url, + data: { + page: settings.page, + method: "deleteActionAlert", + id_alert: settings.id_alert, + id_action: settings.id_action + }, + dataType: "json", + success: function(data) { + // Delete row table. + $( + "#li-al-" + settings.id_alert + "-act-" + settings.id_action + ).remove(); + + var num_row = $("#ul-al-" + settings.id_alert + " li").length; + if (num_row === 0) { + var emptyli = + "
  • " + + settings.emptyli + + "
  • "; + $("#ul-al-" + settings.id_alert).append(emptyli); + } + }, + error: function(error) { + console.log(error); + } + }); + } + }); +}