From fcebad195ef53f9815f434e601980437459d7cd8 Mon Sep 17 00:00:00 2001 From: mathieu Date: Tue, 3 May 2016 15:45:16 +0200 Subject: [PATCH] Ajout deja ajoute dans liste --- telemeta/static/telemeta/js/playlist.js | 159 ++++++++++-------- .../templates/telemeta/mediaitem_detail.html | 3 + 2 files changed, 88 insertions(+), 74 deletions(-) diff --git a/telemeta/static/telemeta/js/playlist.js b/telemeta/static/telemeta/js/playlist.js index 66e1eb6f..9e53df5c 100644 --- a/telemeta/static/telemeta/js/playlist.js +++ b/telemeta/static/telemeta/js/playlist.js @@ -28,29 +28,29 @@ //default PopupDiv properties for playlists (mainly for css appearence) PopupDiv.popupClass = 'control component'; PopupDiv.popupCss = { - 'border':'1px solid #999', - 'padding':'1ex' + 'border': '1px solid #999', + 'padding': '1ex' }; -PopupDiv.okButtonTitle = 'Ok'; -PopupDiv.okButtonClass = 'component_icon button icon_ok'; -PopupDiv.closeButtonTitle = ''; -PopupDiv.closeButtonClass = 'markersdivDelete'; +PopupDiv.okButtonTitle = 'Ok'; +PopupDiv.okButtonClass = 'component_icon button icon_ok'; +PopupDiv.closeButtonTitle = ''; +PopupDiv.closeButtonClass = 'markersdivDelete'; PopupDiv.defaultCloseOperation = 'remove'; PopupDiv.focusable = true; PopupDiv.listItemClass = "component_icon list_item icon_playlist"; var playlistUtils = { - playlists : [], + playlists: [], - addPlaylist: function(name, id){ + addPlaylist: function (name, id) { this.playlists.push({ - 'name':name, - 'id':id + 'name': name, + 'id': id }); }, - addEditPlaylist: function(id, title, description){ + addEditPlaylist: function (id, title, description) { this.playlists.push({ 'id': id, 'title': title, @@ -58,26 +58,26 @@ var playlistUtils = { }); }, - showAdd: function(anchorElement){ + showAdd: function (anchorElement) { var t = gettrans('title'); var d = gettrans('description'); var dd = {}; - dd[t]=''; - dd[d]=''; + dd[t] = ''; + dd[d] = ''; var playlist = this; new PopupDiv({ - 'content':dd, - invoker:anchorElement, - showOk:true, - onOk:function(data){ - if(!data[t] && !data[d]){ + 'content': dd, + invoker: anchorElement, + showOk: true, + onOk: function (data) { + if (!data[t] && !data[d]) { return; } //convert language playlist.add({ - 'title':data[t], - 'description':data[d] + 'title': data[t], + 'description': data[d] }); } }).show(); @@ -88,45 +88,45 @@ var playlistUtils = { * Copied from Timeside.utils.uniqid (Timeside might NOT ALWAYS be loaded, see home.html when user is authenitcated) * */ - uniqid : function() { + uniqid: function () { var d = new Date(); return new String(d.getTime() + '' + Math.floor(Math.random() * 1000000)).substr(0, 18); }, - add : function(dictionary){ + add: function (dictionary) { - if(dictionary.public_id===undefined){ + if (dictionary.public_id === undefined) { dictionary.public_id = this.uniqid(); } - if(dictionary.user===undefined){ + if (dictionary.user === undefined) { dictionary.user = CURRENT_USER_NAME; } - json([dictionary],'telemeta.add_playlist',function(){ + json([dictionary], 'telemeta.add_playlist', function () { window.location.reload(); }); }, - remove: function(id){ - json([id],'telemeta.del_playlist',function(){ + remove: function (id) { + json([id], 'telemeta.del_playlist', function () { window.location.reload(); }); }, - removeResource: function(id, range_playlist){ - json([id, range_playlist],'telemeta.del_playlist_resource',function(data){ - var id = data.result; - window.location.pathname = '/desk/lists/open-list-' + id; + removeResource: function (id, range_playlist) { + json([id, range_playlist], 'telemeta.del_playlist_resource', function (data) { + var id = data.result; + window.location.pathname = '/desk/lists/open-list-' + id; }); }, - update : function(dictionary){ - json([dictionary],'telemeta.update_playlist',function(){ - window.location.reload(); + update: function (dictionary) { + json([dictionary], 'telemeta.update_playlist', function () { + window.location.reload(); }); }, - showEdit: function(anchorElement, id){ + showEdit: function (anchorElement, id) { var t = gettrans('title'); var d = gettrans('description'); @@ -134,79 +134,90 @@ var playlistUtils = { var playlist = this; var playlists = this.playlists; - for (var i=0; i< playlists.length; i++){ - if (playlists[i].id == id){ + 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], - }); - } + '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++){ + for (var i = 0; i < playlists.length; i++) { ar.push(playlists[i].name); } var pl = this; - if(!ar.length){ + if (!ar.length) { pl.showAdd(anchorElement); } //var addFcn = this.addResourceToPlaylist; new PopupDiv({ - invoker:anchorElement, + invoker: anchorElement, content: ar, - onOk:function(data){ + onOk: function (data) { var val = data.selIndex; var callbackok = undefined; - if(optionalOkMessage){ - callbackok = function(){ - var p =new PopupDiv({ - content : "
"+optionalOkMessage+"
", - focusable: false - - }); - p.bind('show', function(){ - this.setTimeout('close',1500); //this refers to p - }); - p.show(); + if (optionalOkMessage) { + callbackok = function () { + localStorage['messOkPlaylist'] = optionalOkMessage; + localStorage['displayOkPlaylist']=true; + window.location.reload(); } } - pl.addResourceToPlaylist.apply(pl,[playlists[val].id,resourceType,objectId,callbackok]); + pl.addResourceToPlaylist.apply(pl, [playlists[val].id, resourceType, objectId, callbackok]); } }).show(); }, //resourceType can be: 'collection', 'item', 'marker' - addResourceToPlaylist: function(playlistId,resourceType,objectId, callbackOnSuccess,callbackOnError){ + addResourceToPlaylist: function (playlistId, resourceType, objectId, callbackOnSuccess, callbackOnError) { var send = { - 'public_id':this.uniqid(), - 'resource_type':resourceType, - 'resource_id':objectId + 'public_id': this.uniqid(), + 'resource_type': resourceType, + 'resource_id': objectId }; - json([playlistId,send],'telemeta.add_playlist_resource',callbackOnSuccess,callbackOnError); + json([playlistId, send], 'telemeta.add_playlist_resource', callbackOnSuccess, callbackOnError); + }, + + messageOk: function () { + if (localStorage['displayOkPlaylist']) { + var p = new PopupDiv({ + content: "
" + localStorage['messOkPlaylist']+ "
", + focusable: false + + }); + p.bind('show', function () { + this.setTimeout('close', 1500); //this refers to p + }); + p.show(); + localStorage.removeItem('displayOkPlaylist'); + localStorage.removeItem('messOkPlaylist'); + } + } diff --git a/telemeta/templates/telemeta/mediaitem_detail.html b/telemeta/templates/telemeta/mediaitem_detail.html index de2ed032..c29ab7f4 100644 --- a/telemeta/templates/telemeta/mediaitem_detail.html +++ b/telemeta/templates/telemeta/mediaitem_detail.html @@ -72,9 +72,12 @@ if(anchor.length){ anchor.unbind('click').click(function(){ playlistUtils.showAddResourceToPlaylist(anchor,'item','{{item.id}}',gettrans('item added to the selected playlist')); + //playlistUtils.showAddResourceToPlaylist(anchor,'item','{{item.id}}'); return false; }); } + + playlistUtils.messageOk(); }); {% endif %} -- 2.39.5