-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (45 loc) · 1.83 KB
/
index.js
File metadata and controls
51 lines (45 loc) · 1.83 KB
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
function newProgramme() {
dialog("New programme", `
<div>
Create a new programme that can contain episodes. You can modify
this information and much more later.
</div>
<div class="spacedTop">
<label>
<span>Name</span>
<input class="newProgrammeName">
</label>
<label>
<span>Thumbnail</span>
<input placeholder="Enter a URL to an image (optional)" class="newProgrammeThumbnail">
</label>
</div>
<p class="dialogError"></p>
`, [
{text: "Cancel", onclick: "closeDialog();", type: "secondary"},
{text: "Create", onclick: "newProgrammeAction();", type: "primary"}
]);
}
function newProgrammeAction() {
$(".dialog button:last").attr("disabled", "true");
if ($(".newProgrammeName").val().trim() == "") {
$(".dialog button:last").attr("disabled", null);
$(".dialogError").text("It appears that you have left some fields blank. Please enter data into those fields and try again.");
} else {
firebase.database().ref("orgs/" + currentUser.orgName + "/programmes").push().set({
name: $(".newProgrammeName").val().trim(),
thumbnail: $(".newProgrammeThumbnail").val().trim() == "" ? null : $(".newProgrammeThumbnail").val().trim()
}).then(function() {
$(".dialog button:last").attr("disabled", null);
closeDialog();
}).catch(function() {
$(".dialog button:last").attr("disabled", null);
$(".dialogError").text("Your programme could not be created. Please try again later.");
});
}
}
$(function() {
if (getURLParameter("prog") != null) {
window.location.replace("prog.html?prog=" + encodeURIComponent(getURLParameter("prog")));
}
})