summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner/templates/edit-composed-room.html
blob: 64a02d612f16eeb6ef4a426f140178daf1423727 (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
<h1>{{lang_editComposedRoom}}</h1>
<h2>{{location.locationname}}</h2>

<form id="main-form" method="post" action="?do=roomplanner&amp;locationid={{location.locationid}}">
	<input type="hidden" name="token" value="{{token}}">
	<input type="hidden" name="isleaf" value="0">
	<input type="hidden" name="action" value="save">
	<div class="panel panel-default">
		<div class="panel-heading">
			<div class="checkbox">
				<input id="check-enable" type="checkbox" name="enabled" value="1" {{enabled_checked}}>
				<label for="check-enable">{{lang_exposeAsComposedRoom}}</label>
			</div>
		</div>
		<div class="panel-body">
			<div id="main-controls">
				<h4>{{lang_composedLayout}}</h4>
				<div class="radio radio-inline">
					<input id="type-horz" type="radio" name="orientation" value="horizontal" {{horizontal_checked}}>
					<label for="type-horz">{{lang_horizontal}}</label>
				</div>
				<div class="radio radio-inline">
					<input id="type-vert" type="radio" name="orientation" value="vertical" {{vertical_checked}}>
					<label for="type-vert">{{lang_vertical}}</label>
				</div>
				<br><br>
				<div id="roomsort">
					{{#locations}}
						<div class="box1">
							<div class="box2">
								<div class="name text-nowrap small">{{locationname}}</div>
								<div class="img">
									<input type="hidden" class="sort-val" name="sort[{{locationid}}]">
									<img src="api.php?do=roomplanner&amp;show=svg&amp;locationid={{locationid}}&amp;scale=2.2">
								</div>
								<div class="clearfix"></div>
							</div>
							<div class="clearfix"></div>
						</div>
					{{/locations}}
				</div>
				<div class="clearfix"></div>
				<br>
				<h4>{{lang_controllingRoom}}</h4>
				<p>{{lang_controlRoomDesc}}</p>
				{{#locations}}
					<div>
						<div class="radio">
							<input id="control-{{locationid}}" type="radio" name="controlroom"
									 value="{{locationid}}" {{checked}}>
							<label for="control-{{locationid}}">{{locationname}}</label>
						</div>
					</div>
				{{/locations}}
			</div>
			<div class="buttonbar pull-right">
				<button type="button" class="btn btn-default" id="btn-cancel">
					{{lang_cancel}}
				</button>
				<button id="btn-save" type="submit" class="btn btn-primary">
					<span class="glyphicon glyphicon-floppy-disk"></span>
					{{lang_save}}
				</button>
			</div>
			<div class="clearfix"></div>
			<div class="alert alert-danger" style="display:none" id="error-msg"></div>
			<div class="alert alert-success" style="display:none" id="success-msg">{{lang_planSuccessfullySaved}}</div>
			<div class="alert alert-info" style="display:none" id="saving-msg">{{lang_planBeingSaved}}</div>
		</div>
	</div>
</form>

<script>
	document.addEventListener('DOMContentLoaded', function () {

		var reassignSortValues = function () {
			var startValue = 1;
			$('.sort-val').each(function (index, element) {
				element.value = startValue * 10;
				startValue++;
			});
		};

		var $rs = $('#roomsort');
		var $mc = $('#main-controls');

		$rs.disableSelection().sortable({
			opacity: 0.8,
			start: function (evt, ui) {
				ui.placeholder.css("visibility", "visible");
				ui.placeholder.css("opacity", "0.352");
				ui.placeholder.css("background-color", "#ddd");
			},
			stop: reassignSortValues
		});

		var setLayout = function () {
			$rs.removeClass('horizontal vertical').addClass($('input[name=orientation]:checked').val());
		};
		$('input[name=orientation]').change(setLayout);

		$('#btn-cancel').click(function () {
			window.close();
		});

		var $ce = $('#check-enable');

		var checkEnable = function () {
			if ($ce.is(':checked')) {
				$mc.show();
			} else {
				$mc.hide();
			}
		};

		$ce.change(checkEnable);

		var $mf = $('#main-form');
		var $sb = $('#btn-save');
		var success = false;
		$sb.click(function(e) {
			$sb.prop('disabled', true);
			$('#error-msg').hide();
			$('#success-msg').hide();
			$('#saving-msg').show();
			var str = $mf.serialize();
			$.post($mf.attr('action'), str).done(function (data) {
				if (data.indexOf('SUCCESS') !== -1) {
					window.close();
					// If window.close() failed, we give some feedback and remember the state as saved
					$('#success-msg').show();
					success = true;
					return;
				}
				$('#error-msg').text('Error: ' + data).show();
			}).fail(function (jq, textStatus, errorThrown) {
				$('#error-msg').text('AJAX save call failed: ' + textStatus + ' (' + errorThrown + ')').show();
			}).always(function() {
				$sb.prop('disabled', success);
				$('#saving-msg').hide();
			});
			e.preventDefault();
		});

		setLayout();
		reassignSortValues();
		checkEnable();

	});
</script>