|
|
@@ -2,7 +2,8 @@ var d3 = require("d3"),
|
|
2
|
2
|
$ = require("jquery"),
|
|
3
|
3
|
preview = require("./preview.js"),
|
|
4
|
4
|
video = require("./video.js"),
|
|
5
|
|
- audio = require("./audio.js");
|
|
|
5
|
+ audio = require("./audio.js"),
|
|
|
6
|
+ newTheme = null;
|
|
6
|
7
|
|
|
7
|
8
|
d3.json("/settings/themes.json", function(err, themes){
|
|
8
|
9
|
|
|
|
@@ -90,6 +91,73 @@ function submitted() {
|
|
90
|
91
|
|
|
91
|
92
|
}
|
|
92
|
93
|
|
|
|
94
|
+function uploadTheme() {
|
|
|
95
|
+ var formData = new FormData();
|
|
|
96
|
+ var file = preview.newTheme();
|
|
|
97
|
+
|
|
|
98
|
+ formData.append("newTheme", file);
|
|
|
99
|
+
|
|
|
100
|
+ var newCaption = preview.newCaption();
|
|
|
101
|
+ console.log('new theme', newCaption);
|
|
|
102
|
+ formData.append("newCaption", newCaption);
|
|
|
103
|
+ console.log(formData);
|
|
|
104
|
+ $.ajax({
|
|
|
105
|
+ url: "/theme/upload",
|
|
|
106
|
+ type: "POST",
|
|
|
107
|
+ data: formData,
|
|
|
108
|
+ contentType: false,
|
|
|
109
|
+ cache: false,
|
|
|
110
|
+ processData: false,
|
|
|
111
|
+ success: function () {
|
|
|
112
|
+ d3.json("/settings/themes.json", function(err, themes){
|
|
|
113
|
+
|
|
|
114
|
+ var errorMessage;
|
|
|
115
|
+
|
|
|
116
|
+ // Themes are missing or invalid
|
|
|
117
|
+ if (err || !d3.keys(themes).filter(function(d){ return d !== "default"; }).length) {
|
|
|
118
|
+ if (err instanceof SyntaxError) {
|
|
|
119
|
+ errorMessage = "Error in settings/themes.json:<br/><code>" + err.toString() + "</code>";
|
|
|
120
|
+ } else if (err instanceof ProgressEvent) {
|
|
|
121
|
+ errorMessage = "Error: no settings/themes.json.";
|
|
|
122
|
+ } else if (err) {
|
|
|
123
|
+ errorMessage = "Error: couldn't load settings/themes.json.";
|
|
|
124
|
+ } else {
|
|
|
125
|
+ errorMessage = "No themes found in settings/themes.json.";
|
|
|
126
|
+ }
|
|
|
127
|
+ d3.select("#loading-bars").remove();
|
|
|
128
|
+ d3.select("#loading-message").html(errorMessage);
|
|
|
129
|
+ if (err) {
|
|
|
130
|
+ throw err;
|
|
|
131
|
+ }
|
|
|
132
|
+ return;
|
|
|
133
|
+ }
|
|
|
134
|
+
|
|
|
135
|
+ for (var key in themes) {
|
|
|
136
|
+ themes[key] = $.extend({}, themes.default, themes[key]);
|
|
|
137
|
+ }
|
|
|
138
|
+
|
|
|
139
|
+ preloadImages(themes);
|
|
|
140
|
+
|
|
|
141
|
+ d3.select("#input-theme")
|
|
|
142
|
+ .selectAll("option")
|
|
|
143
|
+ .each(function (d) {
|
|
|
144
|
+ if (d.name === newCaption) {
|
|
|
145
|
+ this["selected"] = "selected";
|
|
|
146
|
+ d3.select("#input-new-theme").property("value", "");
|
|
|
147
|
+ d3.select("#input-new-caption").property("value", "");
|
|
|
148
|
+ return;
|
|
|
149
|
+ }
|
|
|
150
|
+ });
|
|
|
151
|
+
|
|
|
152
|
+ });
|
|
|
153
|
+ },
|
|
|
154
|
+ error: function (error) {
|
|
|
155
|
+ console.log('error', error);
|
|
|
156
|
+ }
|
|
|
157
|
+ });
|
|
|
158
|
+
|
|
|
159
|
+}
|
|
|
160
|
+
|
|
93
|
161
|
function poll(id) {
|
|
94
|
162
|
|
|
95
|
163
|
setTimeout(function(){
|
|
|
@@ -180,6 +248,12 @@ function initialize(err, themesWithImages) {
|
|
180
|
248
|
setClass(null);
|
|
181
|
249
|
});
|
|
182
|
250
|
|
|
|
251
|
+ d3.select("#btn-new-theme").on("click", uploadTheme);
|
|
|
252
|
+
|
|
|
253
|
+ d3.select("#input-new-theme").on("change", updateNewThemeFile).each(updateNewThemeFile);
|
|
|
254
|
+
|
|
|
255
|
+ d3.select("#input-new-caption").on("change keyup", updateNewCaption).each(updateNewCaption);
|
|
|
256
|
+
|
|
183
|
257
|
d3.select("#submit").on("click", submitted);
|
|
184
|
258
|
|
|
185
|
259
|
}
|
|
|
@@ -218,6 +292,22 @@ function updateAudioFile() {
|
|
218
|
292
|
|
|
219
|
293
|
}
|
|
220
|
294
|
|
|
|
295
|
+function updateNewThemeFile() {
|
|
|
296
|
+ if (!this.files || !this.files[0]) {
|
|
|
297
|
+ preview.newTheme(null);
|
|
|
298
|
+ return true;
|
|
|
299
|
+ }
|
|
|
300
|
+
|
|
|
301
|
+ newTheme = this.files[0];
|
|
|
302
|
+ preview.loadNewTheme(newTheme, function (err) {
|
|
|
303
|
+ if (err) {
|
|
|
304
|
+ setClass("error", "Error updating new theme file");
|
|
|
305
|
+ } else {
|
|
|
306
|
+ setClass(null);
|
|
|
307
|
+ }
|
|
|
308
|
+ });
|
|
|
309
|
+}
|
|
|
310
|
+
|
|
221
|
311
|
function updateCaption() {
|
|
222
|
312
|
preview.caption(this.value);
|
|
223
|
313
|
}
|
|
|
@@ -226,6 +316,10 @@ function updateTheme() {
|
|
226
|
316
|
preview.theme(d3.select(this.options[this.selectedIndex]).datum());
|
|
227
|
317
|
}
|
|
228
|
318
|
|
|
|
319
|
+function updateNewCaption() {
|
|
|
320
|
+ preview.newCaption(this.value);
|
|
|
321
|
+}
|
|
|
322
|
+
|
|
229
|
323
|
function preloadImages(themes) {
|
|
230
|
324
|
|
|
231
|
325
|
// preload images
|