Browse Source

Added JS locking of forms to prevent multiple items being created.

master
David Winterbottom 13 years ago
parent
commit
7baf43c1b0

+ 0
- 2
oscar/apps/checkout/utils.py View File

@@ -1,5 +1,3 @@
1
-from django.core.urlresolvers import resolve
2
-
3 1
 from oscar.core.loading import get_class
4 2
 Repository = get_class('shipping.repository', 'Repository')
5 3
 

+ 0
- 3
oscar/apps/order/models.py View File

@@ -1,6 +1,3 @@
1
-u"""Vanilla implementation of order models"""
2
-from django.db import models
3
-
4 1
 from oscar.apps.order.abstract_models import *
5 2
 from oscar.apps.address.abstract_models import AbstractShippingAddress, AbstractBillingAddress
6 3
 

+ 2
- 2
oscar/apps/payment/forms.py View File

@@ -1,4 +1,4 @@
1
-from datetime import date, datetime
1
+from datetime import date
2 2
 from calendar import monthrange
3 3
 import re
4 4
 
@@ -219,7 +219,7 @@ class BillingAddressForm(forms.ModelForm):
219 219
         super(BillingAddressForm,self ).__init__(*args, **kwargs)
220 220
         self.set_country_queryset() 
221 221
         
222
-    def set_country_queryset(self):    
222
+    def set_country_queryset(self):
223 223
         self.fields['country'].queryset = address_models.Country._default_manager.all()
224 224
     
225 225
     class Meta:

+ 15
- 0
oscar/static/oscar/js/oscar/ui.js View File

@@ -12,6 +12,21 @@ oscar.messages = {
12 12
     warning: function(msg) { oscar.messages.addMessage('warning', msg); },
13 13
     error: function(msg) { oscar.messages.addMessage('error:', msg); }
14 14
 };
15
+oscar.forms = {
16
+    init: function() {
17
+        // Forms with this behaviour are 'locked' once they are submitted to 
18
+        // prevent multiple submissions
19
+        $('form[data-behaviours~="lock"]').submit(oscar.forms.submitIfNotLocked);
20
+    },
21
+    submitIfNotLocked: function(event) {
22
+        $form = $(this);
23
+        if ($form.data('locked')) {
24
+            return false;
25
+        }
26
+        $form.data('locked', true);
27
+    }
28
+};
29
+$(function(){oscar.forms.init();});
15 30
 
16 31
 $(document).ready(function()
17 32
 {   

+ 2
- 2
oscar/templates/customer/address-form.html View File

@@ -30,11 +30,11 @@
30 30
 {% endblock header %}
31 31
 
32 32
 {% block content %}
33
-<form action="." method="post" class="form-horizontal">
33
+<form action="." method="post" class="form-horizontal" data-behaviours="lock">
34 34
     {% csrf_token %}
35 35
     {% include "partials/form_fields.html" with form=form %}
36 36
     <div class="form-actions">
37
-        <button type="submit" value="Save address" class="btn btn-primary">Save address</button>
37
+        <button type="submit" value="Save" class="btn btn-primary btn-large">Save</button>
38 38
         or
39 39
         <a href="{% url customer:address-list %}">cancel</a>
40 40
     </div>

Loading…
Cancel
Save