-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates.html.tmpl
128 lines (110 loc) · 4.75 KB
/
templates.html.tmpl
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
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<title>OCF Email Templates</title>
<style>
#variables > div {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container" style="margin-top: 20px;">
<div class="row">
<div class="col-md-3">
<div class="well">
<ul id="nav" class="nav nav-stacked nav-pills"></ul>
</div>
</div>
<div class="col-md-9">
<div class="well">
<noscript><p>You'd feel better if you enabled JavaScript.</p></noscript>
<h2 style="margin-top: 0;" id="title"></h2>
<div id="variables"></div>
<textarea id="text" class="form-control" style="height: 750px;"></textarea>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script>
(function() {
var oldPage,
text = '',
values = {};
function updateText() {
var content = text,
vars = _.map(_.uniq(content.match(/{.+?}/g)), function(str) {
return str.substring(1, str.length - 1);
});
if (!$('#variables').children().length) {
_.each(vars, function(v) {
$('<div>')
.addClass('form-group')
.append(
$('<label>')
.text(v)
)
.append(
$('<input type="text">')
.addClass('form-control')
.val(values[v] || '')
.keyup(function() {
values[v] = $(this).val();
updateText();
})
)
.appendTo('#variables');
});
}
_.each(vars, function(v) {
var search = '{' + v + '}',
replace = values[v] || search;
content = content.split(search).join(replace);
});
$('#text').text(content);
}
function updatePage() {
var page = (window.location.hash || '#').substring(1);
if (oldPage === page) {
return;
}
$('#title').text(page);
$('#nav > li')
.removeClass('active')
.each(function() {
el = $(this);
if (el.data('template') === page) {
$('#variables').empty();
el.addClass('active');
$.get('/~hkn/templates/' + encodeURI(page), function(newText) {
text = newText;
updateText();
});
}
});
}
$(document).ready(function() {
var templates = {templates};
_.each(templates, function(template) {
$('<li>')
.attr('role', 'presentation')
.data('template', template)
.append(
$('<a>')
.text(template)
.attr('href', '#' + encodeURI(template))
)
.appendTo('#nav');
});
$(window).on('hashchange', updatePage);
updateText();
updatePage();
});
})();
</script>
</body>
</html>