playlist_widget.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. var playlist_data = JSON.parse(document.getElementById('playlist_data').textContent);
  3. var payload = 'csrf_token=' + playlist_data.csrf_token;
  4. function add_playlist_video(target) {
  5. var select = target.parentNode.children[0].children[1];
  6. var option = select.children[select.selectedIndex];
  7. var url = '/playlist_ajax?action_add_video=1&redirect=false' +
  8. '&video_id=' + target.getAttribute('data-id') +
  9. '&playlist_id=' + option.getAttribute('data-plid');
  10. helpers.xhr('POST', url, {payload: payload}, {
  11. on200: function (response) {
  12. option.textContent = '✓' + option.textContent;
  13. }
  14. });
  15. }
  16. function add_playlist_item(target) {
  17. var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
  18. tile.style.display = 'none';
  19. var url = '/playlist_ajax?action_add_video=1&redirect=false' +
  20. '&video_id=' + target.getAttribute('data-id') +
  21. '&playlist_id=' + target.getAttribute('data-plid');
  22. helpers.xhr('POST', url, {payload: payload}, {
  23. onNon200: function (xhr) {
  24. tile.style.display = '';
  25. }
  26. });
  27. }
  28. function remove_playlist_item(target) {
  29. var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
  30. tile.style.display = 'none';
  31. var url = '/playlist_ajax?action_remove_video=1&redirect=false' +
  32. '&set_video_id=' + target.getAttribute('data-index') +
  33. '&playlist_id=' + target.getAttribute('data-plid');
  34. helpers.xhr('POST', url, {payload: payload}, {
  35. onNon200: function (xhr) {
  36. tile.style.display = '';
  37. }
  38. });
  39. }