]> git.parisson.com Git - telemeta.git/commitdiff
add edit popup for playlists, add delete warnings
authoryomguy <yomguy@parisson.com>
Fri, 10 Feb 2012 15:05:28 +0000 (16:05 +0100)
committeryomguy <yomguy@parisson.com>
Fri, 10 Feb 2012 15:05:28 +0000 (16:05 +0100)
telemeta/htdocs/js/playlist.js
telemeta/templates/telemeta/lists.html
telemeta/views/base.py

index c89f92223d07920eb4a974b234562eef39360d22..6a3d1382b9e998ae9cf37745d7b652ce75e6509e 100644 (file)
@@ -44,13 +44,20 @@ var playlistUtils = {
     playlists : [],
 
     addPlaylist: function(name, id){
-        //this.playlists[name]=id;
         this.playlists.push({
             'name':name,
             'id':id
         });
     },
 
+    addEditPlaylist: function(id, title, description){
+        this.playlists.push({
+            'id': id,
+            'title': title,
+            'description': description,
+        });
+    },
+
     showAdd: function(anchorElement){
 
         var t = gettrans('title');
@@ -111,10 +118,47 @@ var playlistUtils = {
         });
     },
 
-//     TODO: add edit fonction
+    update : function(dictionary){
+        json([dictionary],'telemeta.update_playlist',function(){
+        window.location.reload();
+        });
+    },
 
+    showEdit: function(anchorElement, id){
+
+        var t = gettrans('title');
+        var d = gettrans('description');
+        var dd = {};
+        var playlist = this;
+        
+        var playlists = this.playlists;
+        for (var i=0; i< playlists.length; i++){
+            if (playlists[i].id == id){
+                dd[t] = playlists[i].title;
+                dd[d] = playlists[i].description;
+            }
+        }
+        
+        new PopupDiv({
+            'content':dd,
+                    invoker:anchorElement,
+                    showOk:true,
+                    onOk:function(data){
+                        if(!data[t] && !data[d]){
+                            return;
+                        }
+                        //convert language
+                        playlist.update({
+                            'public_id': id,
+                            'title': data[t],
+                            'description': data[d],
+                        });
+                    }
+        }).show();
+    },
+    
     /*shows the popup for adding a resource to a playlist*/
-    showAddResourceToPlaylist: function(anchorElement,resourceType,objectId, optionalOkMessage){
+    showAddResourceToPlaylist: function(anchorElement, resourceType, objectId, optionalOkMessage){
         var ar = [];
         var playlists = this.playlists;
         for(var i=0; i< playlists.length; i++){
index 1b550534edf5c2d050046d2fea45f45de71e199c..f47df171513d62771f33552af3271eb82d654a9d 100644 (file)
         var p = playlistUtils;
         var a = jQuery('#_new_playlist'); 
         a.unbind('click').click(function(){p.showAdd(a);return false;});
-    });
+        });
+
+    {% for playlist in playlists %}
+        playlistUtils.addEditPlaylist('{{playlist.playlist.public_id}}','{{ playlist.playlist.title }}','{{playlist.playlist.description}}');
+    {% endfor %}
+        
+
 </script>
 {% endblock %}
 
     <table class="listing" style="width:100%;margin-top: 3em">
         <tr>
             <td style="border-bottom:1px solid #6A0307;color:#6A0307;font-size: 100%">{{ playlist.playlist.title }}</td>
-            <td style="width:66ex; padding-right: 0; border-bottom:1px solid #6A0307; text-align:right">
+            <td style="width:86ex; padding-right: 0; border-bottom:1px solid #6A0307; text-align:right">
+            <a href="#" id="{{playlist.playlist.public_id}}" onclick="playlistUtils.showEdit(this, this.id); return false;" class="component_icon button icon_edit">{% trans "Edit" %}</a>
                 <a href="{% url telemeta-playlist-csv-export playlist.playlist.public_id 'collections' %}" class="component_icon button icon_csv">CSV Collections</a>
                 <a href="{% url telemeta-playlist-csv-export playlist.playlist.public_id 'items' %}" class="component_icon button icon_csv">CSV Items</a>
-                <a href="#" id="{{playlist.playlist.public_id}}" onclick="playlistUtils.remove(this.id);return false;" class="component_icon button icon_cancel">{% trans "Delete" %}</a>
+                <a href="#" id="{{playlist.playlist.public_id}}" onclick="if(confirm(gettrans('delete the playlist permanently?'))){playlistUtils.remove(this.id);};return false;" class="component_icon button icon_cancel">{% trans "Delete" %}</a>
             </td>
         </tr>
         {% if playlist.playlist.description %}
                 {% endif %}
             </td>
             <td style="vertical-align:middle">
-                <a href="#" onclick="playlistUtils.removeResource('{{resource.public_id}}');return false;" class="component_icon button icon_cancel" style="padding: 4px 12px;"></a>
+            <a href="#" onclick="if(confirm(gettrans('delete the resource from the playlist permanently?'))){playlistUtils.removeResource('{{resource.public_id}}');};return false;" class="component_icon button icon_cancel" style="padding: 4px 12px;"></a>
             </td>
         </tr>
         {% endfor %}
index 9d2ef3613ce3a4e16b9a6147e561ed546d60f5bd..5a6fd3557c16d1fe62148dfff6178febc44d8af4 100644 (file)
@@ -1271,7 +1271,7 @@ class PlaylistView(object):
     def update_playlist(request, playlist):
         if isinstance(playlist, dict):
             m = Playlist.objects.get(public_id=playlist['public_id'])
-            m.title = float(playlist['title'])
+            m.title = playlist['title']
             m.description = playlist['description']
             m.save()
         else: