summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/templates/location-info.html
blob: c2242241cb6de4b8fa5373e27e0daf8877aeefef (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<div>
	<h1>{{lang_mainHeader}}</h1>

	<h4>{{lang_serverTable}}</h4>

	<table class="table table-hover">
		<tr>
			<th width="1">{{lang_serverType}}</th>
			<th>{{lang_locationName}}</th>
			<th width="1"></th>
			<th width="1"></th>
		</tr>
		{{#serverlist}}
		<form method="post" action="?do=locationinfo">
			<input type="hidden" name="token" value="{{token}}">
			<input type="hidden" name="serverid" value="{{serverid}}">
			<tr>
				<td nowrap>{{typename}}</td>
				<td nowrap>{{servername}}</td>

				<td align="center" nowrap>
					<button class="btn btn-sm {{^autherror}}btn-success{{/autherror}}{{#autherror}}btn-danger{{/autherror}}"
							data-server-edit="{{serverid}}" {{disabled}} type="button">
						<span style="margin-right: 5px;" class="glyphicon glyphicon-cog"></span>
						{{lang_locationSettings}}
					</button>
					<button class="btn btn-sm btn-primary server-check" {{disabled}} name="action" value="checkConnection"
							title="{{lang_refresh_title}}" type="submit">
						<span style="margin-right: 5px;" class="glyphicon glyphicon-refresh"></span>
						{{lang_refresh}}
					</button>
				</td>
				<td align="center" nowrap>
					<button class="btn btn-sm btn-danger server-delete" type="submit" name="action" value="deleteServer">
						<span style="margin-right: 5px;" class="glyphicon glyphicon-remove"></span>
						{{lang_delete}}
					</button>
				</td>
			</tr>
		</form>
		{{/serverlist}}
	</table>

	<div>
		<button class="btn btn-sm btn-success" id="addServerButton" onclick="addServer()">
			<span title="{{lang_addServer_title}}">
				<span style="margin-right: 5px;" class="glyphicon glyphicon-plus"></span>
				{{lang_addServer}}
			</span>
		</button>
	</div>

	<h4>{{lang_buildingTable}}</h4>
	<table class="table table-condensed table-hover" style="margin-bottom:0">

		<tr>
			<th>{{lang_locationName}}</th>
			<th width="50" title="{{lang_locationIsHidden_title}}">{{lang_locationIsHidden}}</th>
			<th width="50">{{lang_openingTime}}</th>
			<th width="50">{{lang_locationSettings}}</th>
		</tr>

		{{#list}}
		<tr id="row{{locationid}}">
			<td>
				<div style="display:inline-block;width:{{depth}}em"></div>
				<a href="modules/locationinfo/frontend/doorsign.html?id={{locationid}}">{{locationname}}</a>
			</td>
			<td align="center">
				<div class="checkbox" style="margin:0">
					<input class="hidden-toggle" type="checkbox" data-locationid="{{locationid}}" {{hidden_checked}}>
					<label></label>
				</div>
			</td>
			<td>
				<a class="btn btn-sm btn-default" role="button" style="width: 100%"
					onclick="loadTimeModal({{locationid}}, '{{locationname}}');">
					<span style="margin-right: 5px;" class="glyphicon glyphicon-time"></span>
				</a>
			</td>
			<td>
				<a class="btn btn-sm btn-default" role="button" style="width: 100%;"
					onclick="loadLocationConfigModal({{locationid}}, '{{locationname}}');">
					<span style="margin-right: 5px;" class="glyphicon glyphicon-cog"></span>
				</a>
			</td>
		</tr>

		{{/list}}
	</table>

	<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
		<div class="modal-dialog">

			<div class="modal-content">
				<div class="modal-header" id="myModalHeader"></div>
				<div class="modal-body" id="myModalBody"></div>
				<div class="modal-footer">
					<button type="submit" id="myModalSubmitButton" class="btn btn-primary" form="">{{lang_save}}</button>

					<a class="btn btn-primary" data-dismiss="modal">{{lang_close}}</a>
				</div>
			</div>

		</div>
	</div>
</div>
<script type="text/javascript"><!--

	document.addEventListener("DOMContentLoaded", function () {

		/**
		 * React to click on a "hidden" checkbox.
		 */
		$('.hidden-toggle').change(function() {
			$input = $(this);
			$.ajax({
				type: 'POST',
				url: '?do=locationinfo&action=hide',
				data: {locationid: $input.data('locationid'), hidden: $input[0].checked ? 1 : 0, token: TOKEN },
				dataType: 'json'
			}).done(function(data) {
				if (data && $.isArray(data.changed)) {
					markBoxes(data.changed);
				} else {
					$input.replaceWith('ERROR');
				}
			}).fail(function () {
				$input.replaceWith('ERROR');
			});
		}).parent().click(function() {
			$this = $(this);
			$box = $this.find('input');
			if (!$this.is($box)) {
				$box.click();
			}
		});

		/**
		 * Confirm deleting a server.
		 */
		$('.server-delete').click(function(ev) {
			var del = confirm("{{lang_deleteConfirmation}}");
			if (!del) ev.preventDefault();
		});

		/**
		 * Animate refresh icon while page is loading
		 */
		$('.server-check').click(function() {
			$(this).find('.glyphicon').addClass('slx-rotation');
		});

		$('button[data-server-edit]').click(function() {
			var id = $(this).data('server-edit');
			loadServerSettingsModal(id);
		});

	});

	/**
	 * Gets a status array delivered by backend's ajaxHideLocation()
	 * and sets the checkbox states accordingly.
	 */
	function markBoxes(boxArray) {
		for (var i = 0; i < boxArray.length; ++i) {
			if (boxArray[i].locationid) {
				var lid = parseInt(boxArray[i].locationid);
				$('input.hidden-toggle[data-locationid="' + lid + '"]').prop('checked', !!boxArray[i].hidden);
			}
		}
	}

	/**
	 * Loads the settings modal of a server.
	 *
	 * @param serverid The id of the server.
	 */
	function loadServerSettingsModal(serverid) {
		$('#myModalHeader').text("{{lang_locationSettings}}").css("font-weight", "Bold");
		$('#myModalSubmitButton').attr("form", "settingsForm");
		$('#myModal .modal-dialog').css('width', '');
		$('#myModal').modal('show');
		$('#myModalBody').load("?do=locationinfo&action=serverSettings&id=" + serverid);
	}

	/**
	 * Load a opening time modal of a location.
	 *
	 * @param locationId The id of the location.
	 * @param locationName The name of the location.
	 */
	function loadTimeModal(locationId, locationName) {
		$('#myModalHeader').text("[" + locationId + "] " + locationName).css("font-weight", "Bold");
		$('#myModal .modal-dialog').css('width', '');
		$('#myModal').modal('show');
		$('#myModalBody').load("?do=locationinfo&action=timetable&id=" + locationId);
	}

	/**
	 * Loads the config modal of a location.
	 *
	 * @param locationId The id of the location
	 * @param locationName the name of the location
	 */
	function loadLocationConfigModal(locationId, locationName) {
		$('#myModalHeader').text("[" + locationId + "] " + locationName).css("font-weight", "Bold");
		$('#myModalSubmitButton').attr("form", "configForm");
		$('#myModal .modal-dialog').css('width', '90%');
		$('#myModal').modal('show');
		$('#myModalBody').load("?do=locationinfo&action=config&id=" + locationId);
	}

	// ########### Server Table ###########

	/**
	 * Loads a new / empty server settings modal.
	 */
	function addServer() {
		loadServerSettingsModal(0);
	}
//--></script>