summaryrefslogtreecommitdiffstats
path: root/modules-available/dozmod/templates/templates.html
blob: e8e3f59237df03a2c42c2a4425d09ea5075ba853 (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
<h1> Templates</h1>

<form id="templateForm" role="form" method="POST" action="?do=dozmod&section=templates&action=save">
	<input type="hidden" name="token" value="{{token}}">


	<div class="panel-group" id="accordion">

	{{#templates}}

	<div class="panel panel-default">
		<div id="heading_{{name}}" class="panel-heading">
			<div class="panel-title">
				<h4>
					<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#panel_{{name}}">
					{{name}}
					</a>
				</h4>
				<small>{{description}}</small>

			</div>
		</div>
		<div id="panel_{{name}}" class="panel-collapse collapse">
			<div class="panel-body">
				<div id="msgbox_{{name}}">
				</div>
				<label for="n_{{name}}">{{lang_name}}</label>
				<input name="templates[{{name}}][name]" value="{{name}}" class="form-control"/>

				<label for="n_{{description}}">{{lang_description}}</label>
				<input name="templates[{{name}}][description]" value="{{description}}" class="form-control"/>



				<label for="ta_{{name}}">{{lang_template}}</label>
				<br/>
				<textarea data-mandatory="{{list_mandatoryVariables}}" name="templates[{{name}}][template]" data-setting="{{name}}" id="ta_{{name}}"
																								class="form-control templateEditor" style="min-height:200px"
															>{{template}}</textarea>

				<h3>{{lang_placeholders}}</h3>
				<select name="templates[{{name}}][mandatory_variables]" multiple="multiple" class="hidden">
					{{{html_mandatoryVariables}}}
				</select>
				<select name="templates[{{name}}][optional_variables]" multiple="multiple" class="hidden">
					{{{html_optionalVariables}}}
				</select>
				<ul>
					{{{html_availableVariables}}}
				</ul>
			</div>
		</div>
	</div>


	{{/templates}}
	</div>

	<div class="btn-group">
		<button type="button" onclick="sendForm()" class="btn btn-primary">{{lang_save}}</button>
	</div>
</form>
<script type="application/javascript"><!--


/* check that all necessary placeholders are used */
function validateForm() {
	var ok = true;

	$('.templateEditor').each(function (i, editor) {

		var id = $(editor).attr('id');
		var setting = $(editor).attr('data-setting');
		var mandatory = $(editor).attr('data-mandatory').split(",");
		var value = $(editor).val();


		/* ? */
		if (mandatory.length == 1 && mandatory[0] == "") {
			mandatory = [];
		}

		var missing = [];

		mandatory.forEach(function (v,i) {
			if (value.indexOf("%" + v + "%") == -1) {
				missing.push(v);
			}
		});
		console.log("missing are");
		console.log(missing);

		var $msgBox = $("#msgbox_" + setting);
		var $panel = $("#panel_" + setting);
		var $header = $("#heading_" + setting);


		if (missing.length > 0) {
			/* add errors */
			var missingL = missing.join(", ");
			var msg="<strong>Fehler:</strong> Folgende wichtige Platzhalter wurden nicht verwendet: " +missingL;
			console.log("msg box has " + $msgBox.size());
			$msgBox.html('<div class="alert alert-danger">' + msg + '</div>');
			$panel.addClass('witherror');
			$header.addClass('witherror');
			/* overall result */
			ok = false;
		} else {
			$msgBox.html("");
			$panel.removeClass('witherror');
			$header.removeClass('witherror');
		}


	});
	return ok;
}

function submitForm() {
	console.log('sending form');
	$('#templateForm').submit();
}


function sendForm() {
	var ok = validateForm();
	if (ok) {
		console.log("is ok");
		submitForm();
	} else {
		console.log("form is not ok");
	}
}

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



});
</script>