From c1b9c196d5e36f4f77c238963be6be32d1f6ba45 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sun, 23 Jan 2011 04:58:40 +0000 Subject: [PATCH] use app.config.itemKeys, add Ox.Filter --- pandora/0xdb.json | 65 +++++++++++++--------- pandora/api/views.py | 12 ++-- static/js/pandora.js | 128 ++++++++++++++++++++++++------------------- 3 files changed, 117 insertions(+), 88 deletions(-) diff --git a/pandora/0xdb.json b/pandora/0xdb.json index ec87d17..44b99a9 100644 --- a/pandora/0xdb.json +++ b/pandora/0xdb.json @@ -52,7 +52,7 @@ "title": "Country", "type": ["string"], "find": {"autocomplete": true}, - "sort": {"type": "string", "width": 180}, + "sort": {"type": "string", "width": 120}, "group": true }, { @@ -60,7 +60,7 @@ "title": "Year", "type": "year", "find": {"autocomplete": true}, - "sort": {"type": "year", "width": 180}, + "sort": {"type": "year", "width": 60}, "group": true }, { @@ -68,9 +68,16 @@ "title": "Language", "type": ["string"], "find": {"autocomplete": true}, - "sort": {"type": "string", "width": 180}, + "sort": {"type": "string", "width": 120}, "group": true }, + { + "id": "runtime", + "title": "Runtime", + "type": "integer", + "sort": {"type": "integer", "width": 60}, + "format": {"type": "duration", "args": [0, "medium"]} + }, { "id": "writer", "title": "Writer", @@ -80,8 +87,7 @@ "group": true }, { - "id": - "producer", + "id": "producer", "type": ["string"], "title": "Producer", "find": {"autocomplete": true}, @@ -111,6 +117,13 @@ "find": {"autocomplete": true}, "group": true }, + { + "id": "numberofactors", + "title": "Number of Actors", + "sort": {"type": "integer", "width": 60}, + "value": {"key": "actor", "type": "length"}, + "type": "integer" + }, { "id": "character", "title": "Character", @@ -123,19 +136,12 @@ "type": ["string"], "find": {"autocomplete": true} }, - { - "id": "numberofactors", - "title": "Number of Actors", - "sort": {"type": "integer", "width": 60}, - "value": {"key": "actor", "type": "length"}, - "type": "integer" - }, { "id": "genre", "title": "Genre", "type": ["string"], "find": {"autocomplete": true}, - "sort": {"type": "string", "width": 180}, + "sort": {"type": "string", "width": 120}, "group": true }, { @@ -152,13 +158,6 @@ "sort": {"type": "integer", "width": 60}, "value": {"key": "keyword", "type": "length"} }, - { - "id": "runtime", - "title": "Runtime", - "type": "integer", - "sort": {"type": "integer", "width": 60}, - "format": {"type": "duration", "args": [0, "medium"]} - }, { "id": "summary", "title": "Summary", @@ -166,13 +165,6 @@ "group": false, "find": {} }, - { - "id": "dialog", - "title": "Dialog", - "type": "text", - "group": false, - "find": {} - }, { "id": "wordsinsummary", "title": "Words in Summary", @@ -235,6 +227,13 @@ "sort": {"type": "string", "width": 90}, "type": "string" }, + { + "id": "dialog", + "title": "Dialog", + "type": "text", + "group": false, + "find": {} + }, { "id": "aspectratio", "title": "Aspect Ratio", @@ -351,6 +350,18 @@ "sort": {"type": "date", "width": 90}, "type": "date" }, + { + "id": "accessed", + "title": "Date Accessed", + "sort": {"type": "date", "width": 90}, + "type": "date" + }, + { + "id": "viewed", + "title": "Date Viewed", + "sort": {"type": "date", "width": 90}, + "type": "date" + }, { "id": "popularity", "title": "Popularity", diff --git a/pandora/api/views.py b/pandora/api/views.py index 55d7e4b..9cefb76 100644 --- a/pandora/api/views.py +++ b/pandora/api/views.py @@ -52,18 +52,18 @@ def init(request): ''' #data = json.loads(request.POST['data']) response = json_response({}) - if request.user.is_authenticated(): - response['data']['user'] = get_user_json(request.user) - else: - response['data']['user'] = {'name': 'Guest', - 'group': 'guest', - 'preferences': {}} with open(settings.SITE_CONFIG) as f: response['data']['config'] = json.load(f) response['data']['config']['site']['id'] = settings.SITEID response['data']['config']['site']['name'] = settings.SITENAME response['data']['config']['site']['sectionName'] = settings.SITENAME response['data']['config']['site']['url'] = settings.URL + + if request.user.is_authenticated(): + response['data']['user'] = get_user_json(request.user) + else: + response['data']['user'] = response['data']['config']['user'] + return render_to_json_response(response) actions.register(init) diff --git a/static/js/pandora.js b/static/js/pandora.js index acb5bd1..f206fb5 100755 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -4,7 +4,6 @@ var pandora = new Ox.App({ apiURL: '/api/', - config: '/site.json', init: 'init', }).launch(function(data) { @@ -14,11 +13,22 @@ var pandora = new Ox.App({ $ui: { body: $('body'), document: $(document), - window: $(window).resize(resizeWindow) + window: $(window) + .resize(resizeWindow) + .unload(unloadWindow) }, config: data.config, requests: {}, ui: { + findKeys: $.map(data.config.itemKeys, function(key, i) { + return 'find' in key ? $.extend({ + id: key.id, + title: key.title + }, key.find) : null; + }), + infoRatio: 16 / 9, + scrollbarSize: $.browser.mozilla ? 16 : 12, + sectionElement: 'buttons', sectionFolders: { site: $.merge([ {id: 'site', title: 'Site', items: $.merge([ @@ -43,10 +53,13 @@ var pandora = new Ox.App({ {id: 'featured', title: 'Featured Lists', showBrowser: false} ], }, - infoRatio: 16 / 9, - scrollbarSize: $.browser.mozilla ? 16 : 12, - sectionElement: 'buttons', - selectedMovies: [] + selectedMovies: [], + sortKeys: $.map(data.config.itemKeys, function(key, i) { + return 'sort' in key ? $.extend({ + id: key.id, + title: key.title + }, key.sort) : null; + }) }, user: data.user }; @@ -675,7 +688,7 @@ var pandora = new Ox.App({ ] : [], [ app.$ui.findSelect = new Ox.Select({ id: 'select', - items: $.map(app.config.findKeys, function(key, i) { + items: $.map(app.ui.findKeys, function(key, i) { return { id: key.id, checked: key.id == findKey, @@ -740,7 +753,7 @@ var pandora = new Ox.App({ return app.user.ui.findQuery.conditions.length ? function(value, callback) { var elementValue = that.value(), key = elementValue[app.user.ui.list ? 1 : 0].id, - findKey = Ox.getObjectById(app.config.findKeys, key); + findKey = Ox.getObjectById(app.ui.findKeys, key); Ox.print('!!!!', key, findKey, 'autocomplete' in findKey && findKey.autocomplete) value === '' && Ox.print('Warning: autocomplete function should never be called with empty value'); if ('autocomplete' in findKey && findKey.autocomplete) { @@ -1141,11 +1154,15 @@ var pandora = new Ox.App({ $dialog.close(); }) ], - content: new Ox.Element('div').html('...'), + content: new Ox.Filter({ + keys: $.map(app.config.sortKeys, function(key) { + return {id: key.id, title: key.title, type: 'string'} + }) + }), height: 200, keys: {enter: 'save', escape: 'cancel'}, title: 'Advanced Find', - width: 640 + width: 616 + app.ui.scrollbarSize }).open(); } else if (data.key == 'status') { pandora.api.editList({ @@ -1850,7 +1867,7 @@ var pandora = new Ox.App({ Ox.print('$$$$', keys) */ that = new Ox.TextList({ - columns: $.map(app.config.sortKeys, function(key, i) { + columns: $.map(app.ui.sortKeys, function(key, i) { 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), { @@ -1885,7 +1902,7 @@ var pandora = new Ox.App({ data.ids.forEach(function(id) { columnWidth[id] = app.user.ui.lists[app.user.ui.list].columnWidth[id] || - Ox.getObjectById(app.config.sortKeys, id).width + Ox.getObjectById(app.ui.sortKeys, id).width }); UI.set(['lists', app.user.ui.list, 'columnWidth'].join('|'), columnWidth); */ @@ -1910,7 +1927,7 @@ var pandora = new Ox.App({ height: ratio <= 1 ? size : size / ratio, id: data['id'], info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key], - title: data.title + (data.director ? ' (' + data.director + ')' : ''), + title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''), url: data.poster.url.replace(/jpg/, size + '.jpg'), width: ratio >= 1 ? size : size * ratio }; @@ -2403,7 +2420,7 @@ var pandora = new Ox.App({ ]}, { id: 'sortMenu', title: 'Sort', items: [ { id: 'sortmovies', title: 'Sort Movies by', items: [ - { group: 'sortmovies', min: 1, max: 1, items: $.map(app.config.sortKeys, function(key, i) { + { group: 'sortmovies', min: 1, max: 1, items: $.map(app.ui.sortKeys, function(key, i) { return $.extend({ checked: app.user.ui.lists[app.user.ui.list].sort[0].key == key.id, }, key); @@ -2421,11 +2438,11 @@ var pandora = new Ox.App({ ] }, { id: 'findMenu', title: 'Find', items: [ { id: 'find', title: 'Find', items: [ - { group: 'find', min: 1, max: 1, items: $.map(app.config.findKeys, function(key, i) { + { group: 'find', min: 1, max: 1, items: $.map(app.ui.findKeys, function(key, i) { return $.extend({ checked: app.user.ui.findQuery.conditions.length && - (app.user.ui.findQuery.conditions[0].key == key.id || - (app.user.ui.findQuery.conditions[0].key === '' && key.id == 'all')), + (app.user.ui.findQuery.conditions[0].key == key.id || + (app.user.ui.findQuery.conditions[0].key === '' && key.id == 'all')), }, key) }) } ] }, @@ -2989,7 +3006,7 @@ var pandora = new Ox.App({ sortSelect: function() { var that = new Ox.Select({ id: 'sortSelect', - items: $.map(app.config.sortKeys, function(key) { + items: $.map(app.ui.sortKeys, function(key) { //Ox.print('????', app.user.ui.lists[app.user.ui.list].sort.key, key.id) return $.extend($.extend({}, key), { checked: app.user.ui.lists[app.user.ui.list].sort[0].key == key.id, @@ -3191,7 +3208,7 @@ var pandora = new Ox.App({ function getAlignment(key) { // fixme: make static return ['person', 'string', 'text', 'title'].indexOf( - Ox.getObjectById(app.config.sortKeys, key).type + Ox.getObjectById(app.ui.sortKeys, key).type ) > -1 ? 'left' : 'right'; } @@ -3245,7 +3262,7 @@ var pandora = new Ox.App({ function getSortOperator(key) { // fixme: make static return ['person', 'string', 'text', 'title'].indexOf( - Ox.getObjectById(app.config.sortKeys, key).type + Ox.getObjectById(app.ui.sortKeys, key).type ) > -1 ? '' : '-'; } @@ -3364,6 +3381,10 @@ var pandora = new Ox.App({ } } + function saveVideoPosition() { + //alert(JSON.stringify(['videoPosition|' + old.user.ui.item, app.$ui[old.user.ui.itemView == 'player' ? 'player' : 'editor'].options('position')])); + } + function selectList() { if (app.user.ui.list) { pandora.api.findLists({ @@ -3392,6 +3413,19 @@ var pandora = new Ox.App({ } } + function unloadWindow() { + // fixme: ajax request has to have async set to false for this to work + app.user.ui.section == 'items' && + ['player', 'timeline'].indexOf(app.user.ui.itemView) > -1 && + app.user.ui.item && + UI.set( + 'videoPosition|' + app.user.ui.item, + app.$ui[ + app.user.ui.itemView == 'player' ? 'player' : 'editor' + ].options('position') + ); + } + function validateUser(key, existing) { existing = existing || false; var string = key == 'username' ? 'username' : 'e-mail address'; @@ -3600,6 +3634,7 @@ var pandora = new Ox.App({ } }); pandora.api.setUI(obj); + //alert('set ' + JSON.stringify(obj)) } } }()); @@ -3700,40 +3735,23 @@ var pandora = new Ox.App({ update: function() { URL.parse(); - if (app.user.ui.section == 'site') { - if (old.user.ui.section == 'site') { - app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); - } else { - app.$ui.appPanel.replace(1, app.$ui.mainPanel = ui.mainPanel()); - } - } else if (app.user.ui.section == 'items') { - if (old.user.ui.section == 'site') { - app.$ui.appPanel.replace(1, app.$ui.mainPanel = ui.mainPanel()); - } else { - if (!old.user.ui.item) { - if (!app.user.ui.item) { - app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); - //app.$ui.contentPanel.replace(1, ui.list()); - } else { - app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); - //app.$ui.rightPanel.replace(0, app.$ui.toolbar = ui.toolbar()); - //ui.item().display(); - } - } else { - if (['player', 'timeline'].indexOf(old.user.ui.itemView) > -1) { - UI.set( - 'videoPosition|' + old.user.ui.item, - app.$ui[old.user.ui.itemView == 'player' ? 'player' : 'editor'].options('position') - ); - } - if (!app.user.ui.item) { - app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); - //ui.list(app.user.ui.listView).display(); - } else { - app.$ui.contentPanel.replace(1, ui.item()); - } - } - } + if (app.user.ui.section != old.user.ui.section) { + app.$ui.appPanel.replace(1, app.$ui.mainPanel = ui.mainPanel()); + } else if (!app.user.ui.item || !old.user.ui.item) { + app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); + } else { + app.$ui.contentPanel.replace(1, ui.item()); + } + if ( + old.user.ui.item && + ['player', 'timeline'].indexOf(old.user.ui.itemView) > -1 + ) { + UI.set( + 'videoPosition|' + old.user.ui.item, + app.$ui[ + old.user.ui.itemView == 'player' ? 'player' : 'editor' + ].options('position') + ); } delete old.user.ui; } @@ -3782,4 +3800,4 @@ var pandora = new Ox.App({ load(); -}); +}); \ No newline at end of file