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.js54
1 files changed, 31 insertions, 23 deletions
diff --git a/modules-available/locations/clientscript.js b/modules-available/locations/clientscript.js
index 25c255fb..89abcefc 100644
--- a/modules-available/locations/clientscript.js
+++ b/modules-available/locations/clientscript.js
@@ -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));
+ $form.find('input[name="openingtimes"]').val(JSON.stringify(schedule));
} \ No newline at end of file