-
Notifications
You must be signed in to change notification settings - Fork 5
/
concerto-screen.html
146 lines (130 loc) · 4.23 KB
/
concerto-screen.html
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
141
142
143
144
145
146
<!--
The `concerto-screen` element provides the main Concerto screen
-->
<dom-module id="concerto-screen">
<style>
:host {
display: block;
position: relative;
width: 100%;
height: 100%;
cursor: none;
}
.position {
position: absolute;
overflow: hidden;
}
.template {
width: 100%;
height: 100%;
background-size: 100% 100%;
background-repeat: no-repeat;
}
</style>
<template>
<!-- Screen setup requests -->
<iron-ajax
id="initScreenData"
handle-as="json"
on-response="handleScreenData">
</iron-ajax>
<!-- Create template background, positions, and fields -->
<template is="dom-if" if="{{template.id}}">
<div id="{{templateId(template.id)}}" class="template"
style$="{{backgroundImage(template.path)}}">
<template is="dom-repeat" items="{{template.positions}}" as="position">
<div class="position" id="{{positionId(position.id)}}"
style$="{{computeFieldPosition(position)}}">
<concerto-field screen-id="{{screenId}}"
field-id="{{position.field.id}}"
field-name="{{position.field.name}}"
base-url="{{baseUrl}}"
timezone="{{timezone}}"
content-style="{{position.style}}"
opt-config="{{position.field.config}}"
cache-key="{{cacheKey}}">
</concerto-field>
</div>
</template>
</div>
</template>
</template>
<script>
Polymer({
is: "concerto-screen",
behaviors: [ConcertoBehaviors.Utils],
properties: {
cacheKey: {
type: String,
observer: 'cacheKeyChanged'
},
screenId: Number,
preview: String,
baseUrl: {
type: String,
value: "",
reflectToAttribute: true
},
name: String,
template: Object,
timezone: String
},
ready: function() {
/* get intial screen data */
var setup = this.baseUrl + "/frontend/" + this.screenId + "/setup.json";
this.$.initScreenData.url = setup;
this.$.initScreenData.generateRequest();
/* show cursor if screen is in preview mode; hide otherwise */
if (this.preview == "true") {
this.style.cursor = "auto";
}
this.addEventListener('fieldCacheKeyChanged', function (e, detail) {
this.cacheKeyChanged(e.detail.newValue, e.detail.oldValue);
});
},
templateId: function(id) {
return "template_" + id;
},
positionId: function(id) {
return "position_" + id;
},
backgroundImage: function(path) {
/* background-image style for annotated attribute binding */
var url = this.prefixWithBase(path, this.baseUrl);
return "background-image: url('" + url + "');";
},
computeFieldPosition: function(position) {
return "left: " + position.left * 100 + "%; " +
"top: " + position.top * 100 + "%; " +
"width: " + (position.right - position.left) * 100 + "%; " +
"height: " + (position.bottom - position.top) * 100 + "%;";
},
handleScreenData: function(event, response) {
/* set screen setup properties */
var data = response.response;
this.name = data.name;
this.template = data.template;
this.timezone = data.time_zone;
var key = response.xhr.getResponseHeader('X-Concerto-Frontend-Setup-Key');
if (key) {
this.cacheKey = key;
}
/* load the css if any */
if (this.template.css_path && this.template.css_path != "") {
var css_link = document.createElement("link");
css_link.type = "text/css";
css_link.rel = "stylesheet";
css_link.href = this.prefixWithBase(this.template.css_path, this.baseUrl);
document.head.appendChild(css_link);
}
},
cacheKeyChanged: function(newValue, oldValue) {
if (oldValue !== undefined && oldValue !== null && oldValue !== newValue)
{
console.log("cacheKeyChanged reloading screen");
location.reload();
}
}
});
</script>
</dom-module>