Last active
December 21, 2015 07:58
-
-
Save alexspeller/6274662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RESOURCES | |
filteredContent: function() { | |
var view = this; | |
active_asset = view.get('settings.active_asset'), | |
active_playlist = view.get('parentView.settings.active_playlist'), | |
smart_playlist = ['all', 'pending_review', 'reviewed', 'approved'], | |
content = view.get('context.resources'); | |
view.set('activePlaylist', null); | |
switch(active_playlist) { | |
case 'all': | |
content = content; | |
break; | |
case 'pending_review': | |
content = view.pendingReviewContent(); | |
break; | |
case 'reviewed': | |
content = view.reviewedContent(); | |
break; | |
case 'approved': | |
content = view.approvedContent(); | |
break; | |
default: | |
break; | |
} | |
if (active_asset !== 'all') { | |
content = content.filterProperty('asset.id', active_asset); | |
} | |
if (smart_playlist.contains(active_playlist)) { | |
return content; | |
} else { | |
var view = this, playlist = App.Playlist.find(view.get('settings.active_playlist')); | |
var arr = playlist.get('resource_position'); | |
return view.playlistContent().sort(function(a, b) { | |
if (arr.indexOf(a.get('id')) < arr.indexOf(b.get('id'))) { | |
return -1; | |
} | |
if (arr.indexOf(a.get('id')) > arr.indexOf(b.get('id'))) { | |
return 1; | |
} | |
return 0; | |
}); | |
} | |
}.property('settings.active_asset', 'settings.active_playlist', 'context.resources.@each'), | |
searchedContent: function() { | |
var view = this; | |
if (view.get('searchResourcesText') === '') { | |
view.set('filteredContent', view.get('context.resources')); | |
} else { | |
var get = $.get('/backbone/resources.json', {search: {query_string: view.get('searchResourcesText') + '*'}}); | |
get.success(function(data) { | |
view.set('filteredContent', view.get('context.resources').filter(function(resource) { | |
return data.contains(resource.get('id')); | |
})); | |
}); | |
} | |
}.observes('searchResourcesText'), | |
pendingReviewContent: function() { | |
return this.get('context.resources').filter(function(resource) { | |
var states = ['pending_review', 'reviewed']; | |
return states.contains(resource.get('current_state')) && resource.get('reviewer_ids').contains(gon.current_collaborator._id); | |
}); | |
}, | |
reviewedContent: function() { | |
return this.get('context.resources').filter(function(resource) { | |
var states = ['pending_review', 'reviewed']; | |
return states.contains(resource.get('current_state')) && resource.get('has_reviews') === true && !resource.get('reviewer_ids').contains(gon.current_collaborator._id); | |
}); | |
}, | |
approvedContent: function() { | |
return this.get('context.resources').filterProperty('current_state', 'approved'); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment