pandora/static/js/pandora.api.js

114 lines
3.3 KiB
JavaScript
Raw Normal View History

/***
Pandora API
***/
var app = new Ox.App({
apiURL: '/api/',
2011-01-22 19:29:56 +00:00
init: 'init',
}).launch(function(data) {
Ox.print('data', data)
app.config = data.config;
app.user = data.user;
if (app.user.group == 'guest') {
app.user = data.config.user;
$.browser.safari && Ox.theme('modern');
}
app.$body = $('body');
app.$document = $(document);
app.$window = $(window);
//app.$body.html('');
app.$ui = {};
app.$ui.actionList = constructList();
app.$ui.actionInfo = Ox.Container().css({padding: '8px'});
2011-01-14 10:55:05 +00:00
app.api.api({docs: true}, function(results) {
app.actions = results.data.actions;
2010-12-24 13:07:52 +00:00
if(document.location.hash) {
app.$ui.actionList.triggerEvent('select', {ids: document.location.hash.substring(1).split(',')});
}
});
2011-01-22 12:39:55 +00:00
app.$ui.actionList.$body.css({overflowX: 'hidden', overflowY: 'auto'});
var $main = new Ox.SplitPanel({
elements: [
{
element: app.$ui.actionList,
size: 160
},
{
element: app.$ui.actionInfo,
}
],
orientation: 'horizontal'
});
$main.appendTo(app.$body);
});
function constructList() {
return new Ox.TextList({
columns: [
{
align: "left",
id: "name",
operator: "+",
title: "Name",
unique: true,
visible: true,
width: 140
},
],
columnsMovable: false,
columnsRemovable: false,
id: 'actionList',
request: function(data, callback) {
2011-01-22 19:09:02 +00:00
function _sort(a, b) {
if(a.name > b.name)
return 1;
else if(a.name == b.name)
return 0;
return -1;
}
if(!data.keys) {
2010-12-24 10:14:13 +00:00
app.api.api(function(results) {
var items = [];
2011-01-13 19:40:50 +00:00
$.each(results.data.actions, function(i, k) {items.push({'name': i})});
2011-01-22 19:09:02 +00:00
items.sort(_sort);
var result = {'data': {'items': items.length}};
callback(result);
});
} else {
2010-12-24 10:14:13 +00:00
app.api.api(function(results) {
var items = [];
2011-01-13 19:40:50 +00:00
$.each(results.data.actions, function(i, k) {items.push({'name': i})});
2011-01-22 19:09:02 +00:00
items.sort(_sort);
var result = {'data': {'items': items}};
callback(result);
});
}
},
sort: [
{
key: "name",
operator: "+"
}
]
}).bindEvent({
select: function(event, data) {
2010-12-25 10:14:38 +00:00
var info = $('<div>').addClass('OxSelectable'),
2010-12-24 10:31:20 +00:00
hash = '#';
$.each(data.ids, function(v, k) {
console.log(k)
info.append($("<h2>").html(k));
2011-01-14 10:55:05 +00:00
info.append($('<pre>').html(app.actions[k]['doc'].replace('/\n/<br>\n/g')));
2010-12-24 10:31:20 +00:00
hash += k + ','
});
2010-12-24 10:31:20 +00:00
document.location.hash = hash.substring(0, hash.length-1);
app.$ui.actionInfo.html(info);
}
});
}