merge changes from pandora

This commit is contained in:
j 2010-09-13 14:49:37 +02:00
commit f3da10d643

View file

@ -21,6 +21,7 @@ var app = new Ox.App({
app.$document = $(document); app.$document = $(document);
app.$window = $(window); app.$window = $(window);
app.$ui = {}; app.$ui = {};
app.requests = {};
app.ui = { app.ui = {
infoRatio: 4 / 3, infoRatio: 4 / 3,
selectedMovies: [] selectedMovies: []
@ -59,7 +60,7 @@ var app = new Ox.App({
Ox.print('requestStop') Ox.print('requestStop')
app.$ui.loadingIcon.stop(); app.$ui.loadingIcon.stop();
}); });
$.each(app.afterLaunch, function(i, f) { f() });
}); });
@ -410,7 +411,7 @@ app.constructGroups = function() {
id: 'group_' + id, id: 'group_' + id,
request: function(options) { request: function(options) {
delete options.keys; delete options.keys;
app.request('find', $.extend(options, { app.api.find($.extend(options, {
group: id, group: id,
query: app.Query.toObject() query: app.Query.toObject()
}), options.callback); }), options.callback);
@ -436,7 +437,7 @@ app.constructGroups = function() {
query = app.Query.toObject(); query = app.Query.toObject();
app.$ui.list.options({ app.$ui.list.options({
request: function(options) { request: function(options) {
return app.request('find', $.extend(options, { return app.api.find($.extend(options, {
query: query query: query
}), options.callback); }), options.callback);
} }
@ -446,7 +447,7 @@ app.constructGroups = function() {
app.$ui.groups[i_].options({ app.$ui.groups[i_].options({
request: function(options) { request: function(options) {
delete options.keys; delete options.keys;
return app.request('find', $.extend(options, { return app.api.find($.extend(options, {
group: group_.id, group: group_.id,
query: app.Query.toObject(group_.id) query: app.Query.toObject(group_.id)
}), options.callback); }), options.callback);
@ -505,7 +506,7 @@ app.constructList = function(view) {
id: 'list', id: 'list',
request: function(options) { request: function(options) {
Ox.print('options, Query.toObject', options, app.Query.toObject()) Ox.print('options, Query.toObject', options, app.Query.toObject())
app.request('find', $.extend(options, { app.api.find($.extend(options, {
query: app.Query.toObject() query: app.Query.toObject()
}), options.callback); }), options.callback);
}, },
@ -528,14 +529,14 @@ app.constructList = function(view) {
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 ? ' (' + data.director + ')' : ''),
url: data.poster.url.replace(/jpg$/, size + '.jpg'), url: 'http://0xdb.org/' + data.id + '/poster.' + size + '.' + 'jpg',
width: width width: width
}; };
}, },
keys: keys, keys: keys,
request: function(options) { request: function(options) {
Ox.print('options, Query.toObject', options, app.Query.toObject()) Ox.print('options, Query.toObject', options, app.Query.toObject())
app.request('find', $.extend(options, { app.api.find($.extend(options, {
query: app.Query.toObject() query: app.Query.toObject()
}), options.callback); }), options.callback);
}, },
@ -565,7 +566,8 @@ app.constructList = function(view) {
app.$ui.selected.html(app.constructStatus('selected', data)); app.$ui.selected.html(app.constructStatus('selected', data));
}, },
openpreview: function(event, data) { openpreview: function(event, data) {
app.request('find', { app.requests.preview && app.api.cancel(app.requests.preview);
app.requests.preview = app.api.find({
keys: ['director', 'id', 'poster', 'title'], keys: ['director', 'id', 'poster', 'title'],
query: { query: {
conditions: $.map(data.ids, function(id, i) { conditions: $.map(data.ids, function(id, i) {
@ -578,35 +580,54 @@ app.constructList = function(view) {
operator: '|' operator: '|'
} }
}, function(result) { }, function(result) {
var item = result.data.items[0], var documentHeight = app.$document.height(),
item = result.data.items[0],
title = item.title + (item.director ? ' (' + item.director + ')' : ''), title = item.title + (item.director ? ' (' + item.director + ')' : ''),
documentHeight = app.$document.height(), dialogHeight = documentHeight - 100,
dialogHeight = documentHeight - 40, dialogWidth;
dialogWidth = parseInt((dialogHeight - 48) * item.poster.width/item.poster.height), app.ui.previewRatio = item.poster.width / item.poster.height,
$image = $('<img>') dialogWidth = parseInt((dialogHeight - 48) * app.ui.previewRatio);
.attr({
src: item.poster.url.replace(/jpg/, 'large.jpg')
})
.css({
height: (dialogHeight - 48 -3) + 'px',
width: (dialogWidth - 3*item.poster.width/item.poster.height) + 'px'
});
if ('previewDialog' in app.$ui) { if ('previewDialog' in app.$ui) {
app.$ui.previewDialog.options({ app.$ui.previewDialog.options({
title: title title: title
}); });
app.$ui.previewImage.animate({ app.$ui.previewImage.animate({
opacity: 0 opacity: 0
}, 250, function() { }, 100, function() {
app.$ui.previewImage.replaceWith( app.$ui.previewDialog.resize(dialogWidth, dialogHeight, function() {
$image.css({ app.$ui.previewImage
opacity: 0 .attr({
}).animate({ src: item.poster.url,
opacity: 1 })
}, 250)); .one('load', function() {
app.$ui.previewImage = $image; app.$ui.previewImage
.css({
width: dialogWidth + 'px',
height: (dialogHeight - 48 - 2) + 'px', // fixme: why -2 ?
opacity: 0
})
.animate({
opacity: 1
}, 100);
});
});
}); });
Ox.print(app.$document.height(), dialogWidth, 'x', dialogHeight, dialogWidth / (dialogHeight - 48), item.poster.width, 'x', item.poster.height, item.poster.width / item.poster.height)
} else { } else {
app.$ui.previewImage = $('<img>')
.attr({
src: item.poster.url
})
.css({
position: 'absolute',
width: dialogWidth + 'px',
height: (dialogHeight - 48 - 2) + 'px', // fixme: why -2 ?
left: 0,
top: 0,
right: 0,
bottom: 0,
margin: 'auto',
});
app.$ui.previewDialog = new Ox.Dialog({ app.$ui.previewDialog = new Ox.Dialog({
buttons: [ buttons: [
{ {
@ -619,13 +640,32 @@ app.constructList = function(view) {
} }
], ],
height: dialogHeight, height: dialogHeight,
id: 'previewDialog',
minHeight: app.ui.previewRatio >= 1 ? 128 / app.ui.previewRatio + 48 : 176,
minWidth: app.ui.previewRatio >= 1 ? 128 : 176 * app.ui.previewRatio,
padding: 0, padding: 0,
title: title, title: title,
width: dialogWidth width: dialogWidth
}) })
.append($image) .append(app.$ui.previewImage)
.bindEvent('resize', function(event, data) {
var dialogRatio = data.width / (data.height - 48),
height, width;
if (dialogRatio < app.ui.previewRatio) {
width = data.width;
height = width / app.ui.previewRatio;
} else {
height = (data.height - 48 - 2);
width = height * app.ui.previewRatio;
}
app.$ui.previewImage.css({
width: width + 'px',
height: height + 'px', // fixme: why -2 ?
})
})
.open(); .open();
app.$ui.previewImage = $image; //app.$ui.previewImage = $image;
//Ox.print(app.$document.height(), dialogWidth, 'x', dialogHeight, dialogWidth / (dialogHeight - 48), item.poster.width, 'x', item.poster.height, item.poster.width / item.poster.height)
} }
}); });
}, },
@ -703,7 +743,7 @@ app.constructList = function(view) {
}); });
*/ */
} }
app.request('find', { app.api.find({
query: { query: {
conditions: $.map(data.ids, function(id, i) { conditions: $.map(data.ids, function(id, i) {
return { return {
@ -968,7 +1008,7 @@ app.constructMainMenu = function() {
label: 'Username', label: 'Username',
labelWidth: 120, labelWidth: 120,
validate: function(value, callback) { validate: function(value, callback) {
app.request('findUser', { app.api.findUser({
key: 'username', key: 'username',
value: value, value: value,
operator: '=' operator: '='
@ -1001,7 +1041,7 @@ app.constructMainMenu = function() {
} }
], ],
submit: function(data, callback) { submit: function(data, callback) {
app.request('login', data, function(result) { app.api.login(data, function(result) {
if (result.status.code == 200) { if (result.status.code == 200) {
$dialog.close(); $dialog.close();
app.user = result.data.user; app.user = result.data.user;
@ -1371,7 +1411,7 @@ app.constructToolbar = function() {
Ox.print('autocomplete', key, value); Ox.print('autocomplete', key, value);
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) {
app.request('find', { app.api.find({
keys: [key], keys: [key],
query: { query: {
conditions: [ conditions: [
@ -1422,7 +1462,7 @@ app.constructToolbar = function() {
app.$ui.groups[i].options({ app.$ui.groups[i].options({
request: function(options) { request: function(options) {
delete options.keys; delete options.keys;
return app.request('find', $.extend(options, { return app.api.find($.extend(options, {
group: group.id, group: group.id,
query: app.Query.toObject(group.id) query: app.Query.toObject(group.id)
}), options.callback); }), options.callback);
@ -1431,7 +1471,7 @@ app.constructToolbar = function() {
}); });
app.$ui.list.options({ app.$ui.list.options({
request: function(options) { request: function(options) {
return app.request('find', $.extend(options, { return app.api.find($.extend(options, {
query: query = app.Query.toObject() query: query = app.Query.toObject()
}), options.callback); }), options.callback);
} }
@ -1463,7 +1503,7 @@ app.getGroupWidth = function(pos, panelWidth) {
//FIXME: how to properly overwrite functions without replacing them //FIXME: how to properly overwrite functions without replacing them
var super_launch = app.launch; var super_launch = app.launch;
app.launch = function() { app.launch = function() {
app.request('hello', function(result) { app.request.send('hello', function(result) {
app.user = result.data.user; app.user = result.data.user;
if(app.user.group!='guest') { if(app.user.group!='guest') {
app.menu.getItem('status').options('title', 'User: ' + app.user.username); app.menu.getItem('status').options('title', 'User: ' + app.user.username);
@ -1497,7 +1537,7 @@ app.getGroupWidth = function(pos, panelWidth) {
} else if (value) { } else if (value) {
value = value.toLowerCase(); value = value.toLowerCase();
//var order = $.inArray(field, ['year', 'date'])?'-':''; //var order = $.inArray(field, ['year', 'date'])?'-':'';
app.request('find', { app.request.send('find', {
query: { query: {
conditions: [ conditions: [
{ {
@ -1726,7 +1766,7 @@ app.getGroupWidth = function(pos, panelWidth) {
{ {
value: 'Contact', value: 'Contact',
click: function() { click: function() {
app.request('contact', form.values(), app.request.send('contact', form.values(),
function(result) { function(result) {
if(result.status.code == 200) { if(result.status.code == 200) {
$dialog.close(); $dialog.close();
@ -1788,7 +1828,7 @@ app.getGroupWidth = function(pos, panelWidth) {
}); });
var submit = function() { var submit = function() {
app.request('login', loginForm.values(), function(result) { app.request.send('login', loginForm.values(), function(result) {
if(result.status.code == 200) { if(result.status.code == 200) {
$dialog.close(); $dialog.close();
app.user = result.data.user; app.user = result.data.user;
@ -1905,7 +1945,7 @@ app.getGroupWidth = function(pos, panelWidth) {
} }
], ],
request: function(options) { request: function(options) {
app.request('find', $.extend(options, { app.request.send('find', $.extend(options, {
query: { query: {
conditions: [], conditions: [],
operator: ',' // fixme: should be & operator: ',' // fixme: should be &
@ -1922,7 +1962,7 @@ app.getGroupWidth = function(pos, panelWidth) {
app.menu.bindEvent('submit_find', function(event, data) { app.menu.bindEvent('submit_find', function(event, data) {
app.results.options({ app.results.options({
request: function(options) { request: function(options) {
app.request('find', $.extend(options, { app.request.send('find', $.extend(options, {
query: { query: {
key: data.option.substr(6).toLowerCase(), key: data.option.substr(6).toLowerCase(),
value: data.value, value: data.value,