From 7251c8d9aac1a424fa2865c7a4287298202284bb Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 5 Sep 2010 02:31:29 +0200 Subject: [PATCH] app --- pandora/static/js/pandora.js | 2786 ++++++++---------------------- pandora/static/json/pandora.json | 124 ++ pandora/templates/index.html | 7 +- 3 files changed, 855 insertions(+), 2062 deletions(-) create mode 100644 pandora/static/json/pandora.json diff --git a/pandora/static/js/pandora.js b/pandora/static/js/pandora.js index d49b341f..30ee89cd 100755 --- a/pandora/static/js/pandora.js +++ b/pandora/static/js/pandora.js @@ -1,322 +1,765 @@ -$(function() { +/*** + Pandora +***/ + +var app = new Ox.App({ + config: '/static/json/pandora.json', + init: 'hello', + id: 'oxdb', + name: 'OxDB', + requestURL: '/api/' +}).launch(function(data) { + Ox.print('data', data) + app.config = data.config; + app.user = data.user; + if (app.user.group == 'guest') { + app.user = data.config.user; + $.browser.safari && Ox.theme('modern'); + } + + app.$body = $('body'); + app.$document = $(document); + app.$window = $(window); + app.$ui = {}; + app.ui = { + infoRatio: 4 / 3, + selectedMovies: [] + }; + + app.Query.fromString(location.hash.substr(1)); + + app.$ui.mainMenu = app.constructMainMenu(); + app.$ui.sections = app.constructSections(); + app.$ui.lists = app.constructLists(); + app.$ui.info = app.constructInfo(); + app.$ui.toolbar = app.constructToolbar(); + app.$ui.groups = app.constructGroups(); + app.$ui.statusbar = app.constructStatusbar(); + + app.$ui.app = app.constructApp(); + app.$ui.app.appendTo(app.$body); + + Ox.Request.requests() && app.$ui.loadingIcon.start(); + Ox.Event.bind('', 'requestStart', function() { + Ox.print('requestStart') + app.$ui.loadingIcon.start(); + }); + Ox.Event.bind('', 'requestStop', function() { + Ox.print('requestStop') + app.$ui.loadingIcon.stop(); + }); + +}); + - //Ox.debug = Ox.print; - //Ox.print = function() {}; - var $body = $('body'), - $document = $(document), - $window = $(window), - config = { - appId: 'oxdb', - appName: '0xDB', - findKeys: [ - { id: 'all', title: 'All' }, - { id: 'title', title: 'Title', autocomplete: true }, - { id: 'director', title: 'Director', autocomplete: true }, - { id: 'country', title: 'Country', autocomplete: true }, - { id: 'year', title: 'Year', autocomplete: true }, - { id: 'language', title: 'Language', autocomplete: true }, - { id: 'writer', title: 'Writer', autocomplete: true }, - { id: 'producer', title: 'Producer', autocomplete: true }, - { id: 'cinematographer', title: 'Cinematographer', autocomplete: true }, - { id: 'editor', title: 'Editor', autocomplete: true }, - { id: 'actor', title: 'Actor', autocomplete: true }, - { id: 'character', title: 'Character', autocomplete: true }, - { id: 'name', title: 'Name', autocomplete: true }, - { id: 'genre', title: 'Genre', autocomplete: true }, - { id: 'keyword', title: 'Keyword', autocomplete: true }, - { id: 'summary', title: 'Summary' }, - { id: 'dialog', title: 'Dialog' } - ], - groups: ['director', 'country', 'year', 'language', 'genre'], - itemViews: [ - { id: 'info', title: 'Info' }, - { id: 'statistics', title: 'Statistics' }, - { id: 'clips', title: 'Clips' }, - { id: 'timeline', title: 'Timeline' }, - { id: 'map', title: 'Map' }, - { id: 'calendar', title: 'Calendar' }, - { id: 'files', title: 'Files', admin: true } - ], - listViews: [ - { id: 'list', title: 'as List' }, - { id: 'icons', title: 'as Icons' }, - { id: 'info', title: 'with Info' }, - { id: 'clips', title: 'with Clips' }, - { id: 'timelines', title: 'with Timelines' }, - { id: 'maps', title: 'with Maps' }, - { id: 'calendars', title: 'with Calendars' }, - { id: 'clip', title: 'as Clips' }, - { id: 'map', title: 'on Map' }, - { id: 'calendar', title: 'on Calendar' }, - ], - sections: [ - { id: 'history', title: 'History' }, - { id: 'lists', title: 'My Lists' }, - { id: 'public', title: 'Public Lists' }, - { id: 'featured', title: 'Featured Lists' } - ], - sortKeys: [ - { id: 'title', title: 'Title', operator: '', align: 'left', width: 180, removable: false }, - { id: 'director', title: 'Director', operator: '', align: 'left', width: 180, removable: false }, - { id: 'country', title: 'Country', operator: '', align: 'left', width: 120 }, - { id: 'year', title: 'Year', operator: '-', align: 'right', width: 60 }, - { id: 'language', title: 'Language', operator: '', align: 'left', width: 120 }, - { id: 'runtime', title: 'Runtime', operator: '-', align: 'right', width: 60 }, - { id: 'writer', title: 'Writer', operator: '', align: 'left', width: 180 }, - { id: 'producer', title: 'Producer', operator: '', align: 'left', width: 180 }, - { id: 'cinematographer', title: 'Cinematographer', operator: '', align: 'left', width: 180 }, - { id: 'editor', title: 'Editor', operator: '', align: 'left', width: 180 }, - { id: 'actors', title: 'Number of Actors', operator: '-', align: 'right', width: 60 }, - { id: 'genre', title: 'Genre', operator: '', align: 'left', width: 120 }, - { id: 'keywords', title: 'Number of Keywords', operator: '-', align: 'right', width: 60 }, - { id: 'summary', title: 'Words in Summary', operator: '-', align: 'right', width: 60 }, - { id: 'trivia', title: 'Words in Trivia', operator: '-', align: 'right', width: 60 }, - { id: 'releasedate', title: 'Release Date', operator: '-', align: 'left', width: 90 }, - { id: 'budget', title: 'Budget', operator: '-', align: 'right', width: 90 }, - { id: 'gross', title: 'Gross', operator: '-', align: 'right', width: 90 }, - { id: 'profit', title: 'Profit', operator: '-', align: 'right', width: 90 }, - { id: 'rating', title: 'Rating', operator: '-', align: 'right', width: 60 }, - { id: 'votes', title: 'Votes', operator: '-', align: 'right', width: 90 }, - { id: 'id', title: 'ID', operator: '', align: 'left', width: 90 }, - { id: 'aspectratio', title: 'Aspect Ratio', operator: '-', align: 'left', width: 90 }, - { id: 'duration', title: 'Duration', operator: '-', align: 'right', width: 90 }, - { id: 'color', title: 'Color', operator: '', align: 'left', width: 90 }, - { id: 'saturation', title: 'Saturation', operator: '-', align: 'right', width: 60 }, - { id: 'brightness', title: 'Brightness', operator: '-', align: 'right', width: 60 }, - { id: 'volume', title: 'Volume', operator: '-', align: 'right', width: 60 }, - { id: 'clips', title: 'Clips', operator: '-', align: 'right', width: 60 }, - { id: 'cuts', title: 'Cuts', operator: '-', align: 'right', width: 60 }, - { id: 'cutsperminute', title: 'Cuts per Minute', operator: '-', align: 'right', width: 60 }, - { id: 'words', title: 'Words', operator: '-', align: 'right', width: 60 }, - { id: 'wordsperminute', title: 'Words per Minute', operator: '-', align: 'right', width: 60 }, - { id: 'resolution', title: 'Resolution', operator: '-', align: 'left', width: 90 }, - { id: 'pixels', title: 'Pixels', operator: '-', align: 'right', width: 90 }, - { id: 'size', title: 'Size', operator: '-', align: 'right', width: 90 }, - { id: 'bitrate', title: 'Bitrate', operator: '-', align: 'right', width: 90 }, - { id: 'files', title: 'Files', operator: '-', align: 'right', width: 60 }, - { id: 'filename', title: 'Filename', operator: '', align: 'left', width: 180 }, - { id: 'published', title: 'Date Published', operator: '-', align: 'left', width: 90 }, - { id: 'modified', title: 'Date Modified', operator: '-', align: 'left', width: 90 } - ], - totals: [ - { id: 'items' }, - { id: 'runtime' }, - { id: 'files', admin: true }, - { id: 'duration', admin: true }, - { id: 'size', admin: true }, - { id: 'pixels' } - ], - user: { - group: 'guest', - ui: { - columns: ['id', 'title', 'director', 'country', 'year', 'language', 'genre'], - // find: { conditions: [{ key: '', value: '', operator: '' }], operator: '' }, - findQuery: { conditions: [{key: '', value: '', operator: ''}], operator: '' }, - groupsQuery: { conditions: [], operator: '|' }, - groupsSize: 128, - itemView: 'info', - listQuery: { conditions: [], operator: '' }, - listsSize: 192, - listView: 'list', - sections: ['history', 'lists', 'public', 'featured'], - showGroups: true, - showInfo: true, - showLists: true, - showMovies: true, - sort: [ - { key: 'director', operator: '' } - ], - theme: $.browser.mozilla ? 'classic' : 'modern' - }, - username: '' - } - }, - user = config.user, - $ui = { - groups: [] - }, - ui = { - infoRatio: 4 / 3, - selectedMovies: [] - }, // Objects - Query = (function() { +app.Query = (function() { - function constructFind(query) { - Ox.print('cF', query) - return /*encodeURI(*/$.map(query.conditions, function(v, i) { - if (!Ox.isUndefined(v.conditions)) { - return '[' + constructFind(v) + ']'; - } else { - return v.value !== '' ? v.key + (v.key ? ':' : '') + constructValue(v.value, v.operator) : null; - } - }).join(query.operator)/*)*/; + function constructFind(query) { + Ox.print('cF', query) + return /*encodeURI(*/$.map(query.conditions, function(v, i) { + if (!Ox.isUndefined(v.conditions)) { + return '[' + constructFind(v) + ']'; + } else { + return v.value !== '' ? v.key + (v.key ? ':' : '') + constructValue(v.value, v.operator) : null; } + }).join(query.operator)/*)*/; + } - function constructValue(value, operator) { - operator = operator.replace('=', '^$'); - if (operator.indexOf('$') > -1) { - value = operator.substr(0, operator.length - 1) + value + '$' - } else { - value = operator + value; - } - return value; + function constructValue(value, operator) { + operator = operator.replace('=', '^$'); + if (operator.indexOf('$') > -1) { + value = operator.substr(0, operator.length - 1) + value + '$' + } else { + value = operator + value; + } + return value; + } + + function mergeFind() { + } + + function parseFind(str) { + var find = { + conditions: [], + operator: '' + }, + subconditions = str.match(/\[.*?\]/g) || []; + $.each(subconditions, function(i, v) { + subconditions[i] = v.substr(1, v.length - 2); + str = str.replace(v, '[' + i + ']'); + }); + if (str.indexOf(',') > -1) { + find.operator = '&'; + } else if (str.indexOf('|') > -1) { + find.operator = '|'; + } + Ox.print('pF', str, find.operator) + find.conditions = $.map(find.operator === '' ? [str] : str.split(find.operator == '&' ? ',' : '|'), function(v, i) { + Ox.print('v', v) + var ret, kv; + if (v[0] == '[') { + Ox.print('recursion', subconditions) + ret = parseFind(subconditions[parseInt(v.substr(1, v.length - 2))]); + } else { + kv = ((v.indexOf(':') > - 1 ? '' : ':') + v).split(':'); + ret = $.extend({ + key: kv[0] + }, parseValue(kv[1])); } + return ret; + }); + return find; + } - function mergeFind() { + function parseValue(str) { + var value = { + value: decodeURI(str), + operator: '' + }; + if (value.value[0] == '!') { + value.operator = '!' + value.value = value.value.substr(1); + } + if ('^<>'.indexOf(value.value[0]) > -1) { + value.operator += value.value[0]; + value.value = value.value.substr(1); + } + if (value.value.substr(-1) == '$') { + value.operator += '$'; + value.value = value.value.substr(0, value.value.length - 1); + } + value.operator = value.operator.replace('^$', '='); + return value; + } + + return { + + fromString: function(str) { + var query = Ox.unserialize(str), + sort = []; + if ('find' in query) { + app.user.ui.findQuery = parseFind(query.find); + Ox.print('user.ui.findQuery', app.user.ui.findQuery) } - - function parseFind(str) { - var find = { - conditions: [], - operator: '' - }, - subconditions = str.match(/\[.*?\]/g) || []; - $.each(subconditions, function(i, v) { - subconditions[i] = v.substr(1, v.length - 2); - str = str.replace(v, '[' + i + ']'); - }); - if (str.indexOf(',') > -1) { - find.operator = '&'; - } else if (str.indexOf('|') > -1) { - find.operator = '|'; - } - Ox.print('pF', str, find.operator) - find.conditions = $.map(find.operator === '' ? [str] : str.split(find.operator == '&' ? ',' : '|'), function(v, i) { - Ox.print('v', v) - var ret, kv; - if (v[0] == '[') { - Ox.print('recursion', subconditions) - ret = parseFind(subconditions[parseInt(v.substr(1, v.length - 2))]); - } else { - kv = ((v.indexOf(':') > - 1 ? '' : ':') + v).split(':'); - ret = $.extend({ - key: kv[0] - }, parseValue(kv[1])); - } - return ret; - }); - return find; - } - - function parseValue(str) { - var value = { - value: decodeURI(str), - operator: '' - }; - if (value.value[0] == '!') { - value.operator = '!' - value.value = value.value.substr(1); - } - if ('^<>'.indexOf(value.value[0]) > -1) { - value.operator += value.value[0]; - value.value = value.value.substr(1); - } - if (value.value.substr(-1) == '$') { - value.operator += '$'; - value.value = value.value.substr(0, value.value.length - 1); - } - value.operator = value.operator.replace('^$', '='); - return value; - } - - return { - - fromString: function(str) { - var query = Ox.unserialize(str), - sort = []; - if ('find' in query) { - user.ui.findQuery = parseFind(query.find); - Ox.print('user.ui.findQuery', user.ui.findQuery) - } - if ('sort' in query) { - sort = query.sort.split(',') - user.ui.sort = $.map(query.sort.split(','), function(v, i) { - var hasOperator = '+-'.indexOf(v[0]) > -1, - key = hasOperator ? query.sort.substr(1) : query.sort, - operator = hasOperator ? v[0].replace('+', '') : Ox.getObjectById(config.sortKeys, key).operator; - return { - key: key, - operator: operator - }; - }); - } - if ('view' in query) { - user.ui.listView = query.view; - } - }, - - toObject: function(groupId) { - Ox.print('tO', user.ui.findQuery.conditions) - // the inner $.merge() creates a clone - var conditions = $.merge($.merge([], user.ui.listQuery.conditions), user.ui.findQuery.conditions); - $.merge(conditions, groups ? $.map(groups, function(v, i) { - if (v.id != groupId && v.query.conditions.length) { - return v.query.conditions.length == 1 ? - v.query.conditions : v.query; - } - }) : []), - operator = conditions.length < 2 ? '' : ','; // fixme: should be & - Ox.print(groupId, user.ui.find, conditions); + if ('sort' in query) { + sort = query.sort.split(',') + app.user.ui.sort = $.map(query.sort.split(','), function(v, i) { + var hasOperator = '+-'.indexOf(v[0]) > -1, + key = hasOperator ? query.sort.substr(1) : query.sort, + operator = hasOperator ? v[0].replace('+', '') : Ox.getObjectById(app.config.sortKeys, key).operator; return { - conditions: conditions, + key: key, operator: operator }; - }, - - toString: function() { - Ox.print('tS', user.ui.find) - return Ox.serialize({ - find: constructFind(Query.toObject()), - sort: user.ui.sort[0].operator + user.ui.sort[0].key, - view: user.ui.listView - }); - } + }); + } + if ('view' in query) { + app.user.ui.listView = query.view; + } + }, + toObject: function(groupId) { + Ox.print('tO', app.user.ui.findQuery.conditions) + // the inner $.merge() creates a clone + var conditions = $.merge($.merge([], app.user.ui.listQuery.conditions), app.user.ui.findQuery.conditions); + $.merge(conditions, app.ui.groups ? $.map(app.ui.groups, function(v, i) { + if (v.id != groupId && v.query.conditions.length) { + return v.query.conditions.length == 1 ? + v.query.conditions : v.query; + } + }) : []), + operator = conditions.length < 2 ? '' : ','; // fixme: should be & + Ox.print(groupId, app.user.ui.find, conditions); + return { + conditions: conditions, + operator: operator }; + }, - })(); + toString: function() { + Ox.print('tS', app.user.ui.find) + return Ox.serialize({ + find: constructFind(Query.toObject()), + sort: app.user.ui.sort[0].operator + app.user.ui.sort[0].key, + view: app.user.ui.listView + }); + } -// App + }; - Query.fromString(location.hash.substr(1)); - Ox.print('user.ui', user.ui) - document.title = config.appName; - Ox.theme(user.ui.theme); - app = new Ox.App({ - name: config.appName, - requestURL: '/api/' +})(); + + + +/* + // Menu + + + Ox.Event.bind('change_viewmovies', function(event, data) { + app.$ui.viewSelect.selectItem(data.id); + }); + Ox.Event.bind('change_find', function(event, data) { + app.$ui.findInput.changeLabel(data.id); + }); + Ox.Event.bind('click_query', function(event, data) { + var $dialog = new Ox.Dialog({ + buttons: [ + { + click: function() { + $dialog.close(); + }, + id: 'close', + title: 'Close', + value: 'Close' + } + ], + id: 'query', + title: 'Query' + }).append(Query.toString() + '

' + JSON.stringify(Query.toObject())).open(); }); - $(' - - - + + \ No newline at end of file