From b89f993d6c9401126c53a4590c838c46465e1434 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 20 Oct 2019 14:20:14 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 36 ++++++++++++++++++------------------ config/media.php | 3 ++- config/rooms.php | 2 +- js/home.js | 22 ++++++++++++++++++++++ scripts/checkstate.php | 13 +++++++++++++ scripts/lib/lib.php | 11 ++++++++++- scripts/pcgames.php | 8 ++++++++ 7 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 scripts/checkstate.php create mode 100644 scripts/pcgames.php diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 255c2de..ff73955 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,16 +2,13 @@ + + - - - - - - - - - + + + + diff --git a/config/media.php b/config/media.php index c3864a3..03fbcc4 100644 --- a/config/media.php +++ b/config/media.php @@ -9,6 +9,7 @@ $shortcuts['media'][] = ['label' => 'Séries TV', 'type' => 'sub', 'sub' => 'ser $shortcuts['media'][] = ['label' => 'Films', 'type' => 'sub', 'sub' => 'movies']; if ($device == 'salon' || $device == 'bureau') { $shortcuts['media'][] = ['label' => 'Nintendo Switch', 'type' => 'harmonyactivity', 'activity' => 'nintendo-switch']; + $shortcuts['media'][] = ['label' => 'Jeux PC', 'type' => 'ajax', 'url' => '/scripts/pcgames.php']; $shortcuts['media'][] = ['label' => 'Vidéo web', 'type' => 'raspberrycast']; } @@ -33,7 +34,7 @@ if (is_array($recent)) { profile('Got recents', __FILE__, __LINE__); } -if(is_array($media)) { +if (is_array($media)) { foreach ($media as $id => $mediagroup) { if ($id == 'x' && !isset($_GET['x'])) { continue; diff --git a/config/rooms.php b/config/rooms.php index a582122..c41b9f4 100644 --- a/config/rooms.php +++ b/config/rooms.php @@ -45,7 +45,7 @@ function lit($additionnalfavorites = array()) function home() { $favorites = [ - ['type' => 'light', 'scene' => 'home/welcome', 'label' => 'Bienvenue'], + ['type' => 'light', 'scene' => 'home/welcome', 'label' => 'Bienvenue', 'confirm' => ['message' => 'Quelqu\'un dort peut-être. Veuillez confirmer votre action.', 'conditions' => ['night' => '1']]], ['type' => 'light', 'scene' => 'home/off', 'label' => 'éteindre'], ]; $all = array_merge($favorites, [ diff --git a/js/home.js b/js/home.js index 9dfa37e..f1896cd 100644 --- a/js/home.js +++ b/js/home.js @@ -87,6 +87,28 @@ $(function () { return true; }); + $(document).on(clickevent, '[data-confirm]:not(.confirmok)', function (e) { + var $this = $(this); + e.preventDefault(); + e.stopPropagation(); + e.stopImmediatePropagation(); + + var needsconfirm; + $.get('scripts/checkstate.php?state=' + encodeURIComponent($(this).attr('data-confirm')), function (data) { + needsconfirm = data === '1'; + + if (!needsconfirm || window.confirm($this.data('confirm-message'))) { + $this.addClass('confirmok'); + $this.click(); + setTimeout(function () { + $this.removeClass('confirmok'); + }, 500); + } + }); + + return false; + }); + $(document).on(clickevent, '[data-volume]', function () { $.get('scripts/volume.php?volume=' + $(this).data('volume') + '%'); return true; diff --git a/scripts/checkstate.php b/scripts/checkstate.php new file mode 100644 index 0000000..cd958ee --- /dev/null +++ b/scripts/checkstate.php @@ -0,0 +1,13 @@ + $v) { + if (getState($k) != $v) { + $res = false; + break; + } +} +header('Content-Type: text/plain'); +echo $res ? '1' : '0'; \ No newline at end of file diff --git a/scripts/lib/lib.php b/scripts/lib/lib.php index 3400b8e..d9a5def 100644 --- a/scripts/lib/lib.php +++ b/scripts/lib/lib.php @@ -200,7 +200,10 @@ function shortcut($s, $hash) $swcorner = ''; - if ($s['type'] == 'task') { + if ($s['type'] == 'ajax') { + $attrs['class'] = 'ajax'; + $attrs['href'] = $s['url']; + } elseif ($s['type'] == 'task') { $attrs['class'] = 'ajax'; $attrs['href'] = 'scripts/tortugatask.php?task=' . $s['command']; } elseif ($s['type'] == 'light') { @@ -332,6 +335,12 @@ function shortcut($s, $hash) $attrs['data-volume'] = $s['volume']; } + if (isset($s['confirm'])) { + $attrs['data-confirm'] = json_encode($s['confirm']['conditions']); + $attrs['data-confirm-message'] = $s['confirm']['message']; + } + + if (isset($html)) { $res = $html; } else { diff --git a/scripts/pcgames.php b/scripts/pcgames.php new file mode 100644 index 0000000..0581549 --- /dev/null +++ b/scripts/pcgames.php @@ -0,0 +1,8 @@ +