summaryrefslogtreecommitdiffstats
path: root/modules-available/usblockoff/templates/usb-edit-rule.html
blob: e2bc5b651050d0c88bf07f63deaa3f65821da88d (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
<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="ruleid" value="{{ruleid}}" id="ruleid">
	<input type="hidden" name="attributes" value="" id="attributes">

	<div class="panel panel-default">
		<div class="panel-heading">{{lang_editRule}}</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() {
		$('.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 vendorid = $('#prop-vid');
		var productid = $('#prop-pid');

		var vid = vendorid.val();
		vendorid.empty();


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

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

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

		vendorid.val(vid);
		vendorid.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>