public
Description: the code behind metratime.com
Homepage: http://metratime.googlegroups.com
Clone URL: git://github.com/cosmin/metratime.git
added ajax screen for setting station order
cosmin (author)
Sun Apr 27 18:13:19 -0700 2008
commit  b95e92ed7cac5dc841280749b1562979f6df1d33
tree    113dc6d161a660afa06ba8dab7a3d3cfd39bb822
parent  12f52c4832207f9f61203ad4cc23c3358510730f
...
58
59
60
61
62
63
 
 
 
 
64
65
66
67
68
69
70
71
72
73
74
75
76
 
 
 
 
 
 
 
 
77
78
79
...
58
59
60
 
 
 
61
62
63
64
65
 
 
 
 
 
 
 
 
 
 
 
 
66
67
68
69
70
71
72
73
74
75
76
0
@@ -58,22 +58,19 @@ def edit_line(request, line_name):
0
     stations = line.stations.order('index')
0
 
0
     if request.method == 'POST':
0
- for s in stations:
0
- index = request.POST.get(s.url_name)
0
- if index is None:
0
+ station_keys = request.POST.get('order', "").split("+")
0
+ i = 1
0
+ for k in station_keys:
0
+ if not k:
0
                 continue
0
- try:
0
- s.index = int(index)
0
- s.put()
0
- except:
0
- logging.debug('Skipping %s with %s' % (s.name, index))
0
- continue
0
-
0
-
0
- stations = line.stations.order('index')
0
-
0
-
0
- return render_to_response('edit_line.html', locals())
0
+ s = models.Station.get_by_key_name(k, parent=line)
0
+ s.index = i
0
+ s.put()
0
+ i += 1
0
+ return HttpResponse("done")
0
+ else:
0
+ #stations = line.stations.order('index'
0
+ return render_to_response('edit_line.html', locals())
0
 
0
 def choose_edit_line(request):
0
     lines = models.TrainLine.all()
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
7
 
8
9
10
11
12
 
13
14
15
16
 
 
 
17
18
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
 
45
46
 
 
 
 
47
48
 
 
 
49
50
51
52
53
0
@@ -1,18 +1,53 @@
0
 <html>
0
 <head>
0
 <title>Edit line {{ line.name }}</title>
0
+<!--script type="text/javascript" src="/static/javascripts/jquery-1.2.3.min.js"></script>
0
+<script type="text/javascript" src="/static/javascripts/ui.base.min.js" /></script>
0
+<script type="text/javascript" src="/static/javascripts/ui.sortable.min.js" /></script -->
0
+<script src="http://dev.jquery.com/view/tags/ui/1.5b2/jquery-1.2.4a.js"></script>
0
+<script src="http://dev.jquery.com/view/tags/ui/1.5b2/ui.base.js"></script>
0
+<script src="http://dev.jquery.com/view/tags/ui/1.5b2/ui.sortable.js"></script>
0
+
0
+<script type="text/javascript">
0
+
0
+function refreshPage(recv) {
0
+ alert("Saved!");
0
+ window.location.reload(true);
0
+}
0
+
0
+$(document).ready( function () {
0
+ $("#stations").sortable({});
0
+ $("#savebutton").click( function() {
0
+ var data = "";
0
+ var children = $("#stations").children();
0
+ for (i=0;i<children.length;i++) {
0
+ data += children[i].id + "+";
0
+ }
0
+ $.ajax({
0
+ url: "#",
0
+ type: "POST",
0
+ data: {order: data},
0
+ processData: "false",
0
+ success: refreshPage
0
+ });
0
+ });
0
+
0
+});
0
+
0
+</script>
0
+
0
+<style>
0
+ ul { list-style: none; }
0
+ li { background: #427EA3; color: #FFF; width: 200px; margin: 5px; font-size: 14px; font-family: Arial; padding: 3px; }
0
+</style>
0
 </head>
0
 <body>
0
-<form action="" method="POST">
0
-<table>
0
+<ul id="stations" style="cursor: hand; cursor: pointer;">
0
 {% for s in stations %}
0
-<tr>
0
- <td><label for="{{s.url_name}}">{{s.name}}</label></td>
0
- <td><input type="text" name="{{s.url_name}}" value="{{s.index}}"/></td>
0
-</tr>
0
+ <li id="{{s.url_name}}">{{s.name}}</li>
0
 {% endfor %}
0
-</table>
0
-<a href="/edit/line/">Back</a> <input type="submit" value="Update"/>
0
-</form>
0
+</ul>
0
+<button id="savebutton">Save</button
0
+<button onclick="window.location = '/edit/line/';">Cancel</button>
0
 </body>
0
 </html>

Comments

    No one has commented yet.