template.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. var AIRTIME = (function(AIRTIME) {
  2. var mod;
  3. var $historyTemplate;
  4. if (AIRTIME.template === undefined) {
  5. AIRTIME.template = {};
  6. }
  7. mod = AIRTIME.template;
  8. function createItemLi(id, name, configured) {
  9. var editUrl = baseUrl+"Playouthistorytemplate/configure-template/id/"+id;
  10. var defaultUrl = baseUrl+"Playouthistorytemplate/set-template-default/format/json/id/"+id;
  11. var removeUrl = baseUrl+"Playouthistorytemplate/delete-template/format/json/id/"+id;
  12. var itemConfigured =
  13. "<li class='template_configured' data-template='<%= id %>' data-name='<%= name %>'>" +
  14. "<a href='<%= editUrl %>' class='template_name'><%= name %></a>" +
  15. "<i class='icon icon-ok'></i>" +
  16. "</li>";
  17. var item =
  18. "<li data-template='<%= id %>' data-name='<%= name %>'>" +
  19. "<a href='<%= editUrl %>' class='template_name'><%= name %></a>" +
  20. "<a href='<%= removeUrl %>' class='template_remove'><i class='icon icon-trash'></i></a>" +
  21. "<a href='<%= defaultUrl %>' class='template_default'>" + $.i18n._('Set Default') + "</a>" +
  22. "</li>";
  23. var template = (configured) === true ? itemConfigured : item;
  24. var template = _.template(template);
  25. var $li = $(template({id: id, name: name, editUrl: editUrl, defaultUrl: defaultUrl, removeUrl: removeUrl}));
  26. return $li;
  27. }
  28. mod.onReady = function() {
  29. $historyTemplate = $("#history_template");
  30. $historyTemplate.on("click", ".template_remove", function(ev) {
  31. ev.preventDefault();
  32. var $a = $(this);
  33. var url = $a.attr("href");
  34. $a.parents("li").remove();
  35. $.post(url, function(){
  36. var x;
  37. });
  38. });
  39. $historyTemplate.on("click", ".template_default", function(ev) {
  40. ev.preventDefault();
  41. var $a = $(this);
  42. var url = $a.attr("href");
  43. var $oldLi, $newLi;
  44. $oldLi = $a.parents("ul").find("li.template_configured");
  45. $newLi = $a.parents("li");
  46. $oldLi.replaceWith(createItemLi($oldLi.data('template'), $oldLi.data('name'), false));
  47. $newLi.replaceWith(createItemLi($newLi.data('template'), $newLi.data('name'), true));
  48. $.post(url, function(){
  49. var x;
  50. });
  51. });
  52. function createTemplate(type) {
  53. var createUrl = baseUrl+"Playouthistorytemplate/create-template";
  54. $.post(createUrl, {format: "json", type: type}, function(json) {
  55. if (json.error !== undefined) {
  56. alert(json.error);
  57. return;
  58. }
  59. window.location.href = json.url;
  60. });
  61. }
  62. $historyTemplate.on("click", "#new_item_template", function() {
  63. createTemplate("item");
  64. });
  65. $historyTemplate.on("click", "#new_file_template", function() {
  66. createTemplate("file");
  67. });
  68. };
  69. return AIRTIME;
  70. }(AIRTIME || {}));
  71. $(document).ready(AIRTIME.template.onReady);