/* This file is part of Jeedom. * * Jeedom is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. *Commandes Entrées * Jeedom is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jeedom. If not, see . */ $('#div_pageContainer').on( 'click','.cmdAction[data-action=testinfo]',function (event) { expression = $(this).closest('.confconso').find(('.confconsoAttr[data-l1key='+$(this).attr('actioncommande')+']')).value(); jeedom.scenario.testExpression({ expression: expression, error: function (error) { $('#div_alertExpressionTest').showAlert({message: error.message, level: 'danger'}); }, success: function (data) { $('#div_alert').showAlert({message: 'Commande : '+expression+'. Résultat : '+data.evaluate , level: 'success'}); } }); }); $('#bt_addconsoEqLogic').on('click', function () { addConfconso({}); $('#bt_addconsoEqLogic').hide(); }); // $('#bt_addconsoCmd').on('click', function () { // addCmdToTable({configuration: {period: 1}}); //}); $("#div_confconso").delegate('.bt_removeConfconso', 'click', function () { $(this).closest('.confconso').remove(); }); $("#div_confconso").delegate(".listCmdInfo", 'click', function () { var el = $(this).closest('.confconso').find('.confconsoAttr[data-l1key=' + $(this).attr('data-input') + ']'); jeedom.cmd.getSelectModal({cmd: {type: 'info'}}, function (result) { el.atCaret('insert', result.human); }); }); $('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').on('change', function () { showbytype($(this).value()); }); $('#bt_configureSubType').on('click', function () { $('#md_modal').dialog({title: "{{Configuration des catégories}}"}); $('#md_modal').load('index.php?v=d&plugin=conso&modal=configure.subType').dialog('open'); }); $('.eqLogicAttr[data-l1key=configuration][data-l2key=rateMode]').on('change', function () { $('.rate').hide(); $('.rate.' + $(this).value()).show(); }); $('.dtimepicker').datetimepicker({lang: 'fr', format: 'Y-m-d', timepicker:false, step: 15 }); //$('.dtimepicker').datetimepicker({ // lang: 'fr', // datepicker: false, // format: 'H:i', // step: 15 //}); function showbytype(type){ if (type == 'electricity' || type == 'electprod'){ $('.energy').show(); $('.water').hide(); $('.gaz').hide(); } else if (type == 'gaz'){ $('.gaz').show(); $('.water').hide(); $('.energy').hide(); } else{ $('.gaz').hide(); $('.energy').hide(); $('.water').show(); } showcommandetype(); } function saveEqLogic(_eqLogic) { if (!isset(_eqLogic.configuration)) { _eqLogic.configuration = {}; } _eqLogic.configuration.confconso = $('#div_confconso .confconso').getValues('.confconsoAttr'); return _eqLogic; } function printEqLogic(_eqLogic) { $('#div_confconso').empty(); $('#div_costconso').empty(); $('#bt_addconsoEqLogic').show(); if (isset(_eqLogic.configuration)) { if (isset(_eqLogic.configuration.confconso)) { for (var i in _eqLogic.configuration.confconso) { $('#bt_addconsoEqLogic').hide(); addConfconso(_eqLogic.configuration.confconso[i]); // addCmdToTable(_eqLogic.configuration.confconso[i]); if(_eqLogic.configuration.parent_id=="") $('.eqLogicAttr[data-l1key=configuration][data-l2key=parent_id] option:eq(0)').prop('selected', true); } } } var type = $('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').value(); showbytype(type); hideMyEcq(); } $("#table_cmd").sortable({axis: "y", cursor: "move", items: ".cmd", placeholder: "ui-state-highlight", tolerance: "intersect", forcePlaceholderSize: true}); function addCmdToTable(_cmd) { if (!isset(_cmd)) { var _cmd = {configuration: {}}; } var tr = ''; tr += ''; tr += '
'; tr += '
'; tr += ' {{Icône}}'; tr += ''; tr += '
'; tr += '
'; tr += ''; tr += '
'; tr += '
'; tr += ''; tr += ''; tr += ''; tr += ''; tr += ''; tr += ''; tr += ''; tr += '
'; tr += ''; tr += ' '; tr += ''; tr += ''; tr += ''; tr += ''; tr += ' '; tr += ' '; // tr += ' '; tr += ''; tr += ''; // tr += ''; // tr += ''; tr += ''; // tr += ' '; // tr += ''; tr += ''; tr += ''; if (is_numeric(_cmd.id)) { tr += ' '; tr += ' Tester'; } tr += ''; tr += ''; $('#table_cmd tbody').append(tr); var tr = $('#table_cmd tbody tr:last'); jeedom.eqLogic.builSelectCmd({ id: $(".li_eqLogic.active").attr('data-eqLogic_id'), filter: {type: 'info'}, error: function (error) { $('#div_alert').showAlert({message: error.message, level: 'danger'}); }, success: function (result) { tr.find('.cmdAttr[data-l1key=value]').append(result); tr.find('.cmdAttr[data-l1key=configuration][data-l2key=updateCmdId]').append(result); tr.setValues(_cmd, '.cmdAttr'); jeedom.cmd.changeType(tr, init(_cmd.subType)); } }); $('#table_cmd .cmdAction[data-action=remove]').hide(); } $('.eqLogicAttr[data-l1key=configuration][data-l2key=type_abo]').on('change', function () { showcommandetype(); showParent(); }); function addConfconso(_conso) { if (!isset(_conso)) { _conso = {}; } var div = '
'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += ' 
'; div += '
'; //if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').value() == 'electricity') { div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += '  (en Wh)
'; div += '
'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += '  (en Wh)
'; div += '
'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += '  (en Wh)
'; div += '
'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += '  Votre équipement est allumé ou éteint (Type : numerique 0 ou 1 )
'; div += '

'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += '  Puissance apparente instantanée (Type : numerique)
'; div += '

'; div += '
'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += '  Tranche tarifaire ( attention ce n est pas OPTARIF Type d abonnement ) (Type : Autre)
'; div += '
'; div += '
'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += '  Intensité instantanée
'; div += '
'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += '  Intensité maximale
'; div += '
'; div += '
'; div += ''; div += '
'; div += ''; div += '
'; div += '
'; div += 'Tester '; div += ''; div += '  (en °C)
'; div += '
'; //div += '
'; //div += ''; //div += '
'; //div += ''; //div += '
'; // div += '
'; // div += ''; // div += '
'; div += '
'; $('#div_confconso').append(div); $('#div_confconso').find('.confconso:last').setValues(_conso, '.confconsoAttr'); showcommandetype(); } function showParent() { if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=parent_id]').value() == ''){ $('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').removeAttr('disabled'); $('.eqLogicAttr[data-l1key=configuration][data-l2key=type_abo]').removeAttr('disabled'); $('.eqLogicAttr[data-l1key=configuration][data-l2key=abo_power]').removeAttr('disabled'); $('.parent').show(); $('.total').show(); $('.default').show(); $('.abonnement').hide(); $('.Puissance_Personalise').hide(); $('#puissance_individuel').hide(); if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').value() == 'electricity'){ $('.existe_production').show(); } else { $('.existe_production').hide(); } document.getElementById("puissance").checked = false; }else{ document.getElementById("total").checked = false; document.getElementById("default").checked = false; $('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').attr('disabled', 'disabled'); $('.eqLogicAttr[data-l1key=configuration][data-l2key=type_abo]').attr('disabled', 'disabled'); $('.eqLogicAttr[data-l1key=configuration][data-l2key=abo_power]').attr('disabled', 'disabled'); $('.eqLogicAttr[data-l1key=configuration][data-l2key=production_sup]').removeAttr('disabled'); $('.abonnement').show(); $('.Puissance_Personalise').show(); $('.existe_production').hide(); $('.total').hide(); $('.default').hide(); $('.parent').hide(); } } function showcommandetype() { if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').value() == 'electricity' || $('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').value() == 'electprod'){ $('.energy').show(); $('.energytemp').show(); $('.water').hide(); $('.gaz').hide(); showParent(); if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=puissance]').value() == '1'){ $('#puissance_compteur').hide(); $('#puissance_individuel').show(); } else { $('#puissance_compteur').show(); $('#puissance_individuel').hide(); } if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=onlypower]').value() == '1'){ $('.noconso').hide(); $('.energyhp').hide(); $('.cmd_etat').show(); $('.conso').show(); $('.variation').hide(); $('.labelleindexpapp').html('Puissance électrique déclarée'); $('.descpapp').html('  (Wh) La puissance consommée de vos ampoules ou équipements une fois mesurée'); /*return;*/ }else { $('.labelleindexpapp').html('PAPP'); $('.descpapp').html('  Puissance apparente instantanée (Type : numerique)'); $('.energyhp').show(); $('.cmd_etat').hide(); } if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=onlyconso]').value() == '1'){ $('.noconso').hide(); $('.labelleindexhp').text('Consommation'); $('.labelvariationmax').text('Variation max autorisée entre 2 mesures'); $('.conso').show(); $('.variation').show(); $('.cmd_etat').hide(); } else{ $('.noconso').show(); $('#confighchc').show(); $('.conso').hide(); $('.variation').hide(); $('#ptec').show(); if($('.eqLogicAttr[data-l1key=configuration][data-l2key=type_abo]').value() == 'HCHP'){ $('.labelleindexhp').text('Index Heure Pleine'); $('.labelleindexhc').text('Index Heure Creuse'); $("#hchp_unity").val("1"); if($('.eqLogicAttr[data-l1key=configuration][data-l2key=onlypower]').value() == '1'){ $('#confighchc').hide(); } }else{ $('#ptec').hide(); $('#ptecvalue').value("HP"); /*$('.noconso').hide();*/ $('#confighchc').hide(); $('.labelleindexhp').text('Index Heure de Base'); /*$('.conso').show();*/ } } } else if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').value() == 'gaz'){ $('.cmd_etat').hide(); $('.energy').hide(); $('.water').hide(); $('.gaz').show(); $('.energytemp').show(); } else{ if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=type]').value() == 'oil'){ $('.energytemp').show(); } else { $('.energytemp').hide(); } $('.cmd_etat').hide(); $('.energy').hide(); $('.gaz').hide(); $('.water').show(); } } function hideMyEcq(){ var id = $(".li_eqLogic.active").attr('data-eqLogic_id'); $('.optionparent').show(); $('#equipementparent_'+id).hide(); } $('#parent_object').on('change', function () { showParent(); }); $('#onlyconso').on('click', function () { if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=onlypower]').value() == '1') { $( "#onlypower" ).prop( "checked", false ); } showcommandetype(); }); $('#onlypower').on('click',function () { if ($('.eqLogicAttr[data-l1key=configuration][data-l2key=onlyconso]').value() == '1'){ $( "#onlyconso" ).prop( "checked", false ); } showcommandetype(); }); $('#puissance').on('click',function () { showcommandetype(); }); $(function () { $('[data-toggle="tooltip"]').tooltip(); }) $('.eqLogicAction[data-action=gotoPluginPartenaire]').on('click', function () { $('#md_modal').dialog({title: "{{Plugin Partenaire}}"}); $("#md_modal").load('index.php?v=d&m=conso&p=partenaire&ajax=1').dialog('open'); });