script_slides_eng.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. checkRoute();
  2. let card;
  3. let userBasics = JSON.parse(localStorage.getItem('user_profile')) || [];
  4. //userBasics = JSON.parse(userBasics);
  5. if(userBasics !== [] && typeof(userBasics) !== 'string'){
  6. $('.userName').html(`<h2 class="user-name text-white mt-lg-3 mt-xl-1 fw-bold">Hi ${userBasics.user_info.userName}</h2>`);
  7. }
  8. function checkRoute() {
  9. let jwt_token = get_jwt_token();
  10. if(jwt_token == undefined) {
  11. window.location.replace("login.html");
  12. }
  13. axios({
  14. method: 'post',
  15. url: 'https://www.choozmo.com:8887/user_profile',
  16. headers: {
  17. 'accept': 'text/html',
  18. 'Authorization': `Bearer ${jwt_token}`
  19. }
  20. }).then(res => {
  21. console.log(res.data);
  22. // if(res.status !== 200) {
  23. // window.location.replace("login.html");
  24. // }
  25. var userName='';
  26. userName+=' <h2 class="user-name text-white mt-lg-3 mt-xl-1 fw-bold">Hi '+res.data.user_info.userName+'</h2>';
  27. $('.userName').html(userName);
  28. }).catch(err => {
  29. console.log(err);
  30. window.location.replace("login.html");
  31. });
  32. }
  33. let lan = localStorage.getItem('lan');
  34. $('.dropdown-toggle').click(() => {
  35. lan = localStorage.getItem('lan');
  36. checkLan();
  37. });
  38. checkLan();
  39. function checkLan() {
  40. if(lan == 'en') {
  41. $('.btn-makev').css('display', 'none');
  42. $('.btn-makelong').css('display', 'none');
  43. } else {
  44. $('.btn-makev').css('display', 'block');
  45. $('.btn-makelong').css('display', 'block');
  46. $('#slide_raw_url').attr('placeholder', 'SLIDE連結(連結須為公開)')
  47. }
  48. }
  49. const btnLoginPage = document.querySelector('.btn-login');
  50. const btnUserProfile = document.querySelector('.btn-userProfile');
  51. const btnLogout = document.querySelector('.btn-logout');
  52. function loginControl() {
  53. btnLoginPage.style.display = 'none';
  54. btnLogout.style.display = 'block';
  55. btnUserProfile.style.display = 'block';
  56. }
  57. loginControl();
  58. JsLoadingOverlay.show({
  59. "overlayBackgroundColor": "#FFFFFF",
  60. "overlayOpacity": "1",
  61. "spinnerIcon": "ball-circus",
  62. "spinnerColor": "#B9DDF3",
  63. "spinnerSize": "1x",
  64. "overlayIDName": "overlay",
  65. "spinnerIDName": "spinner",
  66. "offsetX": 0,
  67. "offsetY": 0,
  68. "containerID": "avatar-cards",
  69. "lockScroll": false,
  70. "overlayZIndex": 9998,
  71. "spinnerZIndex": 9999
  72. });
  73. window.setTimeout(() => {
  74. JsLoadingOverlay.hide()
  75. }, 5000)
  76. function getAvatar() {
  77. let jwt_token = get_jwt_token();
  78. if(jwt_token == undefined) {
  79. window.location.replace("login.html");
  80. }
  81. axios({
  82. method: 'post',
  83. url: 'https://www.choozmo.com:8887/get_avatar_by_role',
  84. headers: {
  85. 'accept': 'text/html',
  86. 'Authorization': `Bearer ${jwt_token}`
  87. }
  88. }).then(res => {
  89. console.log(res.data);
  90. let result = [...res.data];
  91. let str = '';
  92. let carStr = '';
  93. for(let i = 0; i < result.length; i++) {
  94. str += `<option value="${result[i].num}">${result[i].name}</option>`
  95. }
  96. for(let i = 0; i < result.length; i++) {
  97. carStr += `<div class="card item col" data-avatar="${result[i].name}" data-img="${result[i].name.toLowerCase()}">
  98. <div class="imgfr"><img src="static/img/${result[i].name.toLowerCase()}.webp" class="card-img-top" alt="..."></div>
  99. <div class="card-body">
  100. <h5 class="card-title">${result[i].name.toLowerCase()}</h5>
  101. </div>
  102. </div>`;
  103. }
  104. $('#avatar').html(`<option value="Choose Character" selected="selected" disabled>Choose Character</option>${str}`);
  105. $('.avatar-cards').html(carStr);
  106. if(lan = 'en') {
  107. $('#avatar option:disabled').val('請選擇人物')
  108. $('#avatar option:disabled').text('請選擇人物')
  109. }
  110. card = document.getElementsByClassName('card');
  111. console.log(card);
  112. addCardListener(card);
  113. avatarChange()
  114. }).catch(err => {
  115. console.log(err);
  116. });
  117. }
  118. getAvatar();
  119. var client_id = Date.now();
  120. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  121. var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  122. return new bootstrap.Tooltip(tooltipTriggerEl)
  123. });
  124. var myModal = new bootstrap.Modal(document.getElementById('history'), {
  125. keyboard: false
  126. })
  127. var avatarModal = new bootstrap.Modal(document.getElementById('avatarmega'), {
  128. keyboard: false
  129. })
  130. var modalImg = document.querySelector("#avatarmega .modal-img");
  131. var modalTitle = document.querySelector("#avatarmega .modal-title");
  132. var avatarSelector = document.getElementById("avatar");
  133. // var card = document.getElementsByClassName('card');
  134. // card = [...card];
  135. avatarSelector.addEventListener('change', avatarChange);
  136. // avatarChange();
  137. function addCardListener(card) {
  138. for (let i = 0; i < card.length; i++) {
  139. card[i].addEventListener('click', openavatarModel);
  140. }
  141. }
  142. // addCardListener();
  143. function avatarChange() {
  144. var value = avatarSelector.options[avatarSelector.selectedIndex].text;
  145. for (let i = 0; i < card.length; i++) {
  146. card[i].classList.remove('active');
  147. if (card[i].dataset.avatar == value) {
  148. card[i].classList.add('active');
  149. }
  150. }
  151. }
  152. function openavatarModel() {
  153. console.log(this.dataset.img);
  154. modalImg.setAttribute("src", `static/img/${this.dataset.img}.webp`);
  155. modalTitle.textContent = `${this.dataset.avatar}`;
  156. avatarModal.show();
  157. }
  158. $('input[type=file]').on('change', prepareUpload);
  159. function prepareUpload(event) {
  160. files = event.target.files;
  161. var data = new FormData();
  162. //data.append('file', $('.img_up1').prop('files')[0]);
  163. data.append('file', files[0]);
  164. // append other variables to data if you want: data.append('field_name_x', field_value_x);
  165. $(this).next().text('');
  166. $(this).next().html('<img src="static/img/Spinner-1s-181px.gif">');
  167. $.ajax({
  168. type: 'POST',
  169. processData: false, // important
  170. contentType: false, // important
  171. data: data,
  172. url: 'https://www.choozmo.com:8887/uploadfile',
  173. dataType: 'json',
  174. success: function (jsonData) {
  175. event.target.previousSibling.value = jsonData.msg;
  176. $(this).prev().val(jsonData.msg);
  177. event.target.nextSibling.innerHTML = '';
  178. event.target.nextSibling.textContent = '上傳檔案';
  179. //console.log($(this).next());
  180. //$(this).next().html('上傳檔案');
  181. //$(this).next().text('上傳檔案');
  182. },
  183. error: function (error) {
  184. event.target.nextSibling.innerHTML = '';
  185. event.target.nextSibling.textContent = '上傳檔案';
  186. alert('圖片錯誤');
  187. }
  188. });
  189. }
  190. const slide_button = document.querySelector('#send_slide');
  191. $("#send_slide").click(function () {
  192. slide_button.setAttribute('disabled', '');
  193. setTimeout(function () {
  194. slide_button.removeAttribute('disabled')
  195. }, 15000);
  196. avatar = $('.avatar').val();
  197. var step;
  198. multiLang = 0
  199. if ($('#multiLang').prop("checked")) {multiLang = 1;}
  200. dataOBJ = {'slide_url':$('#slide_raw_url').val(),"avatar": avatar,"multiLang":multiLang, "client_id": client_id }
  201. objstr = JSON.stringify(dataOBJ);
  202. jwt_token = get_jwt_token()
  203. var xhr = new XMLHttpRequest();
  204. xhr.open("POST", "https://www.choozmo.com:8887/make_anchor_video_gSlide");
  205. xhr.setRequestHeader("accept", "application/json");
  206. xhr.setRequestHeader("Authorization","Bearer "+jwt_token);
  207. xhr.setRequestHeader("Content-Type", "application/json");
  208. xhr.onreadystatechange = function () {
  209. if (xhr.readyState === 4) {
  210. Swal.fire({
  211. title: "資料已送出",
  212. icon: 'success',
  213. text: '資料已傳送,請耐心等候',
  214. confirmButtonColor: '#3085d6',
  215. });
  216. }
  217. };
  218. var data = renderXHR_data(dataOBJ)
  219. console.log(data)
  220. result = xhr.send(objstr);
  221. });
  222. var loaded_data = ''
  223. function openNav() {
  224. document.getElementById("mySidenav").style.width = "250px";
  225. document.querySelector('.loader').style.display = "block";
  226. let jwt_token = get_jwt_token();
  227. axios({
  228. method: 'post',
  229. url: 'https://www.choozmo.com:8887/history_input',
  230. headers: {
  231. 'accept': 'application/json',
  232. 'Authorization': `Bearer ${jwt_token}`
  233. }
  234. }).then(res => {
  235. console.log(res.data);
  236. loaded_data = res.data;
  237. var historyList = document.querySelector('.historyList');
  238. historyList.innerHTML = '';
  239. for (var obj of loaded_data) {
  240. var list = document.createElement('li');
  241. list.id = obj.id;
  242. // div-imgfr
  243. var divImgfr = document.createElement('div');
  244. divImgfr.classList.add('item_imgfr');
  245. var img = document.createElement('img');
  246. img.setAttribute('src', obj['image_urls'][0]);
  247. divImgfr.appendChild(img);
  248. // div-content
  249. var contentBox = document.createElement('div');
  250. contentBox.classList.add('content-box');
  251. var boxTitle = document.createElement('p');
  252. boxTitle.classList.add('box-title');
  253. boxTitle.textContent = obj.name;
  254. boxTitle.id = obj.id;
  255. boxTitle.setAttribute('onclick', `direct(${obj.id})`);
  256. var boxLink = document.createElement('span');
  257. boxLink.classList.add('box-link');
  258. boxLink.setAttribute("data-url", obj.link);
  259. boxLink.setAttribute('onclick', 'view()');
  260. boxLink.innerHTML = '<i class="fas fa-play-circle me-1"></i>觀看影片';
  261. contentBox.appendChild(boxTitle);
  262. contentBox.appendChild(boxLink);
  263. list.classList.add("historyList-item");
  264. list.appendChild(divImgfr);
  265. list.appendChild(contentBox);
  266. historyList.appendChild(list);
  267. }
  268. document.querySelector('.loader').style.display = "none";
  269. }).catch(err => {
  270. console.log(err);
  271. });
  272. }
  273. function direct(id) {
  274. location.href = `make_video2.html?id=${id}`;
  275. }
  276. function closeNav() {
  277. document.getElementById("mySidenav").style.width = "250px";
  278. }
  279. function view() {
  280. event.stopPropagation();
  281. console.log(event.target);
  282. if (event.target.nodeName === 'I') {
  283. return;
  284. } else {
  285. window.open(`http://${event.target.dataset.url}`, '_blank');
  286. }
  287. }
  288. function renderXHR_data(jsonObj) {
  289. XHRstring = ''
  290. for (const [key, value] of Object.entries(jsonObj)) {
  291. console.log(value)
  292. if (typeof (value) == "object") {
  293. XHRstring += (key+'=['+value.join(',')+']&')
  294. }
  295. else {
  296. XHRstring += (key + '=' + value + '&')
  297. }
  298. }
  299. XHRstring = XHRstring.substring(0, XHRstring.length - 1);
  300. return XHRstring
  301. }
  302. function get_jwt_token(){
  303. jwt_raw = document.cookie.split(';').filter(s=>s.includes('jwt_token'))[0];
  304. if(!jwt_raw) {return}
  305. return jwt_raw.split('=')[1];
  306. }
  307. getpathId();
  308. function getpathId() {
  309. id = window.location.search.split('?').pop();
  310. return id.split('=')[1];
  311. //load_data(id);
  312. }
  313. getData();
  314. function getData() {
  315. let jwt_token = get_jwt_token();
  316. axios({
  317. method: 'post',
  318. url: 'https://www.choozmo.com:8887/history_input',
  319. headers: {
  320. 'accept': 'application/json',
  321. 'Authorization': `Bearer ${jwt_token}`
  322. }
  323. }).then(res => {
  324. loaded_data = res.data;
  325. console.log(loaded_data);
  326. const id = getpathId();
  327. load_data(id, loaded_data);
  328. }).catch(err => {
  329. console.log(err);
  330. });
  331. }