Skip to content

Commit

Permalink
Update scenario.php
Browse files Browse the repository at this point in the history
Go back before this PR
27fab5d

For stable
  • Loading branch information
Phpvarious authored Nov 13, 2023
1 parent 18ea06b commit a951014
Showing 1 changed file with 78 additions and 88 deletions.
166 changes: 78 additions & 88 deletions desktop/modal/scenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,58 @@

ini_set('display_errors', 0);
if (!isConnect('admin')) {
throw new Exception('{{401 - Accès non autorisé}}');
throw new Exception('{{401 - Accès non autorisé}}');
}
?>
<div class="col-lg-12 col-md-12 col-sm-12 eqLogicPluginDisplay">
<legend><i class="fas fa-cogs"></i> {{Scénarios}}
<!--<a id="bt_saveScenarios" class="btn btn-sm btn-success pull-right" ><i class="fas fa-check-circle"></i> {{Sauvegarder}}</a>-->
</legend>
<legend><i class="fas fa-cogs"></i> {{Scénarios}}
<!--<a id="bt_saveScenarios" class="btn btn-sm btn-success pull-right" ><i class="fas fa-check-circle"></i> {{Sauvegarder}}</a>-->
</legend>

<div>
<table id="table_scenarioSummary" class="table table-bordered table-condensed tablesorter">
<thead>
<tr>
<th>{{ID}}</th>
<th>{{Scénario}}</th>
<th data-sorter="checkbox" data-filter="false">{{Transmis}}</th>
<!--<th data-sorter="false" data-filter="false">{{Actions}}</th>-->
</tr>
</thead>
<tbody>
<?php
$scenarios = scenario::all();
foreach ($scenarios as $scenario) {
$check = 'unchecked';
$scenario_id = $scenario->getId();
if ($scenario->getDisplay('sendToApp', 0) == 1) {
$check = 'checked';
}
$tr = '<tr data-id="' . $scenario_id . '"><td>' . $scenario_id . '</td>';
$tr .= '<td>' . $scenario->getHumanName() . '</td>';
$tr .= '<td><label><input type="checkbox" class="configuration sendtoapp" value="' . $scenario_id . '" ' . $check . ' title="{{Envoyer à l\'application}}"/></label></td>';
/*$tr .= '<td><a class="btn btn-xs btn-success bt_saveScenario"><i class="fas fa-save"></i></a>';*/
$tr .= '</tr>';
echo $tr;
}
?>
</tbody>
</table>
</div>
</div>
<div>
<table id="table_scenarioSummary" class="table table-bordered table-condensed tablesorter">
<thead>
<tr>
<th>{{ID}}</th>
<th>{{Scénario}}</th>
<th data-sorter="checkbox" data-filter="false">{{Transmis}}</th>
<!--<th data-sorter="false" data-filter="false">{{Actions}}</th>-->
</tr>
</thead>
<tbody>
<?php
$scenarios = scenario::all();
foreach ($scenarios as $scenario) {
$check = 'unchecked';
$scenario_id = $scenario->getId();
if ($scenario->getDisplay('sendToApp', 0) == 1) {
$check = 'checked';
}
$tr = '<tr data-id="' . $scenario_id . '"><td>' . $scenario_id . '</td>';
$tr .= '<td>' . $scenario->getHumanName() . '</td>';
$tr .= '<td><label><input type="checkbox" class="configuration sendtoapp" value="' . $scenario_id . '" ' . $check . ' title="{{Envoyer à l\'application}}"/></label></td>';
/*$tr .= '<td><a class="btn btn-xs btn-success bt_saveScenario"><i class="fas fa-save"></i></a>';*/
$tr .= '</tr>';
echo $tr;
}
?>
</tbody>
</table>
</div>

<script>
var table_scenarioSummary = document.getElementById('table_scenarioSummary')
new DataTable(table_scenarioSummary, {
columns: [{
select: 1,
sort: "asc"
},
{
select: [2],
sortable: false
}
],
paging: true,
perPage: 20,
perPageSelect: [10, 20, 30, 50, 100, 200],
searchable: true,
})
<script>
jeedomUtils.initTableSorter();
var tableScSummary = $('#table_scenarioSummary')
tableScSummary[0].config.widgetOptions.resizable_widths = ['60px', '', '100px']
tableScSummary.trigger('applyWidgets')
tableScSummary.trigger('resizableReset')
tableScSummary.trigger('sorton', [
[
[1, 0]
]
])

/*$('#bt_saveScenarios').off('click').on('click', function () {
/*$('#bt_saveScenarios').off('click').on('click', function () {
console.log('save all scenarios')
$('#table_scenarioSummary tbody tr').each(function(){
var scID = $(this).attr('data-id')
Expand All @@ -91,38 +84,35 @@

})*/

document.getElementById('table_scenarioSummary')?.addEventListener('click', function(event) {
var _target = null
var sendApp = 0
if (_target = event.target.closest('.sendtoapp')) {
idScenario = _target.value
if (_target.checked == true) sendApp = 1;
domUtils.ajax({
type: "POST",
url: "plugins/mobile/core/ajax/mobile.ajax.php",
data: {
action: "savescenario",
id: idScenario,
valueSend: sendApp
},
dataType: 'json',
global: false,
error: function(error) {
jeedomUtils.showAlert({
message: error.message,
level: 'danger'
})
},
success: function(data) {
if (data.state != 'ok') {
jeedomUtils.showAlert({
message: data.result,
level: 'danger'
})
return;
}
}
})
}
})
</script>
$('.sendtoapp').click(function() {
idScenario = $(this).val();
if ($(this).is(':checked')) {
sendApp = 1;
} else {
sendApp = 0;
}
$.ajax({
type: "POST",
url: "plugins/mobile/core/ajax/mobile.ajax.php",
data: {
action: "savescenario",
id: idScenario,
valueSend: sendApp
},
dataType: 'json',
global: false,
error: function(request, status, error) {
handleAjaxError(request, status, error);
},
success: function(data) {
if (data.state != 'ok') {
$('#div_alert').showAlert({
message: data.result,
level: 'danger'
});
return;
}
}
});
})
</script>

0 comments on commit a951014

Please sign in to comment.