Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

dashboard.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var oscar = oscar || {};
  2. oscar.getCsrfToken = function() {
  3. var cookies = document.cookie.split(';');
  4. var csrf_token = null;
  5. $.each(cookies, function(index, cookie) {
  6. cookieParts = $.trim(cookie).split('=');
  7. if (cookieParts[0] == 'csrftoken') {
  8. csrfToken = cookieParts[1];
  9. }
  10. });
  11. return csrfToken;
  12. };
  13. oscar.dashboard = {
  14. init: function() {
  15. $('input[name^="date"], input[name$="date"]').datepicker({dateFormat: 'yy-mm-dd'});
  16. },
  17. ranges: {
  18. init: function() {
  19. $('[data-behaviours~="remove"]').click(function() {
  20. $this = $(this);
  21. $this.parents('table').find('input').attr('checked', false);
  22. $this.parents('tr').find('input').attr('checked', 'checked');
  23. $this.parents('form').submit();
  24. });
  25. }
  26. },
  27. orders: {
  28. initTabs: function() {
  29. if (location.hash) {
  30. $('.nav-tabs a[href=' + location.hash + ']').tab('show');
  31. }
  32. },
  33. initTable: function() {
  34. var table = $('form table'),
  35. input = $('<input type="checkbox" />').css({
  36. 'margin-right': '5px',
  37. 'vertical-align': 'top'
  38. });
  39. $('th:first', table).prepend(input);
  40. $(input).change(function(){
  41. $('tr', table).each(function() {
  42. $('td:first input', this).prop("checked", $(input).is(':checked'));
  43. });
  44. });
  45. }
  46. },
  47. promotions: {
  48. init: function() {
  49. $('.promotion_list').sortable({
  50. handle: '.btn-handle',
  51. stop: oscar.dashboard.promotions.saveOrder
  52. });
  53. },
  54. saveOrder: function(event, ui) {
  55. // Get the csrf token, otherwise django will not accept the
  56. // POST request.
  57. var serial = $(this).sortable("serialize"),
  58. csrf = oscar.getCsrfToken();
  59. serial = serial + '&csrfmiddlewaretoken=' + csrf;
  60. $.ajax({
  61. type: 'POST',
  62. data: serial,
  63. dataType: "json",
  64. url: '#',
  65. beforeSend: function(xhr, settings) {
  66. xhr.setRequestHeader("X-CSRFToken", csrf);
  67. }
  68. });
  69. }
  70. },
  71. search: {
  72. init: function() {
  73. var searchForm = $(".orders_search"),
  74. searchLink = $('.pull_out'),
  75. doc = $('document');
  76. searchForm.each(function(index) {
  77. doc.css('height', doc.height());
  78. });
  79. searchLink.on('click', function() {
  80. searchForm.parent()
  81. .find('.pull-left')
  82. .toggleClass('no-float')
  83. .end().end()
  84. .slideToggle("fast");
  85. }
  86. );
  87. }
  88. }
  89. };