/* 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 = '