move more asynchronous tasks into the url controller; fix bugs with list selection when page loads in item view

This commit is contained in:
rolux 2011-09-20 04:11:25 +00:00
commit 49c013c4ef
8 changed files with 260 additions and 233 deletions

View file

@ -9,7 +9,8 @@ pandora.ui.backButton = function() {
})
.bindEvent({
click: function() {
pandora.URL.set(pandora.Query.toString());
pandora.UI.set({item: null});
pandora.URL.update();
}
});
return that;

View file

@ -1,6 +1,6 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
pandora.ui.browser = function() {
var sizes, that;
var that;
if (!pandora.user.ui.item) {
pandora.user.ui.groupsSizes = pandora.getGroupsSizes();
pandora.$ui.groups = pandora.ui.groups();

View file

@ -371,17 +371,18 @@ pandora.ui.folderList = function(id) {
pandora.$ui.list.triggerEvent('paste', data);
},
select: function(data) {
//pandora.user.ui.item && pandora.UI.set({item: ''});
if (data.ids.length) {
Ox.forEach(pandora.$ui.folderList, function($list, id_) {
id != id_ && $list.options('selected', []);
});
//pandora.UI.set({list: data.ids[0]});
pandora.URL.set('?find=' + (id == 'volumes' ? 'volume' : 'list') + ':' + data.ids[0]);
} else {
//pandora.UI.set({list: ''});
pandora.URL.set('');
}
pandora.URL.set(data.ids.length ? '?find=list:' + data.ids[0] : '');
/*
pandora.UI.set({
item: '',
list: data.ids.length ? data.ids[0] : ''
});
*/
},
submit: function(data) {
data_ = {id: data.id};

View file

@ -11,63 +11,21 @@ pandora.ui.item = function() {
if (result.status.code == 200) {
// fixme: probably does not belong here
document.title = '0xDB - ' + result.data.title;
if (pandora.user.ui.videoPoints[result.data.id].out == -1) {
pandora.UI.set('videoPoints|' + result.data.id + '|out', result.data.duration);
pandora.URL.replace(
document.location.pathname
+ Ox.formatDuration(result.data.duration, 3).replace(/\.000$/, '')
);
}
}
if (result.status.code != 200) {
// fixme: this is quite a hack
var title = decodeURI(pandora.user.ui.item).toLowerCase(),
videoPoints;
if (pandora.user.ui.item in pandora.user.ui.videoPoints) {
videoPoints = pandora.user.ui.videoPoints[pandora.user.ui.item];
pandora.UI.set(['videoPoints', pandora.user.ui.item].join('|'), null);
}
pandora.api.find({
query: {
conditions: [{key: 'title', value: title, operator: ''}],
operator: ''
},
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 = '';
!Ox.isUndefined(videoPoints)
&& pandora.UI.set(['videoPoints', id].join('|'), videoPoints);
pandora.URL.set(id);
} else {
pandora.$ui.contentPanel.replaceElement(1,
Ox.Element()
.css({marginTop: '32px', fontSize: '12px', textAlign: 'center'})
.html(
'Sorry, we can\'t find the '
+ pandora.site.itemName.singular.toLowerCase()
+ ' you\'re looking for.'
)
);
}
});
} else if (!result.data.rendered && [
/*if (result.status.code != 200) {
pandora.$ui.contentPanel.replaceElement(1,
Ox.Element()
.css({marginTop: '32px', fontSize: '12px', textAlign: 'center'})
.html(
'Sorry, we can\'t find the '
+ pandora.site.itemName.singular.toLowerCase()
+ ' you\'re looking for.'
)
);
}*/
if (!result.data.rendered && [
'clips', 'map', 'player', 'timeline'
].indexOf(pandora.user.ui.itemView)>-1) {
pandora.$ui.contentPanel.replaceElement(1,