summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/clientscript.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locations/clientscript.js')
-rw-r--r--modules-available/locations/clientscript.js62
1 files changed, 35 insertions, 27 deletions
diff --git a/modules-available/locations/clientscript.js b/modules-available/locations/clientscript.js
index 25c255fb..9a434e04 100644
--- a/modules-available/locations/clientscript.js
+++ b/modules-available/locations/clientscript.js
@@ -37,8 +37,8 @@ var slxIdCounter = 0;
/**
* Adds a new opening time to the table in expert mode.
*/
-function newOpeningTime(vals) {
- var $row = $('#expert-template').find('div.row').clone();
+function newOpeningTime($loc, vals) {
+ var $row = $loc.find('.expert-template div.row').clone();
if (vals['days'] && Array.isArray(vals['days'])) {
for (var i = 0; i < allDays.length; ++i) {
$row.find('.i-' + allDays[i]).prop('checked', vals['days'].indexOf(allDays[i]) !== -1);
@@ -53,7 +53,7 @@ function newOpeningTime(vals) {
});
$row.find('.i-openingtime').val(vals['openingtime']);
$row.find('.i-closingtime').val(vals['closingtime']);
- $('#expert-table').append($row);
+ $loc.find('.expert-table').append($row);
return $row;
}
@@ -61,60 +61,68 @@ function newOpeningTime(vals) {
* Convert fields from simple mode view to entries in expert mode.
* @returns {Array}
*/
-function simpleToExpert() {
- var retval = [];
- if ($('#week-open').val() || $('#week-close').val()) {
+function simpleToExpert($form) {
+ var retval = [], $open, $close;
+ $open = $form.find('.week-open');
+ $close = $form.find('.week-close');
+ if ($open.val() || $close.val()) {
retval.push({
'days': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
- 'openingtime': $('#week-open').val(),
- 'closingtime': $('#week-close').val(),
- 'tag': '#week'
+ 'openingtime': $open.val(),
+ 'closingtime': $close.val(),
+ 'tag': 'week'
});
}
- if ($('#saturday-open').val() || $('#saturday-close').val()) {
+ $open = $form.find('.saturday-open');
+ $close = $form.find('.saturday-close');
+ if ($open.val() || $close.val()) {
retval.push({
'days': ['Saturday'],
- 'openingtime': $('#saturday-open').val(),
- 'closingtime': $('#saturday-close').val(),
- 'tag': '#saturday'
+ 'openingtime': $open.val(),
+ 'closingtime': $close.val(),
+ 'tag': 'saturday'
});
}
- if ($('#sunday-open').val() || $('#sunday-close').val()) {
+ $open = $form.find('.sunday-open');
+ $close = $form.find('.sunday-close');
+ if ($open.val() || $close.val()) {
retval.push({
'days': ['Sunday'],
- 'openingtime': $('#sunday-open').val(),
- 'closingtime': $('#sunday-close').val(),
- 'tag': '#sunday'
+ 'openingtime': $open.val(),
+ 'closingtime': $close.val(),
+ 'tag': 'sunday'
});
}
return retval;
}
/**
- * Triggered when the form is submitted
+ * Triggered when the openingtimes/WOL form is submitted
*/
-function submitLocationSettings(event) {
+function validateOpeningTimes(event) {
var schedule, s, e;
var badFormat = false;
- $('#settings-outer').find('.red-bg').removeClass('red-bg');
- if ($('#week-open').length > 0) {
- schedule = simpleToExpert();
+ var $form = $(this);
+
+ $form.find('.red-bg').removeClass('red-bg');
+ if ($form.find('.week-open').length > 0) {
+ schedule = simpleToExpert($form);
for (var i = 0; i < schedule.length; ++i) {
s = getTime(schedule[i].openingtime);
e = getTime(schedule[i].closingtime);
if (s === false) {
- $(schedule[i].tag + '-open').addClass('red-bg');
+ $form.find('.' + schedule[i].tag + '-open').addClass('red-bg');
badFormat = true;
}
if (e === false || e <= s) {
- $(schedule[i].tag + '-close').addClass('red-bg');
+ $form.find('.' + schedule[i].tag + '-close').addClass('red-bg');
badFormat = true;
}
}
} else {
// Serialize
schedule = [];
- $('#expert-table').find('.expert-row').each(function () {
+ $form.find('.expert-table .expert-row').each(function () {
var $t = $(this);
if ($t.find('.i-delete').is(':checked')) return; // Skip marked as delete
var entry = {
@@ -149,5 +157,5 @@ function submitLocationSettings(event) {
if (badFormat) {
event.preventDefault();
}
- $('#json-openingtimes').val(JSON.stringify(schedule));
-} \ No newline at end of file
+ $form.find('input[name="openingtimes"]').val(JSON.stringify(schedule));
+}