-
Notifications
You must be signed in to change notification settings - Fork 0
/
myVideoEdit.js
73 lines (58 loc) · 2.72 KB
/
myVideoEdit.js
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
import axios from 'axios';
import * as bootstrap from 'bootstrap'
import { getCookie } from './getCookie';
if (window.location.pathname === "/user/videos/") {
const csrftoken = getCookie('csrftoken');
document.addEventListener("DOMContentLoaded", () => {
let modal = document.querySelector("#editModal");
const Bmodal = new bootstrap.Modal('#editModal');
let videos = document.querySelectorAll(".video-container");
videos.forEach(video => {
let video_id = video.querySelector("#watchurl");
video_id = video_id.search.replace("?v=", "");
let editbtn = video.querySelector("#myVideoEdit");
editbtn.addEventListener("click", () => {
axios.get(`/getvideoinfo/${video_id}`)
.then(response => {
modal.querySelector("#title").value = response.data[0].fields.title;
modal.querySelector("#videoDescription").value = response.data[-0].fields.description;
modal.querySelector("#private").checked = response.data[-0].fields.private;
})
Bmodal.show();
let editform = modal.querySelector("#editform");
editform.addEventListener("submit", (e) => {
e.preventDefault();
if (e.submitter.name == "delete") {
axios.delete(`/delete/${video_id}`, {
headers: {
'X-CSRFToken': csrftoken
}
})
.then((response) => {
Bmodal.hide();
video.className = "d-none";
})
.catch(error => {
console.log(error);
});
} else if (e.submitter.name == "update") {
let data = new FormData(e.target);
data.append("video_id", video_id);
axios.post("/user/videos/", data, {
headers: {
'X-CSRFToken': csrftoken
}
})
.then(response => {
video.querySelector(".card-title").innerHTML = editform.querySelector("#title").value;
Bmodal.hide();
})
.catch(error => {
console.log(error);
});
}
});
});
});
});
}