summaryrefslogtreecommitdiffstats
path: root/modules-available/usblockoff/templates/usb-edit-rule.html
blob: ec14d5abe6ce1f8d82cca85b52e91c4dfd3c2a42 (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
<form method="post" action="?do=usblockoff" id="editRuleForm">
	<input type="hidden" name="token" value="{{token}}">
	<input type="hidden" name="action" value="editRule">
	<input type="hidden" name="configid" value="{{configid}}" id="configid">
	<input type="hidden" name="attributes" value="" id="attributes">

	<div class="panel panel-default">
		<div class="panel-heading">{{lang_editRules}}</div>
		<div class="panel-body">
			<div class="list-group">

				{{#attributes}}
				{{{attributesHtml}}}
				{{/attributes}}

			</div>
		</div>
	</div>

	<div class="pull-right">
		<a href="?do=usblockoff&show=edit-config&configid={{configid}}" class="btn btn-default">Cancel</a>

		<button id="addButton" class="btn btn-primary" type="submit">
			<span class="glyphicon glyphicon-floppy-disk"></span> {{lang_save}}
		</button>
	</div>

</form>

<script>
	var idArray = {{{usbJson}}};

	document.addEventListener("DOMContentLoaded", function(event) {
		$('.switch-input').click(function() {
			var $op = $(this).parent().find('select');
			var val = $op.val();
			$op.replaceWith($('<input class="form-control" type="text">').attr('name', $op.attr('name')).val(val));
		});

		var vid = $('#prop-vid').val();
		var pid = $('#prop-pid').val();
		$('#prop-vid').empty();


		$('[id^="prop-"]').change(function () {
			updateAttributes();
		});

		$('#prop-vid').change(function () {
			var $this = $(this);
			var vid = $this.val();
			var pid = $('#prop-pid').val();
			$('#prop-pid').empty();
			$.each(idArray[vid]['products'], function(key, value) {
				$('#prop-pid').append($('<option></option>').val(key).html(value));
			});
			$("#prop-pid").val(pid);
		});

		$.each(idArray, function(key, value) {
			$('#prop-vid').append($('<option></option>').val(key).html(value['name']));
		});

		$("#prop-vid").val(vid);
		$("#prop-vid").change();
	});

	function updateAttributes() {
		var attributes = [];

		$.each($('[id^="prop-"]'), function () {
			var attr = {};
			attr['prop'] = $(this).attr('id');
			attr['value'] = $(this).val();

			attributes.push(attr);
		});
		$('#attributes').val(JSON.stringify(attributes));
	}


</script>