diff --git a/core/ajax/Abeille.ajax.php b/core/ajax/Abeille.ajax.php index b5c3e23c9b..408e2ff0be 100755 --- a/core/ajax/Abeille.ajax.php +++ b/core/ajax/Abeille.ajax.php @@ -298,27 +298,27 @@ function sendToCmd($topic, $payload = '') { ajax::success(json_encode(array('status' => $status))); } - /* Developer feature: Remove equipment(s) listed by id in 'eqList', from Jeedom DB. - Zigate is untouched. - Returns: status=0/-1, errors= */ - if (init('action') == 'removeEqJeedom') { - $eqList = init('eqList'); - - $status = 0; - $errors = ""; // Error messages - foreach ($eqList as $eqId) { - /* Collecting required infos */ - $eqLogic = eqLogic::byId($eqId); - if (!is_object($eqLogic)) { - throw new Exception(__('EqLogic inconnu. Vérifiez l\'ID', __FILE__).' '.$eqId); - } - - /* Removing device from Jeedom DB */ - $eqLogic->remove(); - } - - ajax::success(json_encode(array('status' => $status, 'errors' => $errors))); - } + // /* Developer feature: Remove equipment(s) listed by id in 'eqList', from Jeedom DB. + // Zigate is untouched. + // Returns: status=0/-1, errors= */ + // if (init('action') == 'removeEqJeedom') { + // $eqList = init('eqList'); + + // $status = 0; + // $errors = ""; // Error messages + // foreach ($eqList as $eqId) { + // /* Collecting required infos */ + // $eqLogic = eqLogic::byId($eqId); + // if (!is_object($eqLogic)) { + // throw new Exception(__('EqLogic inconnu. Vérifiez l\'ID', __FILE__).' '.$eqId); + // } + + // /* Removing device from Jeedom DB */ + // $eqLogic->remove(); + // } + + // ajax::success(json_encode(array('status' => $status, 'errors' => $errors))); + // } /* Remove equipment(s) from zigbee listed by id in 'eqIdList'. Returns: status=0/-1, errors= */ diff --git a/desktop/js/Abeille.js b/desktop/js/Abeille.js index 56bc294d93..c1e76aa626 100755 --- a/desktop/js/Abeille.js +++ b/desktop/js/Abeille.js @@ -320,68 +320,184 @@ function getSelectedEqs(zgId) { } /* Removes selected equipments for given zigate nb from Jeedom DB only. Zigate is untouched. */ -function removeBeesJeedom(zgId) { - console.log("removeBeesJeedom(zgId=" + zgId + ")"); +// function removeBeesJeedom(zgId) { +// console.log("removeBeesJeedom(zgId=" + zgId + ")"); + +// /* Any selected ? */ +// var sel = getSelectedEqs(zgId); +// console.log(sel); +// if (sel["nb"] == 0) { +// alert("Aucun équipement sélectionné !"); +// return; +// } +// var eqIdList = sel["ids"]; +// console.log("eqIdList=" + eqIdList); + +// var msg = +// "{{Vous êtes sur le point de supprimer les équipements selectionnés de Jeedom."; +// msg += +// "

Si ils sont toujours dans le réseau, ils deviendront 'fantomes' et devraient être réinclus automatiquement au fur et à mesure de leur reveil et ce, tant qu'on ne les force pas à quitter le réseau."; +// msg += "

Etes vous sur de vouloir continuer ?}}"; +// bootbox.confirm(msg, function (result) { +// if (result == false) return; + +// // Collecting addresses before EQ is removed +// var eqAddrList = sel["addrs"]; +// console.log("eqAddrList=" + eqAddrList); + +// $.ajax({ +// type: "POST", +// url: "plugins/Abeille/core/ajax/Abeille.ajax.php", +// data: { +// action: "removeEqJeedom", +// eqList: eqIdList, +// }, +// dataType: "json", +// global: false, +// error: function (request, status, error) { +// bootbox.alert("ERREUR 'removeEqJeedom' !"); +// }, +// success: function (json_res) { +// window.location.reload(); +// res = JSON.parse(json_res.result); +// if (res.status != 0) { +// var msg = +// "ERREUR ! Quelque chose s'est mal passé.\n" + +// res.errors; +// alert(msg); +// } else { +// // Informing parser that some equipements have to be considered "phantom" +// var xhr = new XMLHttpRequest(); +// xhr.open( +// "GET", +// "plugins/Abeille/core/php/AbeilleCliToQueue.php?action=sendMsg&queueId=" + +// js_queueXToParser + +// "&msg=type:eqRemoved_net:Abeille" + +// zgId + +// "_eqList:" + +// eqAddrList, +// true +// ); +// xhr.send(); +// } +// }, +// }); +// }); +// } + +/* Removes selected equipments for given zigate nb from Jeedom DB only. Zigate is untouched. */ +function removeSelectedEq(zgId) { + console.log("removeSelectedEq(zgId=" + zgId + ")"); /* Any selected ? */ var sel = getSelectedEqs(zgId); console.log(sel); if (sel["nb"] == 0) { - alert("Aucun équipement sélectionné !"); + alert("{{Aucun équipement sélectionné !}}"); return; } var eqIdList = sel["ids"]; console.log("eqIdList=" + eqIdList); - var msg = - "{{Vous êtes sur le point de supprimer les équipements selectionnés de Jeedom."; - msg += - "

Si ils sont toujours dans le réseau, ils deviendront 'fantomes' et devraient être réinclus automatiquement au fur et à mesure de leur reveil et ce, tant qu'on ne les force pas à quitter le réseau."; - msg += "

Etes vous sur de vouloir continuer ?}}"; - bootbox.confirm(msg, function (result) { - if (result == false) return; + for (const eqId of eqIdList) removeEq(zgId, eqId); +} - // Collecting addresses before EQ is removed - var eqAddrList = sel["addrs"]; - console.log("eqAddrList=" + eqAddrList); +/* Remove from Jeedom eq with ID 'eqId' but list first how it is used and ask confirmation to user */ +function removeEq(zgId, eqId) { + console.log("removeEq(" + eqId + ")"); - $.ajax({ - type: "POST", - url: "plugins/Abeille/core/ajax/Abeille.ajax.php", - data: { - action: "removeEqJeedom", - eqList: eqIdList, - }, - dataType: "json", - global: false, - error: function (request, status, error) { - bootbox.alert("ERREUR 'removeEqJeedom' !"); - }, - success: function (json_res) { - window.location.reload(); - res = JSON.parse(json_res.result); - if (res.status != 0) { - var msg = - "ERREUR ! Quelque chose s'est mal passé.\n" + - res.errors; - alert(msg); - } else { - // Informing parser that some equipements have to be considered "phantom" - var xhr = new XMLHttpRequest(); - xhr.open( - "GET", - "plugins/Abeille/core/php/AbeilleCliToQueue.php?action=sendMsg&queueId=" + - js_queueXToParser + - "&msg=type:eqRemoved_net:Abeille" + - zgId + - "_eqList:" + - eqAddrList, - true - ); - xhr.send(); + eval("var eqPerZigate = JSON.parse(js_eqPerZigate);"); + eqName = eqPerZigate[zgId][eqId]["name"]; + eqAddr = eqPerZigate[zgId][eqId]["addr"]; + eqAddrList = new Array(); + eqAddrList.push(eqAddr); + + jeedom.eqLogic.getUseBeforeRemove({ + id: eqId, + error: function (error) { + $.fn.showAlert({ + message: error.message, + level: "danger", + }); + }, + success: function (data) { + var text = + "{{Êtes-vous sûr de vouloir supprimer l'équipement}} Abeille " + + eqName + + " ?"; + if (Object.keys(data).length > 0) { + text += "
{{Il est utilisé par ou utilise :}}
"; + var complement = null; + for (var i in data) { + complement = ""; + if ("sourceName" in data[i]) { + complement = " (" + data[i].sourceName + ")"; + } + text += + "- " + + '' + + data[i].type + + " : " + + data[i].name + + "" + + complement + + '
'; } - }, - }); + } + text = text.substring(0, text.length - 2); + bootbox.confirm(text, function (result) { + if (result) { + jeedom.eqLogic.remove({ + type: "Abeille", + id: eqId, + error: function (error) { + $.fn.showAlert({ + message: error.message, + level: "danger", + }); + }, + success: function () { + // Inform parser & cmd that this equipement has been removed + var xhr = new XMLHttpRequest(); + xhr.open( + "POST", + "plugins/Abeille/core/php/AbeilleCliToQueue.php?action=sendMsg&queueId=" + + js_queueXToParser + + "&msg=type:eqRemoved_net:Abeille" + + zgId + + "_eqList:" + + eqAddrList, + true + ); + xhr.send(); + + var vars = getUrlVars(); + var url = "index.php?"; + for (var i in vars) { + if ( + i != "id" && + i != "removeSuccessFull" && + i != "saveSuccessFull" + ) { + url += + i + + "=" + + vars[i].replace("#", "") + + "&"; + } + } + modifyWithoutSave = false; + url += "removeSuccessFull=1"; + jeedomUtils.loadPage(url); + }, + }); + } + }); + }, }); } diff --git a/desktop/php/Abeille-Bees.php b/desktop/php/Abeille-Bees.php index d424b33659..325ddd48d9 100644 --- a/desktop/php/Abeille-Bees.php +++ b/desktop/php/Abeille-Bees.php @@ -83,7 +83,8 @@ function displayBeeCard($eqLogic, $files, $zgId) { echo ''; /* Remove equipments from Jeedom only */ - echo '{{Supprimer de Jeedom}}'; + // echo '{{Supprimer de Jeedom}}'; + echo '{{Supprimer de Jeedom}}'; /* Exclude feature */ echo '{{Exclure}}'; diff --git a/desktop/php/Abeille.php b/desktop/php/Abeille.php index dc6fc93208..20c60b2cc3 100755 --- a/desktop/php/Abeille.php +++ b/desktop/php/Abeille.php @@ -40,6 +40,7 @@ $eq['mainEp'] = $eqLogic->getConfiguration('mainEP', ''); $eqModel = $eqLogic->getConfiguration('ab::eqModel', null); $eq['jsonId'] = $eqModel ? $eqModel['id'] : ''; + $eq['name'] = $eqLogic->getName(); if ($eqAddr == "0000") { if (isset($eqPerZigate[$zgId][$eqId])) array_unshift($eqPerZigate[$zgId][$eqId], $eq); diff --git a/docs/fr_FR/Changelog.rst b/docs/fr_FR/Changelog.rst index 4dcef0a2ce..26e73cc558 100644 --- a/docs/fr_FR/Changelog.rst +++ b/docs/fr_FR/Changelog.rst @@ -9,6 +9,7 @@ ChangeLog - Abeille remote control: Commandes 'on all' & 'off all' cachées par défaut. Trop dangereux. - Interne: Mise-à-jour 'getDevicesList()' + 'getDeviceModel()'. - Reset de modele: Correction pour signatures alternatives. +- Suppression d'un équipement: Correction permettant d'affichage comment il est utilisé avant suppression (2652). 231107-BETA-2 -------------