diff --git a/core/js/eqLogic.class.js b/core/js/eqLogic.class.js index 7f3bb8856b..be9482d6c8 100644 --- a/core/js/eqLogic.class.js +++ b/core/js/eqLogic.class.js @@ -34,7 +34,7 @@ if (!isset(jeedom.eqLogic.cache.byId)) { jeedom.eqLogic.cache.byId = Array() } -if(!isset(jeedom.eqLogic.cache.byLogical)){ +if (!isset(jeedom.eqLogic.cache.byLogical)) { jeedom.eqLogic.cache.byLogical = Array() } @@ -173,29 +173,67 @@ jeedom.eqLogic.usedBy = function(_params) { jeedom.eqLogic.remove = function(_params) { const paramsRequired = ['id', 'type'] - const paramsSpecifics = { - pre_success: function(data) { - if (isset(jeedom.eqLogic.cache.byId[_params.id])) { - delete jeedom.eqLogic.cache.byId[_params.id] - } - return data - } - } try { jeedom.private.checkParamsRequired(_params || {}, paramsRequired) } catch (e) { - (_params.error || paramsSpecifics.error || jeedom.private.default_params.error)(e) + (_params.error || jeedom.private.default_params.error)(e) return } - const params = domUtils.extend({}, jeedom.private.default_params, paramsSpecifics, _params || {}) - const paramsAJAX = jeedom.private.getParamsAJAX(params) - paramsAJAX.url = 'core/ajax/eqLogic.ajax.php' - paramsAJAX.data = { - action: 'remove', - type: _params.type, - id: _params.id - } - domUtils.ajax(paramsAJAX) + jeedom.eqLogic.getUseBeforeRemove({ + id: _params.id, + error: function(error) { + jeedomUtils.showAlert({ message: error.message, level: 'danger' }) + }, + success: function(data) { + let text = "{{Êtes-vous sûr de vouloir supprimer l'équipement}} " + _params.type + if (_params.name) { + text += ' ' + _params.name + '' + } + text += ' ?' + if (Object.keys(data).length > 0) { + text += ' {{Il est utilisé par:}}' + let complement = null + for (const i in data) { + complement = ('sourceName' in data[i]) ? ' (' + data[i].sourceName + ')' : '' + text += '- ' + data[i].type + ' : ' + data[i].name + '' + complement + ' ' + } + } + jeeDialog.confirm(text, function(result) { + if (!result) return + + // Fires only once the actual removal succeeds server-side: + const paramsSpecifics = { + pre_success: function(data) { + if (isset(jeedom.eqLogic.cache.byId[_params.id])) { + delete jeedom.eqLogic.cache.byId[_params.id] + } + return data + }, + success: function() { + jeeFrontEnd.modifyWithoutSave = false + modifyWithoutSave = false + const vars = getUrlVars() + let url = 'index.php?' + for (const i in vars) { + if (i != 'id' && i != 'removeSuccessFull' && i != 'saveSuccessFull') { + url += i + '=' + vars[i].replace('#', '') + '&' + } + } + jeedomUtils.loadPage(url + 'removeSuccessFull=1') + } + } + const params = domUtils.extend({}, jeedom.private.default_params, paramsSpecifics, _params || {}) + const paramsAJAX = jeedom.private.getParamsAJAX(params) + paramsAJAX.url = 'core/ajax/eqLogic.ajax.php' + paramsAJAX.data = { + action: 'remove', + type: _params.type, + id: _params.id + } + domUtils.ajax(paramsAJAX) + }) + } + }) } jeedom.eqLogic.copy = function(_params) { @@ -270,7 +308,7 @@ jeedom.eqLogic.toHtml = function(_params) { action: 'toHtml', id: _params.id, version: _params.version, - global : _params.global || false + global: _params.global || false } domUtils.ajax(paramsAJAX) } @@ -299,7 +337,7 @@ jeedom.eqLogic.getCmd = function(_params) { paramsAJAX.data = { action: 'byEqLogic', eqLogic_id: _params.id, - ...(_params.typeCmd ? { typeCmd: _params.typeCmd } : {}) + ...(_params.typeCmd ? { typeCmd: _params.typeCmd } : {}) } domUtils.ajax(paramsAJAX) } @@ -333,22 +371,22 @@ jeedom.eqLogic.byId = function(_params) { } jeedom.eqLogic.removeImage = function(_params) { - const paramsRequired = ['id']; - const paramsSpecifics = {}; + const paramsRequired = ['id'] + const paramsSpecifics = {} try { - jeedom.private.checkParamsRequired(_params || {}, paramsRequired); + jeedom.private.checkParamsRequired(_params || {}, paramsRequired) } catch (e) { - (_params.error || paramsSpecifics.error || jeedom.private.default_params.error)(e); - return; + (_params.error || paramsSpecifics.error || jeedom.private.default_params.error)(e) + return } - const params = domUtils.extend({}, jeedom.private.default_params, paramsSpecifics, _params || {}); - const paramsAJAX = jeedom.private.getParamsAJAX(params); - paramsAJAX.url = 'core/ajax/eqLogic.ajax.php'; + const params = domUtils.extend({}, jeedom.private.default_params, paramsSpecifics, _params || {}) + const paramsAJAX = jeedom.private.getParamsAJAX(params) + paramsAJAX.url = 'core/ajax/eqLogic.ajax.php' paramsAJAX.data = { action: 'removeImage', id: _params.id - }; - domUtils.ajax(paramsAJAX); + } + domUtils.ajax(paramsAJAX) } jeedom.eqLogic.byLogical = function(_params) { @@ -425,7 +463,7 @@ jeedom.eqLogic.getSelectModal = function(_options, callback) { args.human = mod_insertEqLogic.getValue() args.id = mod_insertEqLogic.getId() if (args.human.trim() != '') { - callback(args) + callback(args) } document.getElementById('mod_insertEqLogicValue')._jeeDialog.destroy() } @@ -512,7 +550,7 @@ jeedom.eqLogic.refreshValue = function(_params) { jeedomUtils.positionEqLogic(result[i].id) const packer = Packery.data(object_div) if (packer != undefined) packer.destroy() - new Packery(object_div, {isLayoutInstant: true, transitionDuration: 0}) + new Packery(object_div, { isLayoutInstant: true, transitionDuration: 0 }) document.querySelectorAll('div.eqLogic-widget').forEach(function(element, idx) { element.setAttribute('data-order', idx + 1) @@ -548,7 +586,7 @@ jeedom.eqLogic.refreshValue = function(_params) { jeeFrontEnd.plan.cssStyleString = '' } } - break; + break } } } catch (e) { console.error(e) } @@ -592,7 +630,7 @@ jeedom.eqLogic.refreshValue = function(_params) { eqLogic.triggerEvent('create') jeedomUtils.setTileSize('.eqLogic') } else if (typeof jeedomUI !== 'undefined' && typeof jeeFrontEnd?.dashboard?.editWidgetMode == 'function' && document.getElementById('bt_editDashboardWidgetOrder') != null) { - jeeFrontEnd.dashboard.editWidgetMode(jeedomUI?.isEditing,false) + jeeFrontEnd.dashboard.editWidgetMode(jeedomUI?.isEditing, false) } } } diff --git a/core/js/plugin.template.js b/core/js/plugin.template.js index 68338e2338..585bee22e8 100644 --- a/core/js/plugin.template.js +++ b/core/js/plugin.template.js @@ -98,8 +98,8 @@ if (!jeeFrontEnd.pluginTemplate) { if (isset(data) && isset(data.timeout) && data.timeout == 0) { data.timeout = '' } - if(document.getElementById('img_device') != null && document.querySelector('.eqLogicDisplayCard.active img').getAttribute('src') != ''){ - document.getElementById('img_device').setAttribute("src",document.querySelector('.eqLogicDisplayCard.active img').getAttribute('src')); + if (document.getElementById('img_device') != null && document.querySelector('.eqLogicDisplayCard.active img').getAttribute('src') != '') { + document.getElementById('img_device').setAttribute("src", document.querySelector('.eqLogicDisplayCard.active img').getAttribute('src')) } document.getElementById('div_mainContainer').setJeeValues(data, '.eqLogicAttr') if (!isset(data.category.opening)) try { document.querySelector('input[data-l2key="opening"]').checked = false } catch (e) { } @@ -398,62 +398,21 @@ if (!jeeFrontEnd.pluginTemplate) { removeEqLogic: function() { const eqLogicId = document.querySelector('.eqLogicAttr[data-l1key="id"]').jeeValue() if (eqLogicId != undefined) { - const thisEqType = document.querySelector('.eqLogicDisplayCard[data-eqlogic_id="' + eqLogicId + '"]')?.getAttribute('data-eqLogic_type') - const textEqtype = thisEqType || eqType - jeedom.eqLogic.getUseBeforeRemove({ + const thisEqType = document.querySelector('.eqLogicDisplayCard[data-eqlogic_id="' + eqLogicId + '"]')?.getAttribute('data-eqLogic_type') || eqType + jeedom.eqLogic.remove({ id: eqLogicId, + type: thisEqType, + name: document.querySelector('.eqLogicAttr[data-l1key="name"]').jeeValue(), error: function(error) { jeedomUtils.showAlert({ message: error.message, level: 'danger' }) - }, - success: function(data) { - let text = '{{Êtes-vous sûr de vouloir supprimer l\'équipement}} ' + textEqtype + ' ' + document.querySelector('.eqLogicAttr[data-l1key="name"]').jeeValue() + ' ?' - if (Object.keys(data).length > 0) { - text += ' {{Il est utilisé par:}}' - let complement = null - for (const 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) - jeeDialog.confirm(text, function(result) { - if (result) { - jeedom.eqLogic.remove({ - type: thisEqType || eqType, - id: eqLogicId, - error: function(error) { - jeedomUtils.showAlert({ - message: error.message, - level: 'danger' - }) - }, - success: function() { - const vars = getUrlVars() - let url = 'index.php?' - for (const i in vars) { - if (i != 'id' && i != 'removeSuccessFull' && i != 'saveSuccessFull') { - url += i + '=' + vars[i].replace('#', '') + '&' - } - } - jeeFrontEnd.modifyWithoutSave = false - modifyWithoutSave = false - url += 'removeSuccessFull=1' - jeedomUtils.loadPage(url) - } - }) - } - }) } }) } else { jeedomUtils.showAlert({ - message: '{{Veuillez d\'abord sélectionner un}} ' + textEqtype, + message: '{{Veuillez d\'abord sélectionner un}} ' + eqType, level: 'danger' }) } diff --git a/desktop/modal/eqLogic.configure.php b/desktop/modal/eqLogic.configure.php index 96df24d676..8e51b0e91c 100644 --- a/desktop/modal/eqLogic.configure.php +++ b/desktop/modal/eqLogic.configure.php @@ -56,17 +56,17 @@