fix select all

This commit is contained in:
rolux 2011-12-19 17:20:06 +00:00
parent 92239d2bc2
commit 80f90420db
3 changed files with 30 additions and 10 deletions

View file

@ -75,8 +75,11 @@ class List(models.Model):
l.item = item l.item = item
l.save() l.save()
def remove(self, item): def remove(self, item=None, items=None):
if item:
ListItem.objects.all().filter(item=item, list=self).delete() ListItem.objects.all().filter(item=item, list=self).delete()
if items:
ListItem.objects.all().filter(item__itemId__in=items, list=self).delete()
def __unicode__(self): def __unicode__(self):
return self.get_id() return self.get_id()

View file

@ -4,6 +4,7 @@ from __future__ import division
import os import os
from django.db.models import Max, Sum from django.db.models import Max, Sum
from django.db import transaction
from django.http import HttpResponseForbidden, Http404 from django.http import HttpResponseForbidden, Http404
from django.conf import settings from django.conf import settings
from ox.utils import json from ox.utils import json
@ -139,6 +140,7 @@ def addListItems(request):
list = get_list_or_404_json(data['list']) list = get_list_or_404_json(data['list'])
if 'items' in data: if 'items' in data:
if list.editable(request.user): if list.editable(request.user):
with transaction.commit_on_success():
for item in Item.objects.filter(itemId__in=data['items']): for item in Item.objects.filter(itemId__in=data['items']):
list.add(item) list.add(item)
response = json_response(status=200, text='items added') response = json_response(status=200, text='items added')
@ -170,8 +172,7 @@ def removeListItems(request):
list = get_list_or_404_json(data['list']) list = get_list_or_404_json(data['list'])
if 'items' in data: if 'items' in data:
if list.editable(request.user): if list.editable(request.user):
for item in list.items.filter(itemId__in=data['items']): list.remove(items=data['items'])
list.remove(item)
response = json_response(status=200, text='items removed') response = json_response(status=200, text='items removed')
else: else:
response = json_response(status=403, text='not allowed') response = json_response(status=403, text='not allowed')

View file

@ -497,7 +497,7 @@ pandora.ui.list = function() {
}, pandora.reloadList); }, pandora.reloadList);
}, },
select: function(data) { select: function(data) {
var $still, $timeline; var query;
pandora.UI.set('listSelection', data.ids); pandora.UI.set('listSelection', data.ids);
if (data.ids.length) { if (data.ids.length) {
pandora.$ui.mainMenu.enableItem('copy'); pandora.$ui.mainMenu.enableItem('copy');
@ -507,8 +507,8 @@ pandora.ui.list = function() {
pandora.$ui.mainMenu.disableItem('openmovie'); pandora.$ui.mainMenu.disableItem('openmovie');
} }
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info()); pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info());
pandora.api.find({ if (Ox.isUndefined(data.rest)) {
query: { query = {
conditions: data.ids.map(function(id) { conditions: data.ids.map(function(id) {
return { return {
key: 'id', key: 'id',
@ -517,7 +517,23 @@ pandora.ui.list = function() {
} }
}), }),
operator: '|' operator: '|'
};
} else {
query = {
conditions: Ox.merge([
pandora.user.ui.find
], data.rest.map(function(id) {
return {
key: 'id',
value: id,
operator: '!='
};
})),
operator: '&'
};
} }
pandora.api.find({
query: query
}, function(result) { }, function(result) {
pandora.$ui.selected.html(pandora.ui.status('selected', result.data)); pandora.$ui.selected.html(pandora.ui.status('selected', result.data));
}); });