new app api

This commit is contained in:
rolux 2010-09-13 15:54:52 +02:00
parent ae9c823198
commit 23f047522f

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: []
@ -408,12 +409,13 @@ app.constructGroups = function() {
} }
], ],
id: 'group_' + id, id: 'group_' + id,
request: function(options) { request: function(data, callback) {
delete options.keys; Ox.print('sending request', data)
app.request('find', $.extend(options, { delete data.keys;
return app.api.find($.extend(data, {
group: id, group: id,
query: app.Query.toObject() query: app.Query.toObject()
}), options.callback); }), callback);
}, },
sort: [ sort: [
{ {
@ -435,21 +437,21 @@ app.constructGroups = function() {
}); });
query = app.Query.toObject(); query = app.Query.toObject();
app.$ui.list.options({ app.$ui.list.options({
request: function(options) { request: function(data, callback) {
return app.request('find', $.extend(options, { return app.api.find($.extend(data, {
query: query query: query
}), options.callback); }), callback);
} }
}); });
$.each(app.ui.groups, function(i_, group_) { $.each(app.ui.groups, function(i_, group_) {
if (i_ != i) { if (i_ != i) {
app.$ui.groups[i_].options({ app.$ui.groups[i_].options({
request: function(options) { request: function(data, callback) {
delete options.keys; delete data.keys;
return app.request('find', $.extend(options, { return app.api.find($.extend(data, {
group: group_.id, group: group_.id,
query: app.Query.toObject(group_.id) query: app.Query.toObject(group_.id)
}), options.callback); }), callback);
} }
}); });
} }
@ -463,6 +465,7 @@ app.constructGroups = function() {
size: width.list, size: width.list,
title: title title: title
}; };
Ox.print('--OK--');
}); });
return $groups; return $groups;
} }
@ -503,11 +506,11 @@ app.constructList = function(view) {
columnsMovable: true, columnsMovable: true,
columnsRemovable: true, columnsRemovable: true,
id: 'list', id: 'list',
request: function(options) { request: function(data, callback) {
Ox.print('options, Query.toObject', options, app.Query.toObject()) Ox.print('data, Query.toObject', data, app.Query.toObject())
app.request('find', $.extend(options, { app.api.find($.extend(data, {
query: app.Query.toObject() query: app.Query.toObject()
}), options.callback); }), callback);
}, },
sort: app.user.ui.sort sort: app.user.ui.sort
}); });
@ -525,11 +528,11 @@ app.constructList = function(view) {
}; };
}, },
keys: keys, keys: keys,
request: function(options) { request: function(data, callback) {
Ox.print('options, Query.toObject', options, app.Query.toObject()) Ox.print('data, Query.toObject', data, app.Query.toObject())
app.request('find', $.extend(options, { app.api.find($.extend(data, {
query: app.Query.toObject() query: app.Query.toObject()
}), options.callback); }), callback);
}, },
size: 128, size: 128,
sort: app.user.ui.sort, sort: app.user.ui.sort,
@ -557,7 +560,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) {
@ -733,7 +737,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 {
@ -998,7 +1002,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: '='
@ -1031,7 +1035,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;
@ -1401,7 +1405,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: [
@ -1450,20 +1454,20 @@ app.constructToolbar = function() {
$.each(groups, function(i, group) { $.each(groups, function(i, group) {
groups[i].query.conditions = []; groups[i].query.conditions = [];
app.$ui.groups[i].options({ app.$ui.groups[i].options({
request: function(options) { request: function(data, callback) {
delete options.keys; delete data.keys;
return app.request('find', $.extend(options, { return app.api.find($.extend(data, {
group: group.id, group: group.id,
query: app.Query.toObject(group.id) query: app.Query.toObject(group.id)
}), options.callback); }), callback);
} }
}); });
}); });
app.$ui.list.options({ app.$ui.list.options({
request: function(options) { request: function(data, callback) {
return app.request('find', $.extend(options, { return app.api.find($.extend(data, {
query: query = app.Query.toObject() query: query = app.Query.toObject()
}), options.callback); }), callback);
} }
}); });
location.hash = app.Query.toString(query); location.hash = app.Query.toString(query);
@ -1493,7 +1497,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);
@ -1527,7 +1531,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: [
{ {
@ -1756,7 +1760,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();
@ -1818,7 +1822,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;
@ -1935,7 +1939,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 &
@ -1952,7 +1956,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,