summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/clientscript.js
blob: f8309a8a65e87ca29df443c88ff158f085b65f97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Generic helpers.
 */

/**
 * Initialize timepicker on given element.
 */
function setTimepicker($e) {
	$e.timepicker({
		minuteStep: 15,
		appendWidgetTo: 'body',
		showSeconds: false,
		showMeridian: false,
		defaultTime: false
	});
}

function getTime(str) {
	if (!str) return false;
	str = str.split(':');
	if (str.length !== 2) return false;
	var h = parseInt(str[0].replace(/^0/, ''));
	var m = parseInt(str[1].replace(/^0/, ''));
	if (h < 0 || h > 23) return false;
	if (m < 0 || m > 59) return false;
	return h * 60 + m;
}

const allDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];

/*
 * Opening times related...
 */

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();
	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);
		}
	}
	$row.find('input').each(function() {
		var $inp = $(this);
		if ($inp.length === 0) return;
		slxIdCounter++;
		$inp.prop('id', 'id-inp-' + slxIdCounter);
		$inp.siblings('label').prop('for', 'id-inp-' + slxIdCounter);
	});
	$row.find('.i-openingtime').val(vals['openingtime']);
	$row.find('.i-closingtime').val(vals['closingtime']);
	$('#expert-table').append($row);
	return $row;
}

/**
 * Convert fields from simple mode view to entries in expert mode.
 * @returns {Array}
 */
function simpleToExpert() {
	var retval = [];
	if ($('#week-open').val() || $('#week-close').val()) {
		retval.push({
			'days': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
			'openingtime': $('#week-open').val(),
			'closingtime': $('#week-close').val(),
			'tag': '#week'
		});
	}
	if ($('#saturday-open').val() || $('#saturday-close').val()) {
		retval.push({
			'days': ['Saturday'],
			'openingtime': $('#saturday-open').val(),
			'closingtime': $('#saturday-close').val(),
			'tag': '#saturday'
		});
	}
	if ($('#sunday-open').val() || $('#sunday-close').val()) {
		retval.push({
			'days': ['Sunday'],
			'openingtime': $('#sunday-open').val(),
			'closingtime': $('#sunday-close').val(),
			'tag': '#sunday'
		});
	}
	return retval;
}