From 4c0862efe57fbdaa51a69c8dc39f6fc4ae45fa20 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 19 Mar 2021 13:54:22 +0100 Subject: [locations/rebootcontrol] Inherit openingtimes for WOL/shutdown The opening times schedule is now inherited to child locations, so it's easy to toggle WOL or shutdown for individual rooms in a building, where you only have to set the opening times once for the entire building. As of now, WOL and shutdown settings are *not* inherited to child locations, as I'm not sure if you always want to inherit those by default. Closes #3710 --- .../locations/inc/openingtimes.inc.php | 28 +++++++++++ modules-available/locations/install.inc.php | 7 ++- .../locations/lang/de/template-tags.json | 1 + .../locations/lang/en/template-tags.json | 1 + modules-available/locations/pages/details.inc.php | 55 ++++++++-------------- .../locations/templates/ajax-opening-location.html | 17 ++++++- 6 files changed, 69 insertions(+), 40 deletions(-) create mode 100644 modules-available/locations/inc/openingtimes.inc.php (limited to 'modules-available/locations') diff --git a/modules-available/locations/inc/openingtimes.inc.php b/modules-available/locations/inc/openingtimes.inc.php new file mode 100644 index 00000000..3417a213 --- /dev/null +++ b/modules-available/locations/inc/openingtimes.inc.php @@ -0,0 +1,28 @@ + $locationid, 'openingtime' => $openingTimes)); if (Module::isAvailable('rebootcontrol')) { - if ($wol || $sd) { - $options = array(); - - // Sanity checks - if ($woloffset > 15) { - $woloffset = 15; - } elseif ($woloffset < 0) { - $woloffset = 0; - } - if ($sdoffset > 15) { - $sdoffset = 15; - } elseif ($sdoffset < 0) { - $sdoffset = 0; - } - - // Set options - $options['wol'] = $wol; - $options['wol-offset'] = $woloffset; - $options['sd'] = $sd; - $options['sd-offset'] = $sdoffset; - - Scheduler::updateSchedule($locationid, $options, $openingTimes); - - } else { - Scheduler::deleteSchedule($locationid); - } + // Set options + Scheduler::setLocationOptions($locationid, $wol, $sd, $woloffset, $sdoffset); } } @@ -429,25 +408,29 @@ class SubPage private static function ajaxOpeningTimes($id) { User::assertPermission('location.edit.openingtimes', $id); - $openTimes = Database::queryFirst("SELECT openingtime FROM `location` WHERE locationid = :id", array('id' => $id)); - if ($openTimes !== false) { + $data = ['id' => $id]; + $openTimes = Database::queryFirst("SELECT openingtime FROM `location` + WHERE locationid = :id", array('id' => $id)); + if ($openTimes === false) { + Message::addError('invalid-location-id', $id); + return; + } + if ($openTimes['openingtime'] !== null) { $openingTimes = json_decode($openTimes['openingtime'], true); + } else { + $openingTimes = OpeningTimes::forLocation($id); + $data['openingtimes_inherited'] = 'checked'; } if (!isset($openingTimes) || !is_array($openingTimes)) { $openingTimes = array(); } - $data = array('id' => $id); $data['expertMode'] = !self::isSimpleMode($openingTimes); $data['schedule_data'] = json_encode($openingTimes); $rebootcontrol = Module::isAvailable('rebootcontrol'); $data['rebootcontrol'] = $rebootcontrol; if ($rebootcontrol) { - $res = Database::queryFirst("SELECT action, nextexecution, options FROM `reboot_scheduler` - WHERE locationid = :id", ['id' => $id]); - if ($res !== false) { - $data['scheduler-options'] = json_decode($res['options'], true); - } + $data['scheduler-options'] = Scheduler::getLocationOptions($id); } echo Render::parse('ajax-opening-location', $data); diff --git a/modules-available/locations/templates/ajax-opening-location.html b/modules-available/locations/templates/ajax-opening-location.html index b1aea2e2..5c741857 100644 --- a/modules-available/locations/templates/ajax-opening-location.html +++ b/modules-available/locations/templates/ajax-opening-location.html @@ -1,5 +1,10 @@

{{lang_openingTime}}

+
+ + +
{{^expertMode}}
@@ -135,7 +140,7 @@
+ value="{{scheduler-options.wol-offset}}" placeholder="0" min="0" max="60"> @@ -152,7 +157,7 @@
+ value="{{scheduler-options.sd-offset}}" placeholder="0" min="0" max="60"> @@ -204,6 +209,7 @@ $loc.find('.new-openingtime').click(function (e) { e.preventDefault(); setTimepicker(newOpeningTime($loc, {}).find('.timepicker2')); + setInputEnabled(); }); $loc.find('.btn-show-expert').click(function (e) { @@ -214,9 +220,16 @@ } $loc.find('.simple-mode').remove(); $loc.find('.expert-mode').show(); + setInputEnabled(); }); $loc.find('form').submit(validateOpeningTimes); + var setInputEnabled = function () { + $loc.find('.expert-mode input, .simple-mode input').prop('disabled', $inheritCb.is(':checked') ? 'disabled' : false); + }; + var $inheritCb = $loc.find('.openingtimes-inherited'); + setInputEnabled(); + $inheritCb.change(setInputEnabled); })(); -- cgit v1.2.3-55-g7522