Permalink
Browse files

Moving sorting functions to separate file.

  • Loading branch information...
1 parent 58b3cf6 commit ed210f97e0b9703b4058307b6ca98a8e40bea3fa @ext committed Apr 21, 2012
Showing with 59 additions and 38 deletions.
  1. +4 −1 slideshow/static/css/main.css
  2. +46 −0 slideshow/static/js/sorting.js
  3. +9 −37 slideshow/templates/slides/view.html
@@ -198,7 +198,10 @@ img {
}
.slide_placeholder {
- border: 3px dashed #666;
+ border: 3px dashed #666;
+ float: left;
+ height: 227px;
+ width: 200px;
}
h1, h2 {
@@ -0,0 +1,46 @@
+$(document).ready(function(){
+ /* queue is a global variable */
+ for ( i in queue ){
+ var id = queue[i];
+ var other = queue.filter(function(x){ return x != id; });
+ $(id).bind('updated', function() {
+ var self = '#' + $(this).attr('id');
+ var list = $(this).sortable('toArray');
+ var n = list.length;
+
+ /* show/hide warning about empty queue */
+ if ( self == active ){
+ console.log('n: ' + n);
+ if ( notice_visible && n > 0 ){
+ console.log('hiding');
+ notice_visible = false;
+ $("#empty_notice").fadeOut("slow");
+ }
+ if ( !notice_visible && n == 0 ){
+ console.log('showing');
+ notice_visible = true;
+ $("#empty_notice").fadeIn("slow");
+ }
+ }
+
+ /* notify server about update */
+ $.ajax({
+ type: "POST",
+ url: "/slides/ajax/move",
+ data: "queue=" + $(this).attr('id') + "&slides=" + list,
+ error: function(x, status, error){
+ alert(status + '\n' + error);
+ },
+ });
+ });
+ $(id).sortable({
+ connectWith: other,
+ placeholder: 'slide_placeholder',
+ tolerance: 'pointer',
+ update: function(){
+ $(this).trigger('updated');
+ },
+ });
+ $(id).disableSelection();
+ }
+});
@@ -4,10 +4,16 @@
lang="en">
<xi:include href="../index.html" />
-<head>
-</head>
+ <head>
+ <script src="/static/js/sorting.js" type="text/javascript"></script>
+ <script type="text/javascript">
+ var queue = [ ${', '.join(['"#%s"' % q.div for q in queues])} ];
+ var active = "${'#' + active.div}";
+ var notice_visible = ${len(active) == 0 and 'true' or 'false'};
+ </script>
+ </head>
-<body>
+ <body>
<h2>Current slides</h2>
<?python empty_queue = active.id == 0 or len(active) == 0 ?>
@@ -51,40 +57,6 @@ <h2>Current slides</h2>
<br style="clear: both;" />
</div>
</py:for>
-
- <script type="text/javascript">
- var notice_visible = ${len(active) == 0 and 'true' or 'false'};
- <py:for each="queue in queues">
- $$("#${queue.div}").sortable({
- connectWith: [ ${', '.join(['"#%s"' % q.div for q in queues])} ],
- placeholder: 'slide_placeholder',
- tolerance: "pointer",
-
- update: function($$e, $$ui){
- var list = $$(this).sortable('toArray');
- $$.ajax({
- type: "POST",
- url: "/slides/ajax/move",
- data: "queue=" + $$(this).attr('id') + "${Markup('&amp;')}slides=" + list
- });
-
- <py:if test="queue.id == active.id">
- var n = list.length;
- if ( notice_visible ${Markup('&amp;&amp;')} n ${Markup('&gt;')} 0 ){
- notice_visible = false;
- $("#empty_notice").fadeOut("slow");
- }
- if ( !notice_visible ${Markup('&amp;&amp;')} n == 0 ){
- notice_visible = true;
- $("#empty_notice").fadeIn("slow");
- }
- </py:if>
-
- }
- });
- </py:for>
- </script>
-
</body>
</html>

0 comments on commit ed210f9

Please sign in to comment.