-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAngularApp.PartEditions.cshtml
53 lines (49 loc) · 1.79 KB
/
AngularApp.PartEditions.cshtml
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
@inherits Custom.Hybrid.RazorTyped
@{
// -------------------------------- Show Edition Select -------------------------------
//Show the toolbar to select an edition - usually only for the superuser / developer
var editionHelper = GetCode("shared/Editions.cs");
var currentEdition = editionHelper.CurrentEdition;
var editions = MyModel.Code("Editions").Split(',');
}
<div class="alert alert-info">
<span style="vertical-align: middle;">
Edition to show:
</span>
<div class="btn-group">
@foreach (var name in editions)
{
var selected = name == currentEdition ? "selected" : "not-selected";
var style = name == currentEdition ? "font-weight: bold; text-decoration: underline;" : "";
<button type="button" onclick="sxcAngularApp.setEdition('@name')" class='btn btn-default' style="@style">
@name
</button>
}
</div>
</div>
<script>
window.sxcAngularApp = {
// Source: https://stackoverflow.com/questions/14573223/set-cookie-and-get-cookie-with-javascript
setCookie: function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
},
eraseCookie: function eraseCookie(name) {
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/';
},
setEdition: function setEdition(edition) {
let cookieName = '@editionHelper.EditionCookieName()';
if (edition)
this.setCookie(cookieName, edition);
else
this.eraseCookie(cookieName);
// reload page, preserving hash & angular route
location.reload();
}
}
</script>