forked from 0x2620/pandora
fix URL/UI bugs, handle the case where on page load we have an item and a query that does not match the item
This commit is contained in:
parent
e3fb12441d
commit
d7092ad856
2 changed files with 45 additions and 38 deletions
|
@ -33,40 +33,41 @@ pandora.UI = (function() {
|
||||||
}
|
}
|
||||||
Ox.print('UI SET', args)
|
Ox.print('UI SET', args)
|
||||||
self.previousUI = Ox.clone(pandora.user.ui, true);
|
self.previousUI = Ox.clone(pandora.user.ui, true);
|
||||||
Ox.forEach(args, function(val, key) {
|
if ('find' in args) {
|
||||||
if (key == 'find') {
|
// the challenge here is that find may change list,
|
||||||
// the challenge here is that find may change list,
|
// and list may then change listSort and listView,
|
||||||
// and list may then change listSort and listView,
|
// which we don't want to trigger, since find triggers
|
||||||
// which we don't want to trigger, since find triggers
|
// (values we put in add will be changed, but won't trigger)
|
||||||
var list = pandora.getListsState(val);
|
var list = pandora.getListsState(args.find);
|
||||||
pandora.user.ui._list = list;
|
pandora.user.ui._list = list;
|
||||||
pandora.user.ui._groupsState = pandora.getGroupsState(val);
|
pandora.user.ui._groupsState = pandora.getGroupsState(args.find);
|
||||||
pandora.user.ui._findState = pandora.getFindState(val);
|
pandora.user.ui._findState = pandora.getFindState(args.find);
|
||||||
if (!Ox.isEqual(val, pandora.user.ui.find)) {
|
if (pandora.$ui.appPanel) {
|
||||||
if (pandora.$ui.appPanel) {
|
// if we're not on page load,
|
||||||
// if find has changed and we're not on page load,
|
// switch from item view to list view
|
||||||
// switch from item view to list view
|
add['item'] = '';
|
||||||
add['item'] = '';
|
}
|
||||||
}
|
if (!pandora.user.ui.lists[list]) {
|
||||||
|
add['lists.' + that.encode(list)] = {};
|
||||||
|
}
|
||||||
|
if (list != self.previousUI._list) {
|
||||||
|
Ox.forEach(listSettings, function(listSetting, setting) {
|
||||||
if (!pandora.user.ui.lists[list]) {
|
if (!pandora.user.ui.lists[list]) {
|
||||||
add['lists.' + that.encode(list)] = {};
|
// add default list setting and copy to settings
|
||||||
|
add['lists.' + that.encode(list)][listSetting] = pandora.site.user.ui[setting];
|
||||||
|
add[setting] = pandora.site.user.ui[setting];
|
||||||
|
} else {
|
||||||
|
// copy lists setting to settings
|
||||||
|
add[setting] = pandora.user.ui.lists[list][listSetting]
|
||||||
}
|
}
|
||||||
if (list != self.previousUI._list) {
|
});
|
||||||
Ox.forEach(listSettings, function(listSetting, setting) {
|
}
|
||||||
if (!pandora.user.ui.lists[list]) {
|
}
|
||||||
// add default list setting and copy to settings
|
// it is important to check for find first, so that if find
|
||||||
add['lists.' + that.encode(list)][listSetting] = pandora.site.user.ui[setting];
|
// changes list, pandora.user.ui._list is correct here
|
||||||
add[setting] = pandora.site.user.ui[setting];
|
Ox.forEach(args, function(val, key) {
|
||||||
} else {
|
if (Object.keys(listSettings).indexOf(key) > -1) {
|
||||||
// copy lists setting to settings
|
// if applicable, copy setting to list setting
|
||||||
add[setting] = pandora.user.ui.lists[list][listSetting]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Object.keys(listSettings).indexOf(key) > -1) {
|
|
||||||
// copy setting to list setting
|
|
||||||
add['lists.' + that.encode(pandora.user.ui._list || '') + '.' + listSettings[key]] = val;
|
add['lists.' + that.encode(pandora.user.ui._list || '') + '.' + listSettings[key]] = val;
|
||||||
} else if (key == 'item' && val) {
|
} else if (key == 'item' && val) {
|
||||||
// when switching to an item, update list selection
|
// when switching to an item, update list selection
|
||||||
|
@ -82,16 +83,21 @@ pandora.UI = (function() {
|
||||||
&& ['video', 'timeline'].indexOf(val) > -1
|
&& ['video', 'timeline'].indexOf(val) > -1
|
||||||
&& !pandora.user.ui.videoPoints[pandora.user.ui.item]
|
&& !pandora.user.ui.videoPoints[pandora.user.ui.item]
|
||||||
)) {
|
)) {
|
||||||
// add default videoPoints
|
// when switching to a video view, add default videoPoints
|
||||||
add['videoPoints.' + (
|
add['videoPoints.' + (
|
||||||
key == 'item' ? val : pandora.user.ui.item
|
key == 'item' ? val : pandora.user.ui.item
|
||||||
)] = {'in': 0, out: 0, position: 0};
|
)] = {'in': 0, out: 0, position: 0};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
[args, add].forEach(function(obj, isAdd) {
|
[args, add].forEach(function(obj, isAdd) {
|
||||||
|
Ox.print('UUU', obj)
|
||||||
Ox.forEach(obj, function(val, key) {
|
Ox.forEach(obj, function(val, key) {
|
||||||
var keys = key.replace(/([^\\])\./g, '$1\n').split('\n'),
|
// make sure to not split at escaped dots ('\.')
|
||||||
|
var keys = key.replace(/\\\./g, '\n').split('.').map(function(key) {
|
||||||
|
return key.replace(/\n/g, '.')
|
||||||
|
}),
|
||||||
ui = pandora.user.ui;
|
ui = pandora.user.ui;
|
||||||
|
Ox.print(key, '......', keys)
|
||||||
while (keys.length > 1) {
|
while (keys.length > 1) {
|
||||||
ui = ui[keys.shift()];
|
ui = ui[keys.shift()];
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,9 +205,10 @@ pandora.URL = (function() {
|
||||||
|
|
||||||
///*
|
///*
|
||||||
if (state.find) {
|
if (state.find) {
|
||||||
set.find = state.find;
|
find = state.find;
|
||||||
|
set.find = find;
|
||||||
} else {
|
} else {
|
||||||
var find = pandora.user.ui.find;
|
find = pandora.user.ui.find;
|
||||||
pandora.user.ui._list = pandora.getListsState(find)
|
pandora.user.ui._list = pandora.getListsState(find)
|
||||||
pandora.user.ui._groupsState = pandora.getGroupsState(find);
|
pandora.user.ui._groupsState = pandora.getGroupsState(find);
|
||||||
pandora.user.ui._findState = pandora.getFindState(find);
|
pandora.user.ui._findState = pandora.getFindState(find);
|
||||||
|
@ -219,12 +220,12 @@ pandora.URL = (function() {
|
||||||
$(this).trigger('stop');
|
$(this).trigger('stop');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!pandora.$ui.appPanel && state.item && pandora.user.ui.find) {
|
if (!pandora.$ui.appPanel && state.item && find) {
|
||||||
// on page load, if item is set and there is or was a query,
|
// on page load, if item is set and there is or was a query,
|
||||||
// we have to check if the item actually matches the query,
|
// we have to check if the item actually matches the query,
|
||||||
// and otherwise reset find
|
// and otherwise reset find
|
||||||
pandora.api.find({
|
pandora.api.find({
|
||||||
query: pandora.user.ui.find,
|
query: find,
|
||||||
positions: [state.item],
|
positions: [state.item],
|
||||||
sort: [{key: 'id', operator: ''}]
|
sort: [{key: 'id', operator: ''}]
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
|
|
Loading…
Reference in a new issue