summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo
diff options
context:
space:
mode:
authorJannik Schönartz2017-11-30 12:59:49 +0100
committerJannik Schönartz2017-11-30 12:59:49 +0100
commite88a313149cb39e187baf74a2fc18cc7c5d86d81 (patch)
treef2019cc85e1ff50d0708cb4828357b2d7e6f1d7a /modules-available/locationinfo
parent[inc/Database] Do EXPLAIN SELECT at shutdown so we don't interfere with SQL_C... (diff)
downloadslx-admin-e88a313149cb39e187baf74a2fc18cc7c5d86d81.tar.gz
slx-admin-e88a313149cb39e187baf74a2fc18cc7c5d86d81.tar.xz
slx-admin-e88a313149cb39e187baf74a2fc18cc7c5d86d81.zip
[locationinfo] Reworked summary-panel to the new panel uuid stuff.
Diffstat (limited to 'modules-available/locationinfo')
-rw-r--r--modules-available/locationinfo/api.inc.php52
-rw-r--r--modules-available/locationinfo/inc/infopanel.inc.php3
-rw-r--r--modules-available/locationinfo/inc/locationinfo.inc.php76
-rw-r--r--modules-available/locationinfo/lang/de/template-tags.json1
-rw-r--r--modules-available/locationinfo/page.inc.php47
-rw-r--r--modules-available/locationinfo/templates/frontend-summary.html43
-rw-r--r--modules-available/locationinfo/templates/page-config-panel-summary.html208
7 files changed, 342 insertions, 88 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index e14fe9d7..33a0f3db 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -1,33 +1,5 @@
<?php
-if (Request::get('redirect', false, 'int') !== false) {
- // Redirect to actual panel from uuid
- $uuid = Request::get('uuid', false, 'string');
- if ($uuid === false) {
- http_response_code(400);
- die('Missing uuid parameter');
- }
- $row = Database::queryFirst('SELECT paneltype, panelconfig FROM locationinfo_panel WHERE paneluuid = :uuid', compact('uuid'));
- if ($row === false) {
- http_response_code(404);
- die('Panel not found');
- }
- if ($row['paneltype'] === 'DEFAULT') {
- Util::redirect(dirname($_SERVER['SCRIPT_NAME']) . '/modules/locationinfo/frontend/doorsign.html?uuid=' . $uuid);
- } elseif ($row['paneltype'] === 'SUMMARY') {
- Util::redirect(dirname($_SERVER['SCRIPT_NAME']) . '/modules/locationinfo/frontend/overview.html?uuid=' . $uuid);
- } elseif ($row['paneltype'] === 'URL') {
- $data = json_decode($row['panelconfig'], true);
- if (!$data || !isset($data['url'])) {
- http_response_code('500');
- die('Panel config corrupted on server');
- }
- Util::redirect($data['url']);
- }
- http_response_code('500');
- die('Panel has invalid type "' . $row['paneltype'] . '"');
-}
-
/*
* vvv - API to Panel - vvv
*/
@@ -46,7 +18,7 @@ function HandleParameters()
if ($get === "timestamp") {
$output = array('ts' => getLastChangeTs($uuid));
} elseif ($get === "machines") {
- $locationIds = getLocationsOr404($uuid);
+ $locationIds = LocationInfo::getLocationsOr404($uuid);
$output = array();
InfoPanel::appendMachineData($output, $locationIds, false);
$output = array_values($output);
@@ -57,13 +29,13 @@ function HandleParameters()
die('Panel not found');
}
} elseif ($get === "pcstates") {
- $locationIds = getLocationsOr404($uuid);
+ $locationIds = LocationInfo::getLocationsOr404($uuid);
$output = getPcStates($locationIds);
} elseif ($get === "locationtree") {
- $locationIds = getLocationsOr404($uuid);
+ $locationIds = LocationInfo::getLocationsOr404($uuid);
$output = getLocationTree($locationIds);
} elseif ($get === "calendar") {
- $locationIds = getLocationsOr404($uuid);
+ $locationIds = LocationInfo::getLocationsOr404($uuid);
$output = getCalendar($locationIds);
}
if ($output !== false) {
@@ -76,22 +48,6 @@ function HandleParameters()
}
/**
- * Return list of locationids associated with given panel.
- * @param string $paneluuid panel
- * @return int[] locationIds
- */
-function getLocationsOr404($paneluuid)
-{
- $panel = Database::queryFirst('SELECT locationids FROM locationinfo_panel WHERE paneluuid = :paneluuid',
- compact('paneluuid'));
- if ($panel !== false) {
- return array_map('intval', explode(',', $panel['locationids']));
- }
- http_response_code(404);
- die('Panel not found');
-}
-
-/**
* Get last config modification timestamp for given panel.
* This was planned to be smart and check the involved locations,
* even going up the location tree if the opening time schedule
diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php
index c612e518..dacf860f 100644
--- a/modules-available/locationinfo/inc/infopanel.inc.php
+++ b/modules-available/locationinfo/inc/infopanel.inc.php
@@ -20,6 +20,7 @@ class InfoPanel
}
if ($panel['paneltype'] === 'URL') {
+ // Shortcut for URL redirect
$config = json_decode($panel['panelconfig'], true);
return $panel['paneltype'];
}
@@ -31,6 +32,7 @@ class InfoPanel
if (!empty($panel['panelconfig'])) {
$json = json_decode($panel['panelconfig'], true);
if (is_array($json)) {
+ // Put location-specific overrides in separate variable for later use
if (isset($json['overrides']) && is_array($json['overrides'])) {
$overrides = $json['overrides'];
}
@@ -48,6 +50,7 @@ class InfoPanel
'id' => $lid,
'name' => isset($locations[$lid]) ? $locations[$lid]['locationname'] : 'noname00.pas',
);
+ // Now apply any overrides from above
if (isset($overrides[$lid]) && is_array($overrides[$lid])) {
$config['locations'][$lid]['config'] = $overrides[$lid];
}
diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php
index 933eaf4d..64070cd4 100644
--- a/modules-available/locationinfo/inc/locationinfo.inc.php
+++ b/modules-available/locationinfo/inc/locationinfo.inc.php
@@ -23,6 +23,32 @@ class LocationInfo
}
/**
+ * Return list of locationids associated with given panel.
+ * @param string $paneluuid panel
+ * @param bool $recursive if true and paneltype == SUMMARY the result is recursive with all child room ids.
+ * @return int[] locationIds
+ */
+ public static function getLocationsOr404($paneluuid, $recursive = true)
+ {
+ $panel = Database::queryFirst('SELECT paneltype, locationids FROM locationinfo_panel WHERE paneluuid = :paneluuid',
+ compact('paneluuid'));
+ if ($panel !== false) {
+ $idArray = array_map('intval', explode(',', $panel['locationids']));
+ if ($panel['paneltype'] == "SUMMARY" && $recursive) {
+ $idList = Location::getRecursiveFlat($idArray);
+ $idArray = array();
+
+ foreach ($idList as $key => $value) {
+ $idArray[] = $key;
+ }
+ }
+ return $idArray;
+ }
+ http_response_code(404);
+ die('Panel not found');
+ }
+
+ /**
* Set current error message of given server. Pass null or false to clear.
*
* @param int $serverId id of server
@@ -47,27 +73,38 @@ class LocationInfo
}
/**
- * Creates and returns a default config for room that didn't saved a config yet.
+ * Creates and returns a default config for room that didn't save a config yet.
*
* @return array Return a default config.
*/
public static function defaultPanelConfig($type)
{
- return array(
- 'language' => 'en',
- 'mode' => 1,
- 'vertical' => false,
- 'eco' => false,
- 'prettytime' => true,
- 'scaledaysauto' => true,
- 'daystoshow' => 7,
- 'rotation' => 0,
- 'scale' => 50,
- 'switchtime' => 20,
- 'calupdate' => 30,
- 'roomupdate' => 15,
- 'configupdate' => 180,
- );
+ if ($type === 'DEFAULT') {
+ return array(
+ 'language' => 'en',
+ 'mode' => 1,
+ 'vertical' => false,
+ 'eco' => false,
+ 'prettytime' => true,
+ 'scaledaysauto' => true,
+ 'daystoshow' => 7,
+ 'rotation' => 0,
+ 'scale' => 50,
+ 'switchtime' => 20,
+ 'calupdate' => 30,
+ 'roomupdate' => 15,
+ 'configupdate' => 180,
+ );
+ }
+ if ($type === 'SUMMARY') {
+ return array(
+ 'language' => 'en',
+ 'calupdate' => 30,
+ 'roomupdate' => 15,
+ 'configupdate' => 180,
+ );
+ }
+ return array();
}
/**
@@ -81,6 +118,12 @@ class LocationInfo
return $ret['panelname'];
}
+ /**
+ * Hook called by runmode module where we should modify the client config according to our
+ * needs. Disable standby/logout timeouts, enable autologin, set URL.
+ * @param $machineUuid
+ * @param $panelUuid
+ */
public static function configHook($machineUuid, $panelUuid)
{
$row = Database::queryFirst('SELECT paneltype, panelconfig FROM locationinfo_panel WHERE paneluuid = :uuid',
@@ -98,6 +141,7 @@ class LocationInfo
ConfigHolder::add('SLX_ADDONS', '', 1000);
ConfigHolder::add('SLX_LOGOUT_TIMEOUT', '', 1000);
ConfigHolder::add('SLX_SCREEN_STANDBY_TIMEOUT', '', 1000);
+ ConfigHolder::add('SLX_SYSTEM_STANDBY_TIMEOUT', '', 1000);
ConfigHolder::add('SLX_AUTOLOGIN', '1', 1000);
}
diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json
index 1574d9e8..265f3444 100644
--- a/modules-available/locationinfo/lang/de/template-tags.json
+++ b/modules-available/locationinfo/lang/de/template-tags.json
@@ -24,6 +24,7 @@
"lang_ecoMode": "E-Ink Modus",
"lang_ecoTooltip": "Anstelle der Farb-basierten PC-Status Bilder, werden Symbol-basierte PC Bilder verwendet",
"lang_editDefaultPanelHints": "Hier k\u00f6nnen Sie ein Panel (z.B. digitales T\u00fcrschild) in Aussehen und Funktionsweise definieren. Um im Kalender \u00d6ffnungszeiten anzeigen zu k\u00f6nnen, m\u00fcssen Sie im Tab \"Raum-\/Ortsbezogene Einstellungen\" f\u00fcr den ausgew\u00e4hlten Raum entsprechend \u00d6ffnungszeiten eintragen. Damit im Kalender Veranstaltungen und andere Termine angezeigt werden k\u00f6nnen, muss ein funktionierendes Backend konfiguriert und den ausgew\u00e4hlten R\u00e4umen zugewiesen worden sein.",
+ "lang_editSummaryPanelHints": "Hier k\u00f6nnen Sie ein Summary-Panel definieren. Das Panel zeigt eine Übersicht der in den R\u00e4umen enthalten PCs.",
"lang_editPanel": "Panel bearbeiten",
"lang_entryName": "Name",
"lang_error": "Fehler",
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index 30c38362..847dc73a 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -254,11 +254,14 @@ class Page_LocationInfo extends Page
$params = $this->preparePanelConfigDefault();
} elseif ($paneltype === 'URL') {
$params = $this->preparePanelConfigUrl();
+ } elseif ($paneltype === 'SUMMARY') {
+ $params = $this->preparePanelConfigSummary();
} else {
Message::addError('invalid-panel-type', $paneltype);
Util::redirect('?do=locationinfo');
}
+
if ($paneluuid === 'new') {
$paneluuid = Util::randomUuid();
$query = "INSERT INTO `locationinfo_panel` (paneluuid, panelname, locationids, paneltype, panelconfig, lastchange)
@@ -320,6 +323,16 @@ class Page_LocationInfo extends Page
return array('config' => $conf, 'locationids' => []);
}
+ private function preparePanelConfigSummary()
+ {
+ // Check locations
+ $locationids = self::getLocationIdsFromRequest(true);
+ if (count($locationids) > 4) {
+ $locationids = array_slice($locationids, 0, 4);
+ }
+ return array('locationids' => $locationids);
+ }
+
/**
* Updates the server settings in the db.
*/
@@ -832,7 +845,7 @@ class Page_LocationInfo extends Page
'url' => $config['url'],
'ssl_checked' => $config['insecure-ssl'] ? 'checked' : '',
));
- } else { // TODO
+ } else {
Render::addTemplate('page-config-panel-summary', array(
'new' => $id === 'new',
'uuid' => $id,
@@ -862,19 +875,37 @@ class Page_LocationInfo extends Page
Util::redirect($config['url']);
}
- $data = array(
- 'uuid' => $uuid,
- 'config' => json_encode($config),
- 'language' => $config['language'],
- );
-
+ $data = array();
preg_match('#^(.*)/#', $_SERVER['PHP_SELF'], $script);
preg_match('#^([^?]+)/#', $_SERVER['REQUEST_URI'], $request);
if ($script[1] !== $request[1]) {
$data['dirprefix'] = $script[1] . '/';
}
- echo Render::parse('frontend-default', $data);
+ if ($type === 'DEFAULT') {
+ $data += array(
+ 'uuid' => $uuid,
+ 'config' => json_encode($config),
+ 'language' => $config['language'],
+ );
+
+ die(Render::parse('frontend-default', $data));
+ }
+
+ if ($type === 'SUMMARY') {
+ $locations = LocationInfo::getLocationsOr404($uuid, false);
+ $config['tree'] = Location::getRecursive($locations);
+ $data += array(
+ 'uuid' => $uuid,
+ 'config' => json_encode($config),
+ 'language' => $config['language'],
+ );
+
+ die(Render::parse('frontend-summary', $data));
+ }
+
+ http_response_code(500);
+ die('Unknown panel type ' . $type);
}
}
diff --git a/modules-available/locationinfo/templates/frontend-summary.html b/modules-available/locationinfo/templates/frontend-summary.html
index dd5fc25d..e117cbcb 100644
--- a/modules-available/locationinfo/templates/frontend-summary.html
+++ b/modules-available/locationinfo/templates/frontend-summary.html
@@ -2,7 +2,8 @@
<html lang="de">
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
<head>
- <script type='text/javascript' src='../../../script/jquery.js'></script>
+ <script type='text/javascript' src='{{dirprefix}}script/jquery.js'></script>
+
<style type='text/css'>
body {
@@ -106,7 +107,7 @@
var rooms = {};
var startdate;
var roomidsString = "";
-
+ var config = {{{config}}};
$(document).ready(function () {
//temp
@@ -115,13 +116,17 @@
});
function init() {
- var ids = getUrlParameter("id");
+ // var ids = getUrlParameter("id");
+
+ /*
$.getJSON("../../../api.php?do=locationinfo&action=locationtree&id=" + ids, function (result) {
generateLayout(result);
setTimeout(update, 1000);
});
-
+ */
+ generateLayout(config.tree);
+ update();
}
function SetUpDate(d) {
@@ -140,7 +145,7 @@
}
/**
- * generates the divs, decidecs if parent or child
+ * generates the divs, decides if parent or child
* @param json Room tree json
* @param myParent parent div
* @param outermost if the object is a root node
@@ -183,13 +188,16 @@
var rommUpdateIds = "";
var count = 0;
var nextUpdate = 15000;
+ // TODO: Only query a few rooms is not possible with the new api stuff ...
for (var property in rooms) {
if (rooms[property].lastCalendarUpdate === null || rooms[property].lastCalendarUpdate + CALUPDATE_MS < MyDate().getTime()) {
+ // TODO: NOT NECESSARY ANYMORE?!
calendarUpdateIds = addIdToUpdateList(calendarUpdateIds, rooms[property].id);
count++;
rooms[property].lastCalendarUpdate = MyDate().getTime();
}
if (rooms[property].lastRoomUpdate === null || rooms[property].lastRoomUpdate + ROOMUPDATE_MS < MyDate().getTime()) {
+ // TODO: NOT NECESSARY ANYMORE?!
rommUpdateIds = addIdToUpdateList(rommUpdateIds, rooms[property].id);
count++;
rooms[property].lastRoomUpdate = MyDate().getTime();
@@ -197,11 +205,11 @@
if (count > 7) break;
}
if (calendarUpdateIds !== "") {
- queryCalendars(calendarUpdateIds);
+ queryCalendars();
nextUpdate = 1000;
}
if (rommUpdateIds !== "") {
- queryRooms(rommUpdateIds);
+ queryRooms();
nextUpdate = 1000;
}
for (var property in rooms) {
@@ -214,6 +222,9 @@
function UpdateTimeTables(json) {
var l = json.length;
for (var i = 0; i < l; i++) {
+ if (rooms[json[i].id] == null) {
+ continue;
+ }
rooms[json[i].id].timetable = json[i].calendar;
for (var property in rooms[json[i].id].timetable) {
rooms[json[i].id].timetable[property].start = new Date(rooms[json[i].id].timetable[property].start);
@@ -225,11 +236,11 @@
/**
* Querys Pc states
- * @param ids Room ID's which should be queried. Format for e.g.: "20,5,6"
+ * Room are queried with the {{uuid}} of the panel.
*/
- function queryRooms(ids) {
+ function queryRooms() {
$.ajax({
- url: "../../../api.php?do=locationinfo&action=pcstates&id=" + ids,
+ url: "{{dirprefix}}api.php?do=locationinfo&get=pcstates&uuid={{uuid}}",
dataType: 'json',
cache: false,
timeout: 30000,
@@ -241,6 +252,7 @@
return;
}
updatePcStates(result);
+
}, error: function () {
}
@@ -526,7 +538,7 @@
* @param broken PC's that are broken
*/
function updateRoomUsage(id, idle, occupied, off, broken) {
- if (idle == 0 && occupied == 0 && off == 0) {
+ if (idle == 0 && occupied == 0 && off == 0 && broken == 0) {
$('#parent_' + id).parent().hide();
return;
}
@@ -634,10 +646,11 @@
/**
* querys the Calendar data
- * @param ids ID'S of rooms to query as string, for e.g.: "5,17,8" or "5"
+ * Calender is queried with the {{uuid}} of the panel.
+ * api.inc.php / page.inc.php is getting the ids with the panel uuid.
*/
- function queryCalendars(ids) {
- var url = "../../../api.php?do=locationinfo&action=calendar&id=" + ids;
+ function queryCalendars() {
+ var url = "{{dirprefix}}api.php?do=locationinfo&get=calendar&uuid={{uuid}}";
// Todo reimplement Frontend methode if needed
/*
@@ -652,8 +665,6 @@
timeout: 30000,
success: function (result) {
UpdateTimeTables(result);
-
-
}, error: function () {
}
diff --git a/modules-available/locationinfo/templates/page-config-panel-summary.html b/modules-available/locationinfo/templates/page-config-panel-summary.html
new file mode 100644
index 00000000..2a968fc2
--- /dev/null
+++ b/modules-available/locationinfo/templates/page-config-panel-summary.html
@@ -0,0 +1,208 @@
+<h2>
+ {{#new}}{{lang_createPanel}}{{/new}}
+ {{^new}}{{lang_editPanel}}{{/new}}
+</h2>
+
+<p>{{lang_editSummaryPanelHints}}</p>
+
+<form method="post" action="?do=locationinfo" id="config-form">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="writePanelConfig">
+ <input type="hidden" name="ptype" value="SUMMARY">
+ <input type="hidden" name="uuid" value="{{uuid}}">
+
+ <div class="row">
+
+ <div class="col-md-6">
+ <div class="modify-inputs panel panel-default">
+ <div class="panel-heading">{{lang_display}}</div>
+ <div class="panel-body">
+ <div class="list-group">
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-sm-3">
+ <label for="panel-title">{{lang_displayName}}</label>
+ </div>
+ <div class="col-sm-7">
+ <input class="form-control" name="name" id="panel-title" type="text" value="{{panelname}}">
+ </div>
+ <div class="col-sm-2">
+ <a class="btn btn-default helptext" title="{{lang_displayNameTooltip}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-sm-3">
+ <label for="language">{{lang_language}}</label>
+ </div>
+ <div class="col-sm-7">
+ <select class="form-control" name="language" id="language">
+ {{#languages}}
+ <option value="{{cc}}" id="lang-{{cc}}" {{selected}}>{{name}}</option>
+ {{/languages}}
+ </select>
+ </div>
+ <div class="col-sm-2">
+ <a class="btn btn-default helptext" title="{{lang_languageTooltip}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-sm-3">
+ <label for="input-eco">{{lang_ecoMode}}</label>
+ </div>
+ <div class="col-sm-7">
+ <input id="input-eco" type="checkbox" name="eco" {{eco_checked}}>
+ </div>
+ <div class="col-sm-2">
+ <a class="btn btn-default helptext" title="{{lang_ecoTooltip}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+<!--
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-sm-3">
+ <label for="input-prettytime">{{lang_prettytime}}</label>
+ </div>
+ <div class="col-sm-7">
+ <input id="input-prettytime" type="checkbox" name="prettytime" {{prettytime_checked}}>
+ </div>
+ <div class="col-sm-2">
+ <a class="btn btn-default helptext" title="{{lang_prettytimeTooltip}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+-->
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="modify-inputs">
+ <div class="row">
+
+ <div class="col-md-6">
+ <div class="panel panel-default">
+ <div class="panel-heading">{{lang_locations}}</div>
+ <div class="panel-body">
+ <input type="hidden" name="locationids" value="{{locationids}}" id="locationids">
+ <p>{{lang_fourLocsHint}}</p>
+ <ul id="selected-locations" class="list-unstyled">
+
+ </ul>
+ <div class="dropdown pull-right">
+ <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown">
+ <span class="glyphicon glyphicon-plus"></span>
+ </button>
+ <ul class="dropdown-menu" id="location-list">
+ {{#locations}}
+ <li><a href="#" data-lid="{{locationid}}">{{locationpad}} <span class="name">{{locationname}}</span></a></li>
+ {{/locations}}
+ </ul>
+ </div>
+ <div class="clearfix"></div>
+ </div>
+ </div>
+ </div>
+
+ </div>
+ </div>
+ <button type="submit" class="btn btn-primary">{{lang_save}}</button>
+ <a href="?do=locationinfo&amp;show=panels" class="btn btn-default">{{lang_cancel}}</a>
+</form>
+
+<div class="modal fade" id="no-locations-message" tabindex="-1" role="dialog">
+ <div class="modal-dialog"> <!--style="min-width:600px;width:70%"-->
+
+ <div class="modal-content">
+ <div class="modal-header">{{lang_error}}</div>
+ <div class="modal-body">
+ {{lang_noLocationsWarning}}
+ </div>
+ <div class="modal-footer">
+ <a class="btn btn-primary pull-right" data-dismiss="modal">{{lang_close}}</a>
+ <div class="clearfix"></div>
+ </div>
+ </div>
+
+ </div>
+</div>
+
+<script type="text/javascript"><!--
+
+document.addEventListener("DOMContentLoaded", function () {
+ var $selLocs = $('#selected-locations');
+ var $locList = $('#location-list');
+ var $locInput = $('#locationids');
+
+ // Initialize fancy tooltips
+ $('a.helptext').tooltip();
+ // Add listener to range sliders so their label can be updated
+ $('input[type="range"]').change(function () {
+ $(this).siblings().find('.range-display').text($(this).val());
+ });
+ // Set state of input controls that aren't statically initialized server side
+ $('.modify-inputs input[type="checkbox"]')
+ .bootstrapSwitch({size: 'small'});
+
+ var lids = $locInput.val().split(',');
+ $selLocs.empty();
+ for (var i = 0; i < lids.length; ++i) {
+ var $name = $locList.find('a[data-lid="' + lids[i] + '"] .name');
+ if ($name.length === 0) continue;
+ addLocation(lids[i], $name.text());
+ }
+
+ // Adding/removing locations
+ $locList.find('a').click(function(ev) {
+ ev.preventDefault();
+ var $this = $(this);
+ var name = $this.find('.name').text();
+ var id = $this.data('lid');
+ addLocation(id, name);
+ serializeLocs();
+ });
+
+ $('#config-form').submit(function(ev) {
+ if ($locInput.val().length > 0)
+ return;
+ ev.preventDefault();
+ $('#no-locations-message').modal('show');
+ });
+
+ function addLocation(id, name) {
+ $selLocs.find('li[data-lid="' + id + '"]').remove();
+ var delButton = $('<button class="btn btn-danger btn-xs" type="button">').append($('<span class="glyphicon glyphicon-remove">')).click(delParent);
+ $selLocs.append($('<li>').attr('data-lid', id).text(name).prepend(delButton));
+ }
+
+ function delParent() {
+ $(this).parent().remove();
+ serializeLocs();
+ }
+
+ function serializeLocs() {
+ var res = $selLocs.find('li[data-lid]').map( function() {
+ return $(this).data('lid');
+ }).get().join(',');
+ $locInput.val(res);
+ }
+
+});
+
+//--></script>