even more minor fixes

This commit is contained in:
rlx 2011-01-14 14:09:21 +00:00
parent 70bd9e7170
commit bbaa947384
4 changed files with 43 additions and 27 deletions

View file

@ -187,7 +187,7 @@ Positions
response['data']['positions'] = {} response['data']['positions'] = {}
ids = [j['itemId'] for j in qs.values('itemId')] ids = [j['itemId'] for j in qs.values('itemId')]
response['data']['positions'] = _get_positions(ids, query['ids']) response['data']['positions'] = utils.get_positions(ids, query['ids'])
elif 'keys' in query: elif 'keys' in query:
response['data']['items'] = [] response['data']['items'] = []

View file

@ -72,7 +72,7 @@ class List(models.Model):
return True return True
return False return False
def json(self, keys=['id', 'name', 'user', 'type', 'query', 'status'], user=None): def json(self, keys=['id', 'name', 'user', 'type', 'query', 'status', 'subscribed'], user=None):
response = {} response = {}
for key in keys: for key in keys:
if key == 'items': if key == 'items':

View file

@ -10,7 +10,7 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json,
import models import models
from api.actions import actions from api.actions import actions
from item import utils from item import utils
from item.models import Item
def get_list_or_404_json(id): def get_list_or_404_json(id):
username, listname = id.split('.') username, listname = id.split('.')
@ -111,11 +111,11 @@ actions.register(findLists)
@login_required_json @login_required_json
def addListItem(request): def addListItem(request):
''' '''
param data param data {
{list: listId, list: listId,
item: itemId, item: itemId,
query: ... query: ...
} }
return { return {
status: {'code': int, 'text': string}, status: {'code': int, 'text': string},
data: { data: {
@ -125,7 +125,7 @@ def addListItem(request):
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
list = get_list_or_404_json(data['list']) list = get_list_or_404_json(data['list'])
if 'item' in data: if 'item' in data:
item = get_object_or_404_json(models.Item, itemId=data['item']) item = get_object_or_404_json(Item, itemId=data['item'])
if list.editable(request.user): if list.editable(request.user):
list.add(item) list.add(item)
response = json_response(status=200, text='item added') response = json_response(status=200, text='item added')
@ -142,11 +142,11 @@ actions.register(addListItem, cache=False)
@login_required_json @login_required_json
def removeListItem(request): def removeListItem(request):
''' '''
param data param data {
{list: listId, list: listId,
item: itemId, item: itemId,
quert: ... quert: ...
} }
return { return {
status: {'code': int, 'text': string}, status: {'code': int, 'text': string},
data: { data: {
@ -156,7 +156,7 @@ def removeListItem(request):
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
list = get_list_or_404_json(data['list']) list = get_list_or_404_json(data['list'])
if 'item' in data: if 'item' in data:
item = get_object_or_404_json(models.Item, itemId=data['item']) item = get_object_or_404_json(Item, itemId=data['item'])
if list.editable(request.user): if list.editable(request.user):
list.remove(item) list.remove(item)
response = json_response(status=200, text='item removed') response = json_response(status=200, text='item removed')

View file

@ -1601,7 +1601,7 @@ var pandora = new Ox.App({
{ {
id: 'name', id: 'name',
operator: '+', operator: '+',
title: 'Name', title: 'List',
visible: true, visible: true,
width: Math.ceil(columnWidth) width: Math.ceil(columnWidth)
}, },
@ -1614,6 +1614,9 @@ var pandora = new Ox.App({
width: 40 width: 40
}, },
{ {
clickable: function(data) {
return data.type == 'smart';
},
format: function(value) { format: function(value) {
return $('<img>') return $('<img>')
.attr({ .attr({
@ -1678,18 +1681,21 @@ var pandora = new Ox.App({
}) })
.bindEvent({ .bindEvent({
click: function(event, data) { click: function(event, data) {
if (id == 'public') { if (data.key == 'type') {
alert('...');
} else if (data.key == 'subscribed') {
var subscribed = that.value(data.id, 'subscribed'); var subscribed = that.value(data.id, 'subscribed');
pandora.api[subscribed ? 'unsubscribeFromList' : 'subscribeToList']({ pandora.api[subscribed ? 'unsubscribeFromList' : 'subscribeToList']({
id: data.id, id: data.id,
}, function(result) { }, function(result) {
that.value(data.id, 'subscribed', !subscribed); that.value(data.id, 'subscribed', !subscribed);
}); });
} else if (id == 'featured') { } else if (data.key == 'status') {
pandora.api.editList({ pandora.api.editList({
id: data.id, id: data.id,
status: that.value(data.id, 'status') == 'featured' ? 'public' : 'featured' status: that.value(data.id, 'status') == 'featured' ? 'public' : 'featured'
}, function(result) { }, function(result) {
Ox.print('result', result)
if (result.data.user == app.user.username || result.data.subscribed) { if (result.data.user == app.user.username || result.data.subscribed) {
Ox.Request.emptyCache(); // fixme: remove Ox.Request.emptyCache(); // fixme: remove
app.$ui.sectionList[ app.$ui.sectionList[
@ -2388,7 +2394,7 @@ var pandora = new Ox.App({
clickable: function(data) { clickable: function(data) {
//alert(JSON.stringify([data.user, data.type])) //alert(JSON.stringify([data.user, data.type]))
//Ox.print('$$$$$$$$', data.user, data.type) //Ox.print('$$$$$$$$', data.user, data.type)
return data.user == app.user.username && data.type == 'smart'; return data.type == 'smart';
}, },
format: function(value) { format: function(value) {
return $('<img>') return $('<img>')
@ -2579,14 +2585,14 @@ var pandora = new Ox.App({
}, },
sections: function() { sections: function() {
var that = new Ox.Element() var that = new Ox.Element()
.css({overflowY: 'auto'}) .css({overflowX: 'hidden', overflowY: 'auto'})
.bindEvent({ .bindEvent({
resize: function(event, data) { resize: function(event, data) {
resizeSections(); resizeSections();
} }
}); });
var counter = 0; var counter = 0;
var $sections = []; //var $sections = [];
app.$ui.section = []; app.$ui.section = [];
app.$ui.sectionList = []; app.$ui.sectionList = [];
$.each(app.user.ui.sections, function(i, id) { $.each(app.user.ui.sections, function(i, id) {
@ -2648,6 +2654,7 @@ var pandora = new Ox.App({
} else { } else {
app.$ui.publicListsBrowser.replaceWith(app.$ui.sectionList[1] = ui.sectionList('public')); app.$ui.publicListsBrowser.replaceWith(app.$ui.sectionList[1] = ui.sectionList('public'));
} }
resizeSections();
} }
})]; })];
} else if (id == 'featured' && app.user.group == 'admin') { } else if (id == 'featured' && app.user.group == 'admin') {
@ -2667,6 +2674,7 @@ var pandora = new Ox.App({
} else { } else {
app.$ui.featuredListsBrowser.replaceWith(app.$ui.sectionList[2] = ui.sectionList('featured')); app.$ui.featuredListsBrowser.replaceWith(app.$ui.sectionList[2] = ui.sectionList('featured'));
} }
resizeSections();
} }
})]; })];
} }
@ -2708,14 +2716,14 @@ var pandora = new Ox.App({
resizeSections(); resizeSections();
} }
}); });
$sections.push(app.$ui.section[i]); //$sections.push(app.$ui.section[i]);
app.$ui.sectionList[i] = ui.sectionList(id) app.$ui.sectionList[i] = ui.sectionList(id)
.bindEvent({init: init}) .bindEvent({init: init})
.appendTo(app.$ui.section[i].$content); .appendTo(app.$ui.section[i].$content);
function init(event, data) { function init(event, data) {
Ox.print('init', i, counter) Ox.print('init', i, counter)
if (++counter == 3) { if (++counter == 3) {
$.each($sections, function(i, $section) { $.each(app.$ui.section, function(i, $section) {
that.append($section); that.append($section);
}); });
resizeSections(); resizeSections();
@ -2943,17 +2951,20 @@ var pandora = new Ox.App({
height += show * 40; height += show * 40;
} }
}); });
Ox.print('getSectionsHeight', height)
return height; return height;
} }
function getSectionsWidth() { function getSectionsWidth() {
var width = app.user.ui.sidebarSize; var width = app.user.ui.sidebarSize;
// fixme: don't use height(), look up in splitpanels // fixme: don't use height(), look up in splitpanels
Ox.print('>', app.$ui.leftPanel.height() - 24 - 1 - app.$ui.info.height()) //var a = getSectionsHeight(), b = app.$ui.leftPanel.height() - 24 - 1 - app.$ui.info.height()
Ox.print(getSectionsHeight(), '>', app.$ui.leftPanel.height() - 24 - 1 - app.$ui.info.height())
//Ox.print(a, '>', b);
if (getSectionsHeight() > app.$ui.leftPanel.height() - 24 - 1 - app.$ui.info.height()) { if (getSectionsHeight() > app.$ui.leftPanel.height() - 24 - 1 - app.$ui.info.height()) {
//if (a > b) {
width -= app.ui.scrollbarSize; width -= app.ui.scrollbarSize;
} }
Ox.print('width', width)
return width; return width;
} }
@ -3006,16 +3017,21 @@ var pandora = new Ox.App({
var width = getSectionsWidth(); var width = getSectionsWidth();
Ox.print('sectionsWidth', width) Ox.print('sectionsWidth', width)
app.$ui.sectionList.forEach(function($list, i) { app.$ui.sectionList.forEach(function($list, i) {
var id = i == 1 ? 'id' : 'name'; var id = ['my', 'public', 'featured'][i], // fixme: find a better way
height;
app.$ui.section[i].css({width: width + 'px'});
$list.css({width: width + 'px'}); $list.css({width: width + 'px'});
if ( if (
i == 1 && app.ui.showPublicListsBrowser || (i == 1 && app.ui.showPublicListsBrowser) ||
i == 2 && app.ui.showFeaturedListsBrowser (i == 2 && app.ui.showFeaturedListsBrowser)
) { ) {
$list.resizeColumn('user', Math.floor((width - 88) / 2)) $list.resizeColumn('user', Math.floor((width - 88) / 2))
.resizeColumn('name', Math.floor((width - 88) / 2)); .resizeColumn('name', Math.floor((width - 88) / 2));
} else { } else {
$list.resizeColumn(id, width - 88); $list.resizeColumn(i == 1 ? 'id' : 'name', width - 88);
}
if (!app.user.ui.showSection[id]) {
//app.$ui.section[i].update();
} }
}); });
} }