forked from 0x2620/pandora
some more improvements to lists
This commit is contained in:
parent
74bbe1a266
commit
b99931b3ab
2 changed files with 94 additions and 23 deletions
|
@ -32,6 +32,7 @@ def _parse_query(data, user):
|
|||
query['range'] = [0, 100]
|
||||
#query['sort'] = [{'key':'user', 'operator':'+'}, {'key':'name', 'operator':'+'}]
|
||||
query['sort'] = [{'key':'position__position', 'operator':'+'}]
|
||||
query['sort'] = [{'key':'name', 'operator':'+'}]
|
||||
for key in ('keys', 'group', 'list', 'range', 'ids'):
|
||||
if key in data:
|
||||
query[key] = data[key]
|
||||
|
@ -76,7 +77,11 @@ def findLists(request):
|
|||
query = _parse_query(data, request.user)
|
||||
|
||||
#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
|
||||
response = json_response()
|
||||
if 'keys' in data:
|
||||
|
@ -186,10 +191,12 @@ actions.register(addList)
|
|||
def editList(request):
|
||||
'''
|
||||
param data {
|
||||
key: value
|
||||
position: int
|
||||
id: listId,
|
||||
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 {
|
||||
status: {'code': int, 'text': string},
|
||||
data: {
|
||||
|
@ -210,6 +217,13 @@ def editList(request):
|
|||
if value not in list._status:
|
||||
value = list._status[0]
|
||||
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:
|
||||
setattr(list, key, data[key])
|
||||
|
||||
|
@ -221,6 +235,7 @@ def editList(request):
|
|||
pos.section = 'my'
|
||||
pos.save()
|
||||
list.save()
|
||||
response['data'] = list.json(user=request.user)
|
||||
else:
|
||||
response = json_response(status=403, text='not allowed')
|
||||
return render_to_json_response(response)
|
||||
|
|
|
@ -2110,9 +2110,9 @@ var pandora = new Ox.App({
|
|||
if (id == 'my') {
|
||||
menu = [
|
||||
{ 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: '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...' }
|
||||
];
|
||||
|
@ -2132,19 +2132,26 @@ var pandora = new Ox.App({
|
|||
columns: [
|
||||
{
|
||||
id: 'id',
|
||||
visible: false,
|
||||
unique: true
|
||||
format: function(value) {
|
||||
return value.split('.').join(': ');
|
||||
},
|
||||
{
|
||||
id: 'position',
|
||||
visible: false,
|
||||
operator: '+',
|
||||
unique: true,
|
||||
visible: id == 'public',
|
||||
width: 184
|
||||
},
|
||||
{
|
||||
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',
|
||||
input: {
|
||||
autovalidate: autovalidateListname
|
||||
},
|
||||
operator: '+',
|
||||
visible: true,
|
||||
visible: id != 'public',
|
||||
width: 184
|
||||
},
|
||||
{
|
||||
|
@ -2169,6 +2176,7 @@ var pandora = new Ox.App({
|
|||
},
|
||||
{
|
||||
align: 'left',
|
||||
clickable: id == 'my',
|
||||
format: function(value) {
|
||||
var symbols = {private: 'None', public: 'Publish', featured: 'Star'};
|
||||
return $('<img>').attr({
|
||||
|
@ -2184,6 +2192,7 @@ var pandora = new Ox.App({
|
|||
],
|
||||
max: 1,
|
||||
min: 0,
|
||||
pageLength: 1000,
|
||||
request: function(data, callback) {
|
||||
var query;
|
||||
if (id == 'my') {
|
||||
|
@ -2216,6 +2225,19 @@ var pandora = new Ox.App({
|
|||
}
|
||||
})
|
||||
.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) {
|
||||
$section.$content.css({
|
||||
height: data.items * 16 + 'px'
|
||||
|
@ -2224,21 +2246,37 @@ var pandora = new Ox.App({
|
|||
height: data.items * 16 + 'px'
|
||||
});
|
||||
},
|
||||
select: function(event, data) {
|
||||
app.$ui.sectionLists.forEach(function($list, i_) {
|
||||
i != i_ && $list.options('selected', []);
|
||||
});
|
||||
},
|
||||
sort: function(event, data) {
|
||||
move: function(event, data) {
|
||||
/*
|
||||
data.ids.forEach(function(id, 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({
|
||||
section: id,
|
||||
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);
|
||||
|
@ -2407,6 +2445,24 @@ var pandora = new Ox.App({
|
|||
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) {
|
||||
var length = value.length;
|
||||
value = $.map(value.toLowerCase().split(''), function(v, i) {
|
||||
|
|
Loading…
Reference in a new issue