From 9044cdf9c2cb1f9b90d8f338323360be20f6a2ff Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 15 Jan 2011 23:26:39 +0000 Subject: [PATCH] make more ui settings sticky --- pandora/templates/site.json | 11 +---- pandora/user/views.py | 18 +++++++ static/js/pandora.js | 96 ++++++++++++++++++++++++++++++++----- 3 files changed, 102 insertions(+), 23 deletions(-) diff --git a/pandora/templates/site.json b/pandora/templates/site.json index ccea120..6df4c31 100644 --- a/pandora/templates/site.json +++ b/pandora/templates/site.json @@ -124,16 +124,6 @@ {"id": "size", "admin": true}, {"id": "pixels"} ], - "uiDefaults": { - "list": { - "columns": ["id", "title", "director", "country", "year", "language", "runtime", "genre"], - "listView": "icons", - "selected": [], - "sort": [ - {"key": "director", "operator": ""} - ] - } - }, "user": { "group": "guest", "lists": { @@ -169,6 +159,7 @@ "lists": { "": { "columns": ["id", "title", "director", "country", "year", "language", "runtime", "genre"], + "columnWidth": {}, "listView": "icons", "selected": [], "sort": [ diff --git a/pandora/user/views.py b/pandora/user/views.py index 6018d7d..86fa889 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -402,6 +402,24 @@ def setPreferences(request): actions.register(setPreferences, cache=False) +@login_required_json +def resetUI(request): + ''' + reset user ui settings to defaults + param data { + } + + return { + 'status': {'code': int, 'text': string} + } + ''' + profile = request.user.get_profile() + profile.ui = {} + profile.save() + response = json_response() + return render_to_json_response(response) +actions.register(resetUI, cache=False) + @login_required_json def setUI(request): ''' diff --git a/static/js/pandora.js b/static/js/pandora.js index cb3e627..dab60fc 100755 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -33,7 +33,7 @@ var pandora = new Ox.App({ pandora.app = app; // remove later if (app.user.group == 'guest') { - app.user = data.config.user; + app.user = $.extend({}, app.config.user); $.browser.safari && Ox.theme('modern'); } @@ -1138,18 +1138,31 @@ var pandora = new Ox.App({ return that; }, list: function(view) { // fixme: remove view argument - var that, $map, - keys = ['director', 'id', 'poster', 'title', 'year']; + var that, $map; //Ox.print('constructList', view); if (view == 'list') { + /* + keys = Ox.unique($.merge( + $.map(app.user.ui.lists[app.user.ui.list].columns, function(id) { + return Ox.getObjectById(app.config.sortKeys, id); + }), + app.config.sortKeys + )); + Ox.print('$$$$', keys) + */ that = new Ox.TextList({ columns: $.map(app.config.sortKeys, function(key, i) { - return $.extend({ + var position = app.user.ui.lists[app.user.ui.list].columns.indexOf(key.id); + Ox.print(position, '++++', key.id, app.user.ui.lists[app.user.ui.list].columnWidth[key.id], key.width, '||:', app.user.ui.lists[app.user.ui.list].columnWidth[key.id] || key.width) + return $.extend($.extend({}, key), { align: getAlignment(key.id), + defaultWidth: key.width, operator: getSortOperator(key.id), + position: position, unique: key.id == 'id', - visible: $.inArray(key.id, app.user.ui.lists[app.user.ui.list].columns) > -1 - }, key); + visible: position > -1, + width: app.user.ui.lists[app.user.ui.list].columnWidth[key.id] || key.width + }); }), columnsMovable: true, columnsRemovable: true, @@ -1166,8 +1179,26 @@ var pandora = new Ox.App({ sort: app.user.ui.lists[app.user.ui.list].sort }) .bindEvent({ - resize: function(event, data) { + columnchange: function(event, data) { + var columnWidth = {} + UI.set(['lists', app.user.ui.list, 'columns'].join('|'), data.ids); + /* + data.ids.forEach(function(id) { + columnWidth[id] = + app.user.ui.lists[app.user.ui.list].columnWidth[id] || + Ox.getObjectById(app.config.sortKeys, id).width + }); + UI.set(['lists', app.user.ui.list, 'columnWidth'].join('|'), columnWidth); + */ + }, + columnresize: function(event, data) { + UI.set(['lists', app.user.ui.list, 'columnWidth', data.id].join('|'), data.width); + }, + resize: function(event, data) { // this is the resize event of the split panel that.size(); + }, + sort: function(event, data) { + UI.set(['lists', app.user.ui.list, 'sort'].join('|'), [data]); } }); } else if (view == 'icons') { @@ -1185,7 +1216,7 @@ var pandora = new Ox.App({ width: ratio >= 1 ? size : size * ratio }; }, - keys: keys, + keys: ['director', 'id', 'poster', 'title', 'year'], request: function(data, callback) { //Ox.print('data, Query.toObject', data, Query.toObject()) pandora.api.find($.extend(data, { @@ -1745,6 +1776,7 @@ var pandora = new Ox.App({ UI.set({list: data.ids[0]}); URL.set('?find=list:' + data.ids[0]); } else { + UI.set({list: ''}); URL.set(''); } } @@ -1755,6 +1787,7 @@ var pandora = new Ox.App({ var isGuest = app.user.group == 'guest', that = new Ox.MainMenu({ extras: [ + $('