forked from 0x2620/pandora
move api to apiDialog
This commit is contained in:
parent
e602ca9dc9
commit
c3abc71fd0
5 changed files with 189 additions and 195 deletions
158
static/js/pandora/apiDialog.js
Normal file
158
static/js/pandora/apiDialog.js
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
||||
'use strict';
|
||||
|
||||
pandora.ui.apiDialog = function() {
|
||||
|
||||
var actions,
|
||||
$loading = Ox.Element()
|
||||
.append(
|
||||
$('<img>')
|
||||
.attr({src: Ox.UI.getImageURL('symbolLoadingAnimated')})
|
||||
.css({
|
||||
position: 'absolute',
|
||||
width: '32px',
|
||||
height: '32px',
|
||||
left: 0,
|
||||
top: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
margin: 'auto'
|
||||
})
|
||||
),
|
||||
|
||||
$panel, $list, $text,
|
||||
|
||||
that = Ox.Dialog({
|
||||
buttons: [
|
||||
Ox.Button({
|
||||
id: 'close',
|
||||
title: 'Close'
|
||||
}).bindEvent({
|
||||
click: function() {
|
||||
that.close();
|
||||
}
|
||||
})
|
||||
],
|
||||
closeButton: true,
|
||||
content: $loading,
|
||||
height: Math.round((window.innerHeight - 24) * 0.75),
|
||||
keys: {escape: 'close'},
|
||||
maximizeButton: true,
|
||||
minHeight: 256,
|
||||
minWidth: 576,
|
||||
title: 'API Documentation',
|
||||
width: Math.round(window.innerWidth * 0.75)
|
||||
})
|
||||
.bindEvent({
|
||||
close: function() {
|
||||
pandora.UI.set({page: ''});
|
||||
},
|
||||
resize: function() {
|
||||
$list.size();
|
||||
}
|
||||
}),
|
||||
overview = '<div class="OxSelectable"><h2>Pan.do/ra API Overview</h2>use this api in the browser with <a href="/static/oxjs/demos/doc2/index.html#Ox.App">Ox.app</a> or use <a href="http://code.0x2620.org/pandora_client">pandora_client</a> it in python. Further description of the api can be found <a href="https://wiki.0x2620.org/wiki/pandora/API">on the wiki</a></div>';
|
||||
|
||||
pandora.api.api({docs: true, code: true}, function(results) {
|
||||
var items = [];
|
||||
actions = results.data.actions;
|
||||
Ox.forEach(results.data.actions, function(v, k) {
|
||||
items.push({
|
||||
'id': k,
|
||||
'title': k
|
||||
});
|
||||
});
|
||||
items.sort(function (a, b) {
|
||||
return a.name > b.name ? 1 : a.name == b.name ? 0 : -1;
|
||||
});
|
||||
|
||||
$list = Ox.TableList({
|
||||
_tree: true,
|
||||
columns: [
|
||||
{
|
||||
id: 'title',
|
||||
visible: true,
|
||||
width: 192 - Ox.UI.SCROLLBAR_SIZE
|
||||
}
|
||||
],
|
||||
items: items,
|
||||
max: 1,
|
||||
min: 1,
|
||||
scrollbarVisible: true,
|
||||
selected: [],
|
||||
sort: [{key: 'title', operator: '+'}],
|
||||
unique: 'id'
|
||||
})
|
||||
.bindEvent({
|
||||
select: selectSection
|
||||
});
|
||||
|
||||
$text = Ox.Element()
|
||||
.css({
|
||||
padding: '16px',
|
||||
overflowY: 'auto'
|
||||
})
|
||||
.html(overview);
|
||||
|
||||
|
||||
$panel = Ox.SplitPanel({
|
||||
elements: [
|
||||
{element: $list, size: 192},
|
||||
{element: $text}
|
||||
],
|
||||
orientation: 'horizontal'
|
||||
});
|
||||
|
||||
that.options({content: $panel});
|
||||
|
||||
});
|
||||
|
||||
function selectSection(data) {
|
||||
if (data.ids.length) {
|
||||
$text.html('');
|
||||
data.ids.forEach(function(id) {
|
||||
$text.append(
|
||||
$('<h2>')
|
||||
.html(id)
|
||||
.css({
|
||||
marginBottom: '8px'
|
||||
})
|
||||
);
|
||||
var code = actions[id].code[1],
|
||||
f = actions[id].code[0],
|
||||
line = Math.round(Ox.last(f.split(':')) || 0),
|
||||
doc = actions[id].doc.replace('/\n/<br>\n/g'),
|
||||
$code, $doc;
|
||||
|
||||
$doc = Ox.SyntaxHighlighter({
|
||||
source: doc,
|
||||
})
|
||||
.appendTo($text);
|
||||
|
||||
Ox.Button({
|
||||
title: 'View Source (' + f + ')',
|
||||
}).bindEvent({
|
||||
click: function() {
|
||||
$code.toggle();
|
||||
}
|
||||
})
|
||||
.css({
|
||||
margin: '4px'
|
||||
})
|
||||
.appendTo($text);
|
||||
$code = Ox.SyntaxHighlighter({
|
||||
showLineNumbers: true,
|
||||
source: code,
|
||||
offset: line
|
||||
})
|
||||
.css({
|
||||
borderWidth: '1px',
|
||||
}).appendTo($text).hide();
|
||||
});
|
||||
} else {
|
||||
$text.html(overview);
|
||||
}
|
||||
}
|
||||
return that;
|
||||
|
||||
};
|
||||
|
|
@ -41,7 +41,7 @@ pandora.ui.appPanel = function() {
|
|||
// unless we're on page load, remove home screen
|
||||
pandora.$ui.home.fadeOutScreen();
|
||||
}
|
||||
['site', 'account', 'preferences', 'help'].forEach(function(dialog) {
|
||||
['site', 'account', 'preferences', 'help', 'api'].forEach(function(dialog) {
|
||||
pandora.$ui[dialog + 'Dialog'] && pandora.$ui[dialog + 'Dialog'].close();
|
||||
});
|
||||
if (pandora.$ui.tv) {
|
||||
|
|
@ -63,6 +63,8 @@ pandora.ui.appPanel = function() {
|
|||
}
|
||||
} else if (page == 'help') {
|
||||
pandora.$ui.helpDialog = pandora.ui.helpDialog().open();
|
||||
} else if (page == 'api') {
|
||||
pandora.$ui.apiDialog = pandora.ui.apiDialog().open();
|
||||
} else if (['signup', 'signin'].indexOf(page) > -1) {
|
||||
if (pandora.user.level == 'guest') {
|
||||
if (pandora.$ui.accountDialog && pandora.$ui.accountDialog.is(':visible')) {
|
||||
|
|
|
|||
|
|
@ -150,7 +150,8 @@ pandora.ui.mainMenu = function() {
|
|||
{ id: 'statistics', title: 'Statistics...', disabled: !pandora.site.capabilities.canManageUsers[pandora.user.level] }
|
||||
] },
|
||||
{ id: 'helpMenu', title: 'Help', items: [
|
||||
{ id: 'help', title: pandora.site.site.name + ' Help', keyboard: 'control ?' }
|
||||
{ id: 'help', title: pandora.site.site.name + ' Help', keyboard: 'control ?' },
|
||||
{ id: 'api', title: pandora.site.site.name + ' API' }
|
||||
] }
|
||||
],
|
||||
pandora.site.capabilities.canSeeDebugMenu[pandora.user.level]
|
||||
|
|
@ -285,7 +286,7 @@ pandora.ui.mainMenu = function() {
|
|||
click: function(data) {
|
||||
if ([
|
||||
'home', 'software', 'signup', 'signin', 'signout',
|
||||
'preferences', 'tv', 'help'
|
||||
'preferences', 'tv', 'help', 'api'
|
||||
].concat(
|
||||
pandora.site.sitePages.map(function(page) {
|
||||
return page.id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue