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: [ + $('
').html('beta').css({marginRight: '4px'}), app.$ui.loadingIcon = new Ox.LoadingIcon({ size: 'medium' }) @@ -1904,7 +1937,8 @@ var pandora = new Ox.App({ { id: 'help', title: app.config.site.name + ' Help', keyboard: 'shift ?' } ] }, { id: 'debugMenu', title: 'Debug', items: [ - { id: 'query', title: 'Show Query' } + { id: 'query', title: 'Show Query' }, + { id: 'resetui', title: 'Reset UI Settings'} ] }, { id: 'testMenu', title: 'Test', items: [ { group: 'foogroup', items: [ @@ -2254,7 +2288,31 @@ var pandora = new Ox.App({ overflow: 'hidden' }).append($manage).open(); } else if (data.id == 'query') { - alert(JSON.stringify(Query.toObject())); + var $dialog = new Ox.Dialog({ + buttons: [ + new Ox.Button({ + id: 'close', + title: 'Close' + }).bindEvent({ + click: function() { + $dialog.close(); + } + }) + ], + content: new Ox.Element() + .html([ + 'Query: ' + JSON.stringify(Query.toObject()), + 'findQuery: ' + JSON.stringify(app.user.ui.findQuery), + 'listQuery: ' + JSON.stringify(app.user.ui.listQuery) + ].join('

')), + height: 200, + keys: {enter: 'close', escape: 'close'}, + width: 400 + }).open(); + } else if (data.id == 'resetui') { + pandora.api.resetUI({}, function() { + app.$ui.appPanel.reload(); + }); } } }); @@ -2652,7 +2710,7 @@ var pandora = new Ox.App({ type: data.id == 'new' ? 'static' : 'smart' }, function(result) { id = result.data.id; - UI.set(['lists', id].join('|'), app.config.uiDefaults.list); + UI.set(['lists', id].join('|'), app.config.user.ui.lists['']); URL.set('?find=list:' + id) Ox.Request.emptyCache(); // fixme: remove $list.reloadList().bindEvent({load: load}); @@ -3215,10 +3273,21 @@ var pandora = new Ox.App({ return { fromString: function(str) { - var query = Ox.unserialize(str.substr(1)), + var list = '', + query = Ox.unserialize(str.substr(1)), sort = []; if ('find' in query) { + app.user.ui.listQuery = {conditions: [], operator: ''}; // fixme: hackish app.user.ui.findQuery = parseFind(query.find); + if (app.user.ui.listsQuery) { + list = app.user.ui.listsQuery.conditions[0].value; + UI.set({ + list: list + }); + !app.user.ui.lists[list] && UI.set( + 'lists.' + list, app.config.user.ui.list + ); + } //Ox.print('user.ui.findQuery', app.user.ui.findQuery) } if ('sort' in query) { @@ -3340,7 +3409,7 @@ var pandora = new Ox.App({ }); UI.set(['lists', app.user.ui.list, 'listView'].join('|'), url); }, - '^[0-9A-Z]': function() { + '^[0-9A-Z]': function(url) { var split = url.split('/'), item = split[0], view = new RegExp( @@ -3380,6 +3449,7 @@ var pandora = new Ox.App({ //Ox.print(url, 're', re) re = new RegExp(re); if (re(url)) { + Ox.print('URL re ' + re) fn(url); return false; }