ad_index.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. {% extends "admin/base.html" %}
  2. {% block extrahead %}{{ block.super }}
  3. <link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" type="text/css" />
  4. <script src="//code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  5. <script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  6. <script type="text/javascript">
  7. $(document).ready( function() {
  8. $.ajaxSetup({
  9. beforeSend: function(xhr, settings) {
  10. function getCookie(name) {
  11. var cookieValue = null;
  12. if (document.cookie && document.cookie != '') {
  13. var cookies = document.cookie.split(';');
  14. for (var i = 0; i < cookies.length; i++) {
  15. var cookie = jQuery.trim(cookies[i]);
  16. // Does this cookie string begin with the name we want?
  17. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  18. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  19. break;
  20. }
  21. }
  22. }
  23. return cookieValue;
  24. }
  25. if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
  26. // Only send the token to relative URLs i.e. locally.
  27. xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
  28. }
  29. }
  30. });
  31. $( '#filtersubmit' ).click( function() {
  32. console.log('Filter clicked');
  33. $.post("{% url adzone_xhr_ads_detail_table format='json' %}", {
  34. start: $( '#start' ).val(),
  35. end: $( '#end' ).val()
  36. },
  37. function(data) {
  38. $('#ad_table').find("tr:gt(0)").remove();
  39. var table_obj = $('#ad_table');
  40. $.each(data, function(index, item){
  41. console.log(item)
  42. var table_row = $('<tr>', {id: item.title});
  43. var title = $('<td>', {html: item[0]});
  44. var impressions = $('<td>', {html: item[1]});
  45. var clicks = $('<td>', {html: item[2]});
  46. table_row.append(title);
  47. table_row.append(impressions);
  48. table_row.append(clicks);
  49. table_obj.append(table_row);
  50. })
  51. });
  52. });
  53. });
  54. </script>
  55. {% endblock %}
  56. {% block title %}Ads | Penobscot Bay Press {% endblock %}
  57. {% block content %}
  58. {% load markup typogrify humanize adzone_tags %}
  59. <div id="ad-index">
  60. <h2>Ad overview</h2>
  61. <p>The intial ads metrics displayed are for all `enabled` ads for all time. Use the date filters to narrow down the time period.</p>
  62. <table class="ad_table" id="ad_table">
  63. <caption align="top">
  64. <div class="filterform">
  65. <label>From:</label><input class="dates" id="start" type="text"/>
  66. <label>To:</label><input class="dates" id="end" type="text"/>
  67. <input id="filtersubmit" type="submit" value="Filter" />
  68. </div>
  69. </caption>
  70. <caption align="top"><h3><strong>Impressions</strong></h3></caption>
  71. <tr><th>Ad Name</th><th>Impressions</th><th>Clicks</th><th></th></tr>
  72. {% if ads %}
  73. {% for ad in ads %}
  74. <tr>
  75. {% get_ad_stats for ad as stats %}
  76. <td>{{ad}}</td>
  77. {% for stat in stats %}<td>{{stat}}</td>{% endfor %}
  78. </tr>
  79. {% endfor %}
  80. {% else %}
  81. {% for ad_obj in ad_list %}
  82. <tr>
  83. {% for item in ad_obj %}<td>{{item}}</td>{% endfor %}
  84. </tr>
  85. {% endfor %}
  86. {% endif %}
  87. </table>
  88. </div>
  89. <script type="text/javascript">
  90. $(function() {
  91. $("#end").datepicker({ dateFormat: 'yy-mm-dd', defaultDate: -8}).datepicker('setDate', -8);
  92. $("#start").datepicker({ dateFormat: 'yy-mm-dd'}).datepicker('setDate', -1);
  93. });
  94. </script>
  95. {% endblock %}