adding app.api.foo(), and changing the signature of list.options.request to (data, callback)

This commit is contained in:
rolux 2010-09-13 15:54:22 +02:00
parent 314ddf7d75
commit fe0acbb3ba

View file

@ -143,7 +143,7 @@ requires
name: '',
requestTimeout: 15000,
requestType: 'POST',
requestURL: '',
requestURL: '', // fixme: should be apiURL etc
}, options);
function getUserAgent() {
@ -198,6 +198,21 @@ requires
};
that.api = {
api: function(callback) {
Ox.Request.send({
url: self.options.requestURL,
data: {
action: 'api'
},
callback: callback
});
},
cancel: function(id) {
Ox.Request.cancel(id);
}
};
that.launch = function(callback) {
var time = +new Date(),
userAgent = getUserAgent(),
@ -215,7 +230,26 @@ requires
$.getScript('http://maps.google.com/maps/api/js?callback=google&sensor=false', function() {
$.getJSON(self.options.config, function(data) {
var config = data;
that.request(self.options.init, getUserData(), function(data) {
that.api.api(function(result) {
$.each(result.data.actions, function(i, action) {
that.api[action] = function(data, callback) {
if (arguments.length == 1) {
callback = data;
data = {};
}
console.log('api', action, data)
console.log('sending', self.options.requestURL, {action: action, data: data})
return Ox.Request.send({
url: self.options.requestURL,
data: {
action: action,
data: JSON.stringify(data)
},
callback: callback
});
};
});
that.api[self.options.init](getUserData(), function(data) {
var user = data.data.user;
$(function() {
var $div = $body.find('div');
@ -234,9 +268,10 @@ requires
});
});
});
});
}
function stop() {
that.request(self.options.init, getUserData(), function() {});
that.request.send(self.options.init, getUserData(), function() {});
}
return that;
};
@ -245,21 +280,6 @@ requires
return Ox.getset(self.options, Array.prototype.slice.call(arguments), self.change, that);
};
that.request = function(action, data, callback) {
if (arguments.length == 2) {
callback = data;
data = {};
}
return Ox.Request.send({
url: self.options.requestURL,
data: {
action: action,
data: JSON.stringify(data)
},
callback: callback
});
};
return that;
};
@ -288,7 +308,7 @@ requires
function removeEvent(id, type, event, callback) {
var focused = type == 'normal' || Ox.Focus.focused() == id,
toString = (callback || '').toString();
Ox.print('removeEvent', id, type, event, callback);
Ox.print('removeEvent', id, type, event/*, callback*/);
if (events[id] && events[id][type] && (!event || events[id][type][event])) {
$.each(events[id][type], function(e, fns) {
if (!event || event == e) {
@ -642,7 +662,7 @@ requires
Ox.Request = function() {
// fixme: do we want, instead of request('find', data, callback),
// something like server.find(data, callback)?
// something like api.find(data, callback)?
var cache = {},
pending = {},
@ -5912,7 +5932,7 @@ requires
keys: [],
orientation: 'vertical',
pageLength: 100,
request: function() {}, // (sort:, range:, callback:), without parameter returns {items, size etc.}
request: function() {}, // (data, callback), without data returns {items, size etc.}
//rowLength: 1,
sort: [],
type: 'text',
@ -6145,12 +6165,11 @@ requires
// fixme: optimize: send non-selected ids if more than half of the items are selected
if (self.selected.length /*&& self.selected.length < self.listLength*/) {
self.requests.push(self.options.request({
callback: getPositionsCallback,
ids: $.map(self.selected, function(v, i) {
return self.ids[v];
}),
sort: self.options.sort
}));
}, getPositionsCallback));
} else {
getPositionsCallback();
}
@ -6229,7 +6248,10 @@ requires
self.pageLength : self.listLength % self.pageLength)];
if (Ox.isUndefined(self.$pages[page])) {
self.requests.push(self.options.request({
callback: function(result) {
keys: keys,
range: range,
sort: self.options.sort
}, function(result) {
self.$pages[page] = new Ox.ListPage()
.css({
width: self.pageWidth + 'px'
@ -6274,10 +6296,6 @@ requires
}
self.$pages[page].appendTo(that.$content);
!Ox.isUndefined(callback) && callback();
},
keys: keys,
range: range,
sort: self.options.sort
}));
} else {
self.$pages[page].appendTo(that.$content);
@ -6559,8 +6577,7 @@ requires
function updateQuery() {
clear();
self.requests.push(self.options.request({
callback: function(result) {
self.requests.push(self.options.request({}, function(result) {
var keys = {};
that.triggerEvent('load', result.data);
self.rowLength = getRowLength();
@ -6581,7 +6598,6 @@ requires
height: self.listHeight + 'px'
});
getPositions();
}
}));
}