some more improvements to lists

This commit is contained in:
rolux 2011-01-13 01:58:11 +00:00
parent 74bbe1a266
commit b99931b3ab
2 changed files with 94 additions and 23 deletions

View file

@ -32,6 +32,7 @@ def _parse_query(data, user):
query['range'] = [0, 100] query['range'] = [0, 100]
#query['sort'] = [{'key':'user', 'operator':'+'}, {'key':'name', 'operator':'+'}] #query['sort'] = [{'key':'user', 'operator':'+'}, {'key':'name', 'operator':'+'}]
query['sort'] = [{'key':'position__position', 'operator':'+'}] query['sort'] = [{'key':'position__position', 'operator':'+'}]
query['sort'] = [{'key':'name', 'operator':'+'}]
for key in ('keys', 'group', 'list', 'range', 'ids'): for key in ('keys', 'group', 'list', 'range', 'ids'):
if key in data: if key in data:
query[key] = data[key] query[key] = data[key]
@ -76,7 +77,11 @@ def findLists(request):
query = _parse_query(data, request.user) query = _parse_query(data, request.user)
#order #order
qs = _order_query(query['qs'], query['sort']) #FIXME: having to use distinct here seams wrong
qs = _order_query(query['qs'].distinct(), query['sort'])
#qs = query['qs'].distinct().order_by('position__position')
#qs = query['qs']
#range #range
response = json_response() response = json_response()
if 'keys' in data: if 'keys' in data:
@ -186,10 +191,12 @@ actions.register(addList)
def editList(request): def editList(request):
''' '''
param data { param data {
key: value id: listId,
position: int key: value,
} }
keys: name, public, query, featured (if admin) keys: name, status, query, position
if you change status you have to provide position of list
return { return {
status: {'code': int, 'text': string}, status: {'code': int, 'text': string},
data: { data: {
@ -210,6 +217,13 @@ def editList(request):
if value not in list._status: if value not in list._status:
value = list._status[0] value = list._status[0]
setattr(list, key, value) setattr(list, key, value)
elif key == 'name':
name = data['name']
num = 1
while models.List.objects.filter(name=name, user=list.user).exclude(id=list.id).count()>0:
num += 1
name = data['name'] + ' (%d)' % num
setattr(list, key, name)
else: else:
setattr(list, key, data[key]) setattr(list, key, data[key])
@ -221,6 +235,7 @@ def editList(request):
pos.section = 'my' pos.section = 'my'
pos.save() pos.save()
list.save() list.save()
response['data'] = list.json(user=request.user)
else: else:
response = json_response(status=403, text='not allowed') response = json_response(status=403, text='not allowed')
return render_to_json_response(response) return render_to_json_response(response)

View file

@ -2110,9 +2110,9 @@ var pandora = new Ox.App({
if (id == 'my') { if (id == 'my') {
menu = [ menu = [
{ id: 'new', title: 'New List...' }, { id: 'new', title: 'New List...' },
{ id: 'newfromselection', title: 'New List from Selection...' }, { id: 'newfromselection', title: 'New List from Current Selection...', disabled: true },
{ id: 'newsmart', title: 'New Smart List...' }, { id: 'newsmart', title: 'New Smart List...' },
{ id: 'newfromresults', title: 'New Smart List from Results...' }, { id: 'newfromresults', title: 'New Smart List from Current Results...', disabled: true },
{}, {},
{ id: 'addselection', title: 'Add Selection to List...' } { id: 'addselection', title: 'Add Selection to List...' }
]; ];
@ -2132,19 +2132,26 @@ var pandora = new Ox.App({
columns: [ columns: [
{ {
id: 'id', id: 'id',
visible: false, format: function(value) {
unique: true return value.split('.').join(': ');
}, },
{ operator: '+',
id: 'position', unique: true,
visible: false, visible: id == 'public',
width: 184
}, },
{ {
align: 'left', align: 'left',
editable: id == 'my', editable: id == 'my' ? true : (id == 'featured' ? function(data) {
Ox.print('########', data, app.user.username)
return data.id && data.id.split(': ')[0] == app.user.username;
} : false),
id: 'name', id: 'name',
input: {
autovalidate: autovalidateListname
},
operator: '+', operator: '+',
visible: true, visible: id != 'public',
width: 184 width: 184
}, },
{ {
@ -2169,6 +2176,7 @@ var pandora = new Ox.App({
}, },
{ {
align: 'left', align: 'left',
clickable: id == 'my',
format: function(value) { format: function(value) {
var symbols = {private: 'None', public: 'Publish', featured: 'Star'}; var symbols = {private: 'None', public: 'Publish', featured: 'Star'};
return $('<img>').attr({ return $('<img>').attr({
@ -2184,6 +2192,7 @@ var pandora = new Ox.App({
], ],
max: 1, max: 1,
min: 0, min: 0,
pageLength: 1000,
request: function(data, callback) { request: function(data, callback) {
var query; var query;
if (id == 'my') { if (id == 'my') {
@ -2216,6 +2225,19 @@ var pandora = new Ox.App({
} }
}) })
.bindEvent({ .bindEvent({
click: function(event, data) {
var list = app.$ui.sectionLists[i];
if (data.key == 'query') {
} else if (data.key == 'status') {
pandora.api.editList({
id: data.id,
status: list.value(data.id, data.key) == 'private' ? 'public' : 'private'
}, function(result) {
list.value(result.data.id, 'status', result.data.status);
});
}
},
load: function(event, data) { load: function(event, data) {
$section.$content.css({ $section.$content.css({
height: data.items * 16 + 'px' height: data.items * 16 + 'px'
@ -2224,21 +2246,37 @@ var pandora = new Ox.App({
height: data.items * 16 + 'px' height: data.items * 16 + 'px'
}); });
}, },
select: function(event, data) { move: function(event, data) {
app.$ui.sectionLists.forEach(function($list, i_) {
i != i_ && $list.options('selected', []);
});
},
sort: function(event, data) {
/* /*
data.ids.forEach(function(id, pos) { data.ids.forEach(function(id, pos) {
app.user.ui.lists[id].position = pos; app.user.ui.lists[id].position = pos;
}); });
*/ */
// fixme: only one of the below
// (and then Ox.List can send less event data)
pandora.api.editList({
id: data.id,
position: data.position
});
/*
pandora.api.sortLists({ pandora.api.sortLists({
section: id, section: id,
ids: data.ids ids: data.ids
}); });
*/
},
select: function(event, data) {
app.$ui.sectionLists.forEach(function($list, i_) {
i != i_ && $list.options('selected', []);
});
},
submit: function(event, data) {
data_ = {id: data.id};
data_[data.key] = data.value;
pandora.api.editList(data_, function(result) {
app.$ui.sectionLists[i].value(data.id, 'name', result.data.name);
app.$ui.sectionLists[i].value(data.id, 'id', result.data.id);
});
} }
}) })
.appendTo($section.$content); .appendTo($section.$content);
@ -2407,6 +2445,24 @@ var pandora = new Ox.App({
callback(value); callback(value);
} }
function autovalidateListname(value, blur, callback) {
var length = value.length;
value = $.map(value.split(''), function(v, i) {
if (new RegExp('[0-9a-z\\(\\)' + ((i == 0 || (i == length - 1 && blur)) ? '' : ' \-') + ']', 'i')(v)) {
return v
} else {
return null;
}
}).join('');
$.each([' ', ' -', '- ', '--', '\\(\\(', '\\)\\(', '\\)\\)'], function(i, v) {
Ox.print(v, v[0], v[0] == '\\')
while (value.indexOf(v) > -1) {
value = value.replace(new RegExp(v, 'g'), v[0] + (v[0] == '\\' ? v[1] : ''));
}
})
callback(value);
}
function autovalidateUsername(value, blur, callback) { function autovalidateUsername(value, blur, callback) {
var length = value.length; var length = value.length;
value = $.map(value.toLowerCase().split(''), function(v, i) { value = $.map(value.toLowerCase().split(''), function(v, i) {