use app.config.itemKeys, add Ox.Filter

This commit is contained in:
rolux 2011-01-23 04:58:40 +00:00
parent 083e31cc25
commit 052bd72a84
3 changed files with 117 additions and 88 deletions

View file

@ -52,7 +52,7 @@
"title": "Country", "title": "Country",
"type": ["string"], "type": ["string"],
"find": {"autocomplete": true}, "find": {"autocomplete": true},
"sort": {"type": "string", "width": 180}, "sort": {"type": "string", "width": 120},
"group": true "group": true
}, },
{ {
@ -60,7 +60,7 @@
"title": "Year", "title": "Year",
"type": "year", "type": "year",
"find": {"autocomplete": true}, "find": {"autocomplete": true},
"sort": {"type": "year", "width": 180}, "sort": {"type": "year", "width": 60},
"group": true "group": true
}, },
{ {
@ -68,9 +68,16 @@
"title": "Language", "title": "Language",
"type": ["string"], "type": ["string"],
"find": {"autocomplete": true}, "find": {"autocomplete": true},
"sort": {"type": "string", "width": 180}, "sort": {"type": "string", "width": 120},
"group": true "group": true
}, },
{
"id": "runtime",
"title": "Runtime",
"type": "integer",
"sort": {"type": "integer", "width": 60},
"format": {"type": "duration", "args": [0, "medium"]}
},
{ {
"id": "writer", "id": "writer",
"title": "Writer", "title": "Writer",
@ -80,8 +87,7 @@
"group": true "group": true
}, },
{ {
"id": "id": "producer",
"producer",
"type": ["string"], "type": ["string"],
"title": "Producer", "title": "Producer",
"find": {"autocomplete": true}, "find": {"autocomplete": true},
@ -111,6 +117,13 @@
"find": {"autocomplete": true}, "find": {"autocomplete": true},
"group": true "group": true
}, },
{
"id": "numberofactors",
"title": "Number of Actors",
"sort": {"type": "integer", "width": 60},
"value": {"key": "actor", "type": "length"},
"type": "integer"
},
{ {
"id": "character", "id": "character",
"title": "Character", "title": "Character",
@ -123,19 +136,12 @@
"type": ["string"], "type": ["string"],
"find": {"autocomplete": true} "find": {"autocomplete": true}
}, },
{
"id": "numberofactors",
"title": "Number of Actors",
"sort": {"type": "integer", "width": 60},
"value": {"key": "actor", "type": "length"},
"type": "integer"
},
{ {
"id": "genre", "id": "genre",
"title": "Genre", "title": "Genre",
"type": ["string"], "type": ["string"],
"find": {"autocomplete": true}, "find": {"autocomplete": true},
"sort": {"type": "string", "width": 180}, "sort": {"type": "string", "width": 120},
"group": true "group": true
}, },
{ {
@ -152,13 +158,6 @@
"sort": {"type": "integer", "width": 60}, "sort": {"type": "integer", "width": 60},
"value": {"key": "keyword", "type": "length"} "value": {"key": "keyword", "type": "length"}
}, },
{
"id": "runtime",
"title": "Runtime",
"type": "integer",
"sort": {"type": "integer", "width": 60},
"format": {"type": "duration", "args": [0, "medium"]}
},
{ {
"id": "summary", "id": "summary",
"title": "Summary", "title": "Summary",
@ -166,13 +165,6 @@
"group": false, "group": false,
"find": {} "find": {}
}, },
{
"id": "dialog",
"title": "Dialog",
"type": "text",
"group": false,
"find": {}
},
{ {
"id": "wordsinsummary", "id": "wordsinsummary",
"title": "Words in Summary", "title": "Words in Summary",
@ -235,6 +227,13 @@
"sort": {"type": "string", "width": 90}, "sort": {"type": "string", "width": 90},
"type": "string" "type": "string"
}, },
{
"id": "dialog",
"title": "Dialog",
"type": "text",
"group": false,
"find": {}
},
{ {
"id": "aspectratio", "id": "aspectratio",
"title": "Aspect Ratio", "title": "Aspect Ratio",
@ -351,6 +350,18 @@
"sort": {"type": "date", "width": 90}, "sort": {"type": "date", "width": 90},
"type": "date" "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", "id": "popularity",
"title": "Popularity", "title": "Popularity",

View file

@ -52,18 +52,18 @@ def init(request):
''' '''
#data = json.loads(request.POST['data']) #data = json.loads(request.POST['data'])
response = json_response({}) 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: with open(settings.SITE_CONFIG) as f:
response['data']['config'] = json.load(f) response['data']['config'] = json.load(f)
response['data']['config']['site']['id'] = settings.SITEID response['data']['config']['site']['id'] = settings.SITEID
response['data']['config']['site']['name'] = settings.SITENAME response['data']['config']['site']['name'] = settings.SITENAME
response['data']['config']['site']['sectionName'] = settings.SITENAME response['data']['config']['site']['sectionName'] = settings.SITENAME
response['data']['config']['site']['url'] = settings.URL 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) return render_to_json_response(response)
actions.register(init) actions.register(init)

View file

@ -4,7 +4,6 @@
var pandora = new Ox.App({ var pandora = new Ox.App({
apiURL: '/api/', apiURL: '/api/',
config: '/site.json',
init: 'init', init: 'init',
}).launch(function(data) { }).launch(function(data) {
@ -14,11 +13,22 @@ var pandora = new Ox.App({
$ui: { $ui: {
body: $('body'), body: $('body'),
document: $(document), document: $(document),
window: $(window).resize(resizeWindow) window: $(window)
.resize(resizeWindow)
.unload(unloadWindow)
}, },
config: data.config, config: data.config,
requests: {}, requests: {},
ui: { 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: { sectionFolders: {
site: $.merge([ site: $.merge([
{id: 'site', title: 'Site', items: $.merge([ {id: 'site', title: 'Site', items: $.merge([
@ -43,10 +53,13 @@ var pandora = new Ox.App({
{id: 'featured', title: 'Featured Lists', showBrowser: false} {id: 'featured', title: 'Featured Lists', showBrowser: false}
], ],
}, },
infoRatio: 16 / 9, selectedMovies: [],
scrollbarSize: $.browser.mozilla ? 16 : 12, sortKeys: $.map(data.config.itemKeys, function(key, i) {
sectionElement: 'buttons', return 'sort' in key ? $.extend({
selectedMovies: [] id: key.id,
title: key.title
}, key.sort) : null;
})
}, },
user: data.user user: data.user
}; };
@ -675,7 +688,7 @@ var pandora = new Ox.App({
] : [], [ ] : [], [
app.$ui.findSelect = new Ox.Select({ app.$ui.findSelect = new Ox.Select({
id: 'select', id: 'select',
items: $.map(app.config.findKeys, function(key, i) { items: $.map(app.ui.findKeys, function(key, i) {
return { return {
id: key.id, id: key.id,
checked: key.id == findKey, checked: key.id == findKey,
@ -740,7 +753,7 @@ var pandora = new Ox.App({
return app.user.ui.findQuery.conditions.length ? function(value, callback) { return app.user.ui.findQuery.conditions.length ? function(value, callback) {
var elementValue = that.value(), var elementValue = that.value(),
key = elementValue[app.user.ui.list ? 1 : 0].id, 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) Ox.print('!!!!', key, findKey, 'autocomplete' in findKey && findKey.autocomplete)
value === '' && Ox.print('Warning: autocomplete function should never be called with empty value'); value === '' && Ox.print('Warning: autocomplete function should never be called with empty value');
if ('autocomplete' in findKey && findKey.autocomplete) { if ('autocomplete' in findKey && findKey.autocomplete) {
@ -1141,11 +1154,15 @@ var pandora = new Ox.App({
$dialog.close(); $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, height: 200,
keys: {enter: 'save', escape: 'cancel'}, keys: {enter: 'save', escape: 'cancel'},
title: 'Advanced Find', title: 'Advanced Find',
width: 640 width: 616 + app.ui.scrollbarSize
}).open(); }).open();
} else if (data.key == 'status') { } else if (data.key == 'status') {
pandora.api.editList({ pandora.api.editList({
@ -1850,7 +1867,7 @@ var pandora = new Ox.App({
Ox.print('$$$$', keys) Ox.print('$$$$', keys)
*/ */
that = new Ox.TextList({ 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); 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) 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), { return $.extend($.extend({}, key), {
@ -1885,7 +1902,7 @@ var pandora = new Ox.App({
data.ids.forEach(function(id) { data.ids.forEach(function(id) {
columnWidth[id] = columnWidth[id] =
app.user.ui.lists[app.user.ui.list].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); 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, height: ratio <= 1 ? size : size / ratio,
id: data['id'], id: data['id'],
info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key], 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'), url: data.poster.url.replace(/jpg/, size + '.jpg'),
width: ratio >= 1 ? size : size * ratio width: ratio >= 1 ? size : size * ratio
}; };
@ -2403,7 +2420,7 @@ var pandora = new Ox.App({
]}, ]},
{ id: 'sortMenu', title: 'Sort', items: [ { id: 'sortMenu', title: 'Sort', items: [
{ id: 'sortmovies', title: 'Sort Movies by', 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({ return $.extend({
checked: app.user.ui.lists[app.user.ui.list].sort[0].key == key.id, checked: app.user.ui.lists[app.user.ui.list].sort[0].key == key.id,
}, key); }, key);
@ -2421,11 +2438,11 @@ var pandora = new Ox.App({
] }, ] },
{ id: 'findMenu', title: 'Find', items: [ { id: 'findMenu', title: 'Find', items: [
{ id: 'find', 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({ return $.extend({
checked: app.user.ui.findQuery.conditions.length && 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 ||
(app.user.ui.findQuery.conditions[0].key === '' && key.id == 'all')), (app.user.ui.findQuery.conditions[0].key === '' && key.id == 'all')),
}, key) }, key)
}) } }) }
] }, ] },
@ -2989,7 +3006,7 @@ var pandora = new Ox.App({
sortSelect: function() { sortSelect: function() {
var that = new Ox.Select({ var that = new Ox.Select({
id: 'sortSelect', 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) //Ox.print('????', app.user.ui.lists[app.user.ui.list].sort.key, key.id)
return $.extend($.extend({}, key), { return $.extend($.extend({}, key), {
checked: app.user.ui.lists[app.user.ui.list].sort[0].key == key.id, 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 function getAlignment(key) { // fixme: make static
return ['person', 'string', 'text', 'title'].indexOf( return ['person', 'string', 'text', 'title'].indexOf(
Ox.getObjectById(app.config.sortKeys, key).type Ox.getObjectById(app.ui.sortKeys, key).type
) > -1 ? 'left' : 'right'; ) > -1 ? 'left' : 'right';
} }
@ -3245,7 +3262,7 @@ var pandora = new Ox.App({
function getSortOperator(key) { // fixme: make static function getSortOperator(key) { // fixme: make static
return ['person', 'string', 'text', 'title'].indexOf( return ['person', 'string', 'text', 'title'].indexOf(
Ox.getObjectById(app.config.sortKeys, key).type Ox.getObjectById(app.ui.sortKeys, key).type
) > -1 ? '' : '-'; ) > -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() { function selectList() {
if (app.user.ui.list) { if (app.user.ui.list) {
pandora.api.findLists({ 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) { function validateUser(key, existing) {
existing = existing || false; existing = existing || false;
var string = key == 'username' ? 'username' : 'e-mail address'; var string = key == 'username' ? 'username' : 'e-mail address';
@ -3600,6 +3634,7 @@ var pandora = new Ox.App({
} }
}); });
pandora.api.setUI(obj); pandora.api.setUI(obj);
//alert('set ' + JSON.stringify(obj))
} }
} }
}()); }());
@ -3700,40 +3735,23 @@ var pandora = new Ox.App({
update: function() { update: function() {
URL.parse(); URL.parse();
if (app.user.ui.section == 'site') { if (app.user.ui.section != old.user.ui.section) {
if (old.user.ui.section == 'site') { app.$ui.appPanel.replace(1, app.$ui.mainPanel = ui.mainPanel());
app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); } else if (!app.user.ui.item || !old.user.ui.item) {
} else { app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel());
app.$ui.appPanel.replace(1, app.$ui.mainPanel = ui.mainPanel()); } else {
} app.$ui.contentPanel.replace(1, ui.item());
} else if (app.user.ui.section == 'items') { }
if (old.user.ui.section == 'site') { if (
app.$ui.appPanel.replace(1, app.$ui.mainPanel = ui.mainPanel()); old.user.ui.item &&
} else { ['player', 'timeline'].indexOf(old.user.ui.itemView) > -1
if (!old.user.ui.item) { ) {
if (!app.user.ui.item) { UI.set(
app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); 'videoPosition|' + old.user.ui.item,
//app.$ui.contentPanel.replace(1, ui.list()); app.$ui[
} else { old.user.ui.itemView == 'player' ? 'player' : 'editor'
app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); ].options('position')
//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());
}
}
}
} }
delete old.user.ui; delete old.user.ui;
} }
@ -3782,4 +3800,4 @@ var pandora = new Ox.App({
load(); load();
}); });