list.html 3.94 KB
Newer Older
1 2 3 4 5 6
<%! from django.utils.translation import ugettext as _ %>

<%! from django.core.urlresolvers import reverse %>

<%inherit file="../main.html" />

7
<%block name="pagetitle">${_("Your Shopping Cart")}</%block>
8 9

<section class="container cart-list">
10
  <h2>${_("Your selected items:")}</h2>
11
    <h3 class="cart-errors" id="cart-error">Error goes here.</h3>
12 13 14 15 16
  % if shoppingcart_items:
    <table class="cart-table">
      <thead>
        <tr class="cart-headings">
          <th class="dsc">${_("Description")}</th>
17
          <th class="u-pr">${_("Price")}</th>
18
          <th class="cur">${_("Currency")}</th>
19
          <th>&nbsp;</th>
20 21 22 23 24 25
        </tr>
      </thead>
      <tbody>
        % for item in shoppingcart_items:
        <tr class="cart-items">
          <td>${item.line_desc}</td>
26 27 28 29 30 31
          <td>
              ${"{0:0.2f}".format(item.unit_cost)}
              % if item.list_price != None:
                <span class="old-price"> ${"{0:0.2f}".format(item.list_price)}</span>
              % endif
          </td>
32 33 34 35
          <td>${item.currency.upper()}</td>
          <td><a data-item-id="${item.id}" class='remove_line_item' href='#'>[x]</a></td>
        </tr>
        % endfor
36
        <tr class="always-gray">
37
            <td colspan="4" valign="middle" class="cart-total" align="right">
38 39
                <b>${_("Total Amount")}: <span> ${"{0:0.2f}".format(amount)} </span> </b>
            </td>
40
        </tr>
41

42
      </tbody>
43 44 45
      <tfoot>
        <tr class="always-white">
            <td colspan="2">
46 47
                 <input type="text" placeholder="Enter code here" name="cart_code" id="code">
                 <input type="button" value="Apply Code" id="cart-code">
48 49
            </td>
            <td colspan="4" align="right">
50 51 52 53 54
                % if amount == 0:
                     <input type="button" value = "Register" id="register" >
                % else:
                   ${form_html}
                %endif
55 56 57 58
            </td>
        </tr>

      </tfoot>
59 60 61 62 63
    </table>
    <!-- <input id="back_input" type="submit" value="Return" /> -->
  % else:
    <p>${_("You have selected no items for purchase.")}</p>
  % endif
64

65 66 67 68
</section>


<script>
69 70 71 72 73 74 75 76
  $(function() {
    $('a.remove_line_item').click(function(event) {
      event.preventDefault();
      var post_url = "${reverse('shoppingcart.views.remove_item')}";
      $.post(post_url, {id:$(this).data('item-id')})
        .always(function(data){
        location.reload(true);
      });
77
    });
78

79
    $('#cart-code').click(function(event){
80
      event.preventDefault();
81
      var post_url = "${reverse('shoppingcart.views.use_code')}";
82
      $.post(post_url,{
83
               "code" :  $('#code').val(),
84
                beforeSend: function(xhr, options){
85 86
                 if($('#code').val() == "") {
                     showErrorMsgs('Must enter a valid code')
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                     xhr.abort();
                    }
                }
               }
      )
      .success(function(data) {
                 location.reload(true);
              })
      .error(function(data,status) {
                  if(status=="parsererror"){
                       location.reload(true);
                  }else{
                        showErrorMsgs(data.responseText)
                      }
             })
    });

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    $('#register').click(function(event){
      event.preventDefault();
      var post_url = "${reverse('shoppingcart.views.register_courses')}";
      $.post(post_url)
      .success(function(data) {
                  window.location.href = "${reverse('dashboard')}";
              })
      .error(function(data,status) {
                  if(status=="parsererror"){
                       location.reload(true);
                  }else{
                        showErrorMsgs(data.responseText)
                      }
             })
    });

120 121 122
    $('#back_input').click(function(){
      history.back();
    });
123 124 125 126 127

    function showErrorMsgs(msg){
        $(".cart-errors").css('display', 'block');
        $("#cart-error").html(msg);
    }
128
  });
129
</script>