diff --git a/pandora/user/views.py b/pandora/user/views.py index 6767898b..0f44ad96 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -459,7 +459,7 @@ def setUI(request): if key not in p: p[key] = {} p = p[key] - if value == None: + if value == None and keys[0] in p: del p[keys[0]] else: p[keys[0]] = value diff --git a/static/js/pandora/Query.js b/static/js/pandora/Query.js index be894d0f..5e2e197a 100644 --- a/static/js/pandora/Query.js +++ b/static/js/pandora/Query.js @@ -97,13 +97,24 @@ pandora.Query = (function() { list: '', query: {conditions: [], operator: ''} }, - subconditions = str.match(/\[.*?\]/g) || []; + subconditions = []; if (str.length) { // replace subconditions with placeholder, // so we can later split by main operator + var counter = 0; + Ox.forEach(str, function(c, i) { + if (c == ']') { + counter--; + } + if (counter >= 1) { + subconditions[subconditions.length - 1] += c; + } + if (c == '[') { + (++counter == 1) && subconditions.push(''); + } + }); subconditions.forEach(function(subcondition, i) { - subconditions[i] = subcondition.substr(1, subcondition.length - 2); - str = str.replace(subconditions[i], i); + str = str.replace(subcondition, i); }); if (str.indexOf(',') > -1) { ret.query.operator = '&'; @@ -116,7 +127,7 @@ pandora.Query = (function() { var kv, ret; if (condition[0] == '[') { // re-insert subcondition - ret = parseFind(subconditions[parseInt(condition.substr(1, condition.length - 2))]).query; + ret = parseFind(subconditions[parseInt(Ox.sub(condition, 1, -1))]).query; } else { kv = ((condition.indexOf(':') > -1 ? '' : ':') + condition).split(':'); ret = Ox.extend({key: kv[0]}, parseValue(kv[1])); diff --git a/static/js/pandora/UI.js b/static/js/pandora/UI.js index 8804bb3b..e1245eb3 100644 --- a/static/js/pandora/UI.js +++ b/static/js/pandora/UI.js @@ -3,17 +3,21 @@ pandora.UI = (function() { return { set: function(/*{key: val} or key, val*/) { var obj = Ox.makeObject(arguments); - $.each(obj, function(key, val) { + Ox.forEach(obj, function(val, key) { Ox.print('key', key, 'val', val); var i = 0, keys = key.split('|'), - old = pandora.user.ui; + ui = pandora.user.ui; while (i < keys.length - 1) { - old = old[keys[i]]; + ui = ui[keys[i]]; i++; } - if (old[keys[i]] !== val) { - old[keys[i]] = val; + if (ui[keys[i]] !== val) { + if (val === null) { + delete ui[keys[i]] + } else { + ui[keys[i]] = val; + } } else { delete obj[key]; } diff --git a/static/js/pandora/URL.js b/static/js/pandora/URL.js index fcc24d8a..4e420258 100644 --- a/static/js/pandora/URL.js +++ b/static/js/pandora/URL.js @@ -108,7 +108,7 @@ pandora.URL = (function() { return prev + (parseFloat(curr) || 0) * Math.pow(60, i); }, 0); i == 0 && pandora.UI.set(['videoPosition', item].join('|'), point); - return Ox.formatDuration(point, 2).replace(/\.00$/, ''); + return Ox.formatDuration(point, 3).replace(/\.000$/, ''); }).join('-'); pandora.URL.replace(split.join('/')) } diff --git a/static/js/pandora/ui/foldersList.js b/static/js/pandora/ui/foldersList.js index 0bf7cf52..e5fb7987 100644 --- a/static/js/pandora/ui/foldersList.js +++ b/static/js/pandora/ui/foldersList.js @@ -175,7 +175,7 @@ pandora.ui.folderList = function(id) { click: function(event, data) { var $list = pandora.$ui.folderList[id]; if (data.key == 'type') { - pandora.$ui.filterDialog = ui.filterDialog().open(); + pandora.$ui.filterDialog = pandora.ui.filterDialog().open(); } else if (data.key == 'status') { pandora.api.editList({ id: data.id, diff --git a/static/js/pandora/ui/item.js b/static/js/pandora/ui/item.js index fa36f97a..623e75af 100644 --- a/static/js/pandora/ui/item.js +++ b/static/js/pandora/ui/item.js @@ -7,16 +7,39 @@ pandora.ui.item = function() { }, pandora.user.level == 'admin' && pandora.user.ui.itemView == 'info' ? 0 : -1, function(result) { if (result.status.code != 200) { // fixme: this is quite a hack + var title = decodeURI(pandora.user.ui.item).toLowerCase(), + videoPosition; + if (pandora.user.ui.item in pandora.user.ui.videoPosition) { + videoPosition = pandora.user.ui.videoPosition[pandora.user.ui.item]; + pandora.UI.set(['videoPosition', pandora.user.ui.item].join('|'), null); + } pandora.api.find({ query: { - conditions: [{key: 'title', value: decodeURI(pandora.user.ui.item), operator: '='}], + conditions: [{key: 'title', value: title, operator: ''}], operator: '' }, - keys: ['id'] + sort: [{key: 'votes', operator: '-'}], // fixme: operator '' should work as well + range: [0, 100], + keys: ['id', 'title', 'votes'] }, function(result) { if (result.data.items.length) { + Ox.print(result.data.items) + var re = { + exact: new RegExp('^' + title + '$', 'i'), + word: new RegExp('\\b' + title + '\\b', 'i') + }, + id = result.data.items.sort(function(a, b) { + return (parseInt(b.votes) || 0) + + re.word.test(b.title) * 1000000 + + re.exact.test(b.title) * 2000000 + - (parseInt(a.votes) || 0) + - re.word.test(a.title) * 1000000 + - re.exact.test(a.title) * 2000000; + })[0].id; pandora.user.ui.item = ''; - pandora.URL.set(result.data.items[0].id); + !Ox.isUndefined(videoPosition) + && pandora.UI.set(['videoPosition', id].join('|'), videoPosition); + pandora.URL.set(id); } else { pandora.$ui.contentPanel.replaceElement(1, Ox.Element() @@ -404,7 +427,7 @@ pandora.ui.item = function() { ); } if (result.data) { - var director = result.data.director?' ('+result.data.director.join(', ')+')':''; + var director = result.data.director ? ' ('+result.data.director.join(', ') + ')' : ''; pandora.$ui.total.html(result.data.title + director); } }); diff --git a/static/js/pandora/ui/preferencesDialog.js b/static/js/pandora/ui/preferencesDialog.js index 3dc6cd72..5aa98cd5 100644 --- a/static/js/pandora/ui/preferencesDialog.js +++ b/static/js/pandora/ui/preferencesDialog.js @@ -28,13 +28,6 @@ pandora.ui.preferencesDialog = function() { }); }, tabs: tabs - }) - .bindEvent({ - change: function(data) { - $dialog.options({ - title: Ox.getObjectById(tabs, data.selected).title - }); - } }); var $dialog = Ox.Dialog({ buttons: [ @@ -49,12 +42,12 @@ pandora.ui.preferencesDialog = function() { ], //closeButton: true, content: $tabPanel, - height: Math.round((window.innerHeight - 24) * 0.75), + height: Math.round((window.innerHeight - 24) * 0.5), //maximizeButton: true, minHeight: 256, minWidth: 640, title: 'Preferences', - width: Math.round(window.innerWidth * 0.75), + width: Math.round(window.innerWidth * 0.5), }); return $dialog;