mirror of
https://github.com/fergalmoran/dss.git
synced 2026-01-01 06:28:39 +00:00
Adding playlists done
This commit is contained in:
@@ -10,7 +10,7 @@ from spa.models import Playlist, Mix
|
||||
|
||||
class PlaylistResource(BackboneCompatibleResource):
|
||||
user = fields.ToOneField('spa.api.v1.UserResource.UserResource', 'user')
|
||||
mixes = fields.ManyToManyField('spa.api.v1.MixResource.MixResource', 'mixes', null=True)
|
||||
mixes = fields.ManyToManyField('spa.api.v1.MixResource.MixResource', 'mixes', full=True, null=True)
|
||||
|
||||
class Meta:
|
||||
queryset = Playlist.objects.all().annotate(mix_count=Count('mixes')).order_by('-mix_count')
|
||||
@@ -33,6 +33,18 @@ class PlaylistResource(BackboneCompatibleResource):
|
||||
bundle.obj.user = bundle.request.user.get_profile()
|
||||
return bundle
|
||||
|
||||
def obj_update(self, bundle, skip_errors=False, **kwargs):
|
||||
mixes = bundle.data['mixes']
|
||||
bundle.data.pop('mixes')
|
||||
result = super(PlaylistResource, self).obj_update(bundle, **kwargs)
|
||||
if mixes:
|
||||
for mix_item in mixes:
|
||||
result.obj.mixes.add(Mix.objects.get(pk=mix_item['id']))
|
||||
|
||||
result.obj.save()
|
||||
|
||||
return result
|
||||
|
||||
def obj_create(self, bundle, **kwargs):
|
||||
mixes = bundle.data['mixes']
|
||||
bundle.data.pop('mixes')
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
width: 320px !important;
|
||||
}
|
||||
|
||||
.profile-feed{
|
||||
.profile-activity{
|
||||
cursor: pointer !important;
|
||||
}
|
||||
@@ -8,7 +8,26 @@
|
||||
collectionType: App.MixApp.Models.MixCollection
|
||||
]
|
||||
|
||||
containsMix: (mix, callback) ->
|
||||
mixes = @get("mixes")
|
||||
result = false
|
||||
if mixes.length != 0
|
||||
mixes.each (item) ->
|
||||
if item.id == mix.id
|
||||
result = true
|
||||
|
||||
callback(result)
|
||||
|
||||
class Models.PlaylistCollection extends Backbone.Collection
|
||||
model: Models.PlaylistItem
|
||||
|
||||
Models.PlaylistCollection
|
||||
containsMix: (mix, callback)->
|
||||
return callback(false) if item.length = 0
|
||||
@each (item) ->
|
||||
if item.containsMix(mix, callback)
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
save: (options)->
|
||||
Backbone.sync("create", this, options)
|
||||
|
||||
@@ -1,3 +1,37 @@
|
||||
@Dss.module "PlaylistApp.Views", (Views, App, Backbone, Marionette, $ ) ->
|
||||
@Dss.module "PlaylistApp.Views", (Views, App, Backbone, Marionette, $) ->
|
||||
class Views.PlaylistItemView extends Marionette.ItemView
|
||||
template: "playlistitem"
|
||||
tagName: "ul"
|
||||
className: "item-list"
|
||||
|
||||
ui:
|
||||
mixExistsIndicator: ".playlist-selected-indicator"
|
||||
|
||||
events:
|
||||
"click .profile-activity": "onClickItem"
|
||||
|
||||
onClickItem: (e) ->
|
||||
console.log("Clicky clicky")
|
||||
e.stopPropagation()
|
||||
|
||||
@model.containsMix @mix, (result) =>
|
||||
if result
|
||||
@model.get("mixes").remove(@mix)
|
||||
else
|
||||
@model.get("mixes").add(@mix)
|
||||
|
||||
@model.save(
|
||||
"mixes"
|
||||
@model.get("mixes")
|
||||
patch: true
|
||||
)
|
||||
|
||||
@render()
|
||||
|
||||
setContained: (contained)=>
|
||||
@ui.mixExistsIndicator.prop('checked', contained)
|
||||
|
||||
|
||||
onRender: ->
|
||||
@ui.mixExistsIndicator.hide()
|
||||
@model.containsMix(@mix, @setContained)
|
||||
|
||||
@@ -16,12 +16,19 @@
|
||||
Marionette.CompositeView::constructor.apply this, arguments
|
||||
@mix = arguments[0].mix
|
||||
|
||||
onRender: ->
|
||||
console.log("Rendering")
|
||||
initialize: ->
|
||||
console.log("Initializing playlist")
|
||||
|
||||
stopDefaults: (e)->
|
||||
e.stopPropagation()
|
||||
|
||||
onBeforeAddChild: (child)->
|
||||
child.mix = @mix
|
||||
|
||||
renderIntermediate: ->
|
||||
debugger
|
||||
@render()
|
||||
|
||||
addPlaylist: (e)=>
|
||||
console.log("Clicked")
|
||||
unless typeof(App.currentUser) is "undefined"
|
||||
@@ -32,7 +39,7 @@
|
||||
mixes: [id: @mix.id]
|
||||
|
||||
playlist.save()
|
||||
|
||||
@collection.add(playlist)
|
||||
console.log("Adding new: " + playlistName)
|
||||
else
|
||||
@ui.newPlaylistLayout.addClass('has-error')
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
<div class="profile-activity clearfix">
|
||||
<div><%= name %></div>
|
||||
<div class="tools action-buttons">
|
||||
<li class="clearfix profile-activity">
|
||||
|
||||
<label class="inline">
|
||||
<input type="checkbox" name="form-field-checkbox" class="ace playlist-selected-indicator">
|
||||
<span class="lbl"> <%= name %></span>
|
||||
</label>
|
||||
|
||||
<div class="pull-right tools action-buttons">
|
||||
<a href="#" class="blue">
|
||||
<i class="ace-icon fa fa-pencil bigger-125"></i>
|
||||
<i class="ace-icon fa fa-pencil bigger-130"></i>
|
||||
</a>
|
||||
<span class="vbar"></span>
|
||||
<a href="#" class="red">
|
||||
<i class="ace-icon fa fa-times bigger-125"></i>
|
||||
<i class="ace-icon fa fa-trash-o bigger-130"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<div class="widget-main padding">
|
||||
<div class="profile-feed playlist-feed" id="existing-playlists"></div>
|
||||
<div id="existing-playlists">
|
||||
|
||||
</div>
|
||||
<div id="playlist-footer-add" class="well-sm">
|
||||
<form id="playlist-add-form" class="form-horizontal">
|
||||
<div class="row">
|
||||
|
||||
Reference in New Issue
Block a user