blob: 3b2a003fc949b589ab4411ee899fc9391440b8ff (
plain) (
tree)
|
|
<h1>{{lang_mailTemplates}}</h1>
<p><i>{{lang_templatePageDescription}}</i></p>
<form id="templateForm" role="form" method="POST" action="?do=dozmod&section=templates">
<input type="hidden" name="token" value="{{token}}">
<input type="hidden" name="action" value="save">
<div class="panel-group" id="accordion">
{{#templates}}
<div id="frame_{{name}}" class="panel panel-default">
<div 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>
<div class="form-group">
<input id="n_{{name}}" name="templates[{{name}}][name]" value="{{name}}" class="form-control"/>
</div>
<label for="d_{{name}}">{{lang_description}}</label>
<div class="form-group">
<input id="d_{{name}}" name="templates[{{name}}][description]" value="{{description}}" class="form-control"/>
</div>
-->
<label for="ta_{{name}}">{{lang_template}}</label>
<div class="form-group">
<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>
</div>
<h4>{{lang_placeholders}}</h4>
<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="pull-left">
<button type="submit" onclick="return validateForm()" class="btn btn-primary">{{lang_save}}</button>
</div>
</form>
<form method="POST" action="?do=dozmod&section=templates">
<input type="hidden" name="token" value="{{token}}">
<input type="hidden" name="action" value="reset">
<div>
<button type="submit" onclick="return confirm('{{lang_reallyResetTemplates}}')" class="btn btn-danger">{{lang_loadDefaults}}</button>
</div>
</form>
<div class="clearfix"></div>
<script type="application/javascript"><!--
/* check that all necessary placeholders are used */
function validateForm() {
var ok = true;
var $toppest = false;
$('.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);
}
});
var $msgBox = $("#msgbox_" + setting);
var $frame = $("#frame_" + setting);
if (missing.length > 0) {
/* add errors */
var missingL = missing.join(", ");
var msg="<strong>{{lang_error}}:</strong> {{lang_followingPlaceholdersUnused}}: " +missingL;
$msgBox.html('<div class="alert alert-danger">' + msg + '</div>');
$frame.addClass('witherror');
if ($toppest === false || $toppest.offset().top > $frame.offset().top) {
$toppest = $frame;
}
/* overall result */
ok = false;
} else {
$msgBox.html("");
$frame.removeClass('witherror');
}
});
if ($toppest !== false) {
$toppest[0].scrollIntoView();
}
return ok;
}
document.addEventListener("DOMContentLoaded", function () {
validateForm(); // Do once in case invalid templates are in DB
});
//--></script>
|