Allow loading a previously saved slot allocation
authorSverre Rabbelier <srabbelier@gmail.com>
Fri, 10 Apr 2009 15:45:52 +0000
changeset 2147 5dd2091c8f0c
parent 2146 57c74ce47fa3
child 2148 0345046ed7a5
Allow loading a previously saved slot allocation Patch by: Sverre Rabbelier
app/soc/content/js/slot-allocator-090320.js
app/soc/templates/soc/program/allocation/allocation.html
app/soc/views/models/program.py
--- a/app/soc/content/js/slot-allocator-090320.js	Fri Apr 10 15:32:11 2009 +0000
+++ b/app/soc/content/js/slot-allocator-090320.js	Fri Apr 10 15:45:52 2009 +0000
@@ -57,6 +57,11 @@
   $.postJSON(url, current_slots, updateFromJSON);
 }
 
+function load() {
+  url = RETURN_URL+"?load=1&_="+(new Date().getTime())
+  $.postJSON(url, current_slots, updateFromJSON);
+}
+
 function updateOverlay() {
   updateCurrentSlots();
   var remaining_slots = MAX_AVAILABLE_SLOTS - current_allocated_slots;
--- a/app/soc/templates/soc/program/allocation/allocation.html	Fri Apr 10 15:32:11 2009 +0000
+++ b/app/soc/templates/soc/program/allocation/allocation.html	Fri Apr 10 15:45:52 2009 +0000
@@ -20,6 +20,7 @@
 
 <input type="button" class="button" onclick="javascript:reCalculate()" value="Recalculate slots" />
 <input type="button" class="button" onclick="javascript:submit()" value="Submit" />
+<input type="button" class="button" onclick="javascript:load()" value="Load" />
 
 {{ block.super }}
 
--- a/app/soc/views/models/program.py	Fri Apr 10 15:32:11 2009 +0000
+++ b/app/soc/views/models/program.py	Fri Apr 10 15:45:52 2009 +0000
@@ -299,8 +299,14 @@
     if request.method == 'POST' and 'result' in request.POST:
       result = request.POST['result']
       submit = request.GET.get('submit')
+      load = request.GET.get('load')
+      stored = program.slots_allocation
+
+      if load and stored:
+        result = stored
 
       from_json = simplejson.loads(result)
+
       locked_slots = dicts.groupDictBy(from_json, 'locked', 'slots')
 
       if submit: