2010-11-26 15:07:24 +00:00
/ * * *
Pandora API
* * * /
2011-04-26 20:57:52 +00:00
Ox . load ( 'UI' , {
hideScreen : false ,
showScreen : true ,
theme : 'classic'
} , function ( ) {
2010-11-26 15:07:24 +00:00
var app = new Ox . App ( {
apiURL : '/api/' ,
2011-01-22 19:29:56 +00:00
init : 'init' ,
2011-09-17 17:40:15 +00:00
} ) . bindEvent ( 'load' , function ( data ) {
2011-05-30 13:46:33 +00:00
app . site = data . site ;
2010-11-26 15:07:24 +00:00
app . user = data . user ;
2011-07-24 13:32:28 +00:00
app . site . default _info = '<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>' ;
2010-11-26 15:07:24 +00:00
app . $body = $ ( 'body' ) ;
app . $document = $ ( document ) ;
app . $window = $ ( window ) ;
//app.$body.html('');
2011-04-26 20:57:52 +00:00
Ox . UI . hideLoadingScreen ( ) ;
2010-11-26 15:07:24 +00:00
app . $ui = { } ;
app . $ui . actionList = constructList ( ) ;
2011-05-28 11:18:28 +00:00
app . $ui . actionInfo = Ox . Container ( ) . css ( { padding : '16px' } ) . html ( app . site . default _info ) ;
2010-11-26 15:07:24 +00:00
2011-01-26 13:25:26 +00:00
app . api . api ( { docs : true , code : true } , function ( results ) {
2011-01-14 10:55:05 +00:00
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 ( ',' ) } ) ;
}
} ) ;
2010-11-26 15:07:24 +00:00
2011-01-26 12:12:51 +00:00
var $left = new Ox . SplitPanel ( {
elements : [
{
2011-01-26 12:28:37 +00:00
element : new Ox . Element ( ) . append ( new Ox . Element ( )
2011-05-28 11:18:28 +00:00
. html ( app . site . site . name + ' API' ) . css ( {
2011-01-26 12:28:37 +00:00
'padding' : '4px' ,
} ) ) . css ( {
2011-01-26 12:12:51 +00:00
'background-color' : '#ddd' ,
'font-weight' : 'bold' ,
} ) ,
size : 24
} ,
{
element : app . $ui . actionList
}
] ,
orientation : 'vertical'
} ) ;
2010-11-26 15:07:24 +00:00
var $main = new Ox . SplitPanel ( {
elements : [
{
2011-01-26 12:12:51 +00:00
element : $left ,
2010-11-26 15:07:24 +00:00
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' ,
2011-02-25 10:23:46 +00:00
items : 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 ;
}
2011-09-17 18:36:30 +00:00
if ( ! data . keys ) {
2010-12-24 10:14:13 +00:00
app . api . api ( function ( results ) {
2010-11-26 15:07:24 +00:00
var items = [ ] ;
2011-09-17 18:36:30 +00:00
Ox . forEach ( results . data . actions , function ( v , k ) {
2011-09-19 12:29:55 +00:00
items . push ( { 'name' : k } )
2011-09-17 18:36:30 +00:00
} ) ;
2011-01-22 19:09:02 +00:00
items . sort ( _sort ) ;
2010-11-26 15:07:24 +00:00
var result = { 'data' : { 'items' : items . length } } ;
callback ( result ) ;
} ) ;
} else {
2010-12-24 10:14:13 +00:00
app . api . api ( function ( results ) {
2010-11-26 15:07:24 +00:00
var items = [ ] ;
2011-09-17 18:36:30 +00:00
Ox . forEach ( results . data . actions , function ( v , k ) {
2011-09-19 12:29:55 +00:00
items . push ( { 'name' : k } )
2011-09-17 18:36:30 +00:00
} ) ;
2011-01-22 19:09:02 +00:00
items . sort ( _sort ) ;
2010-11-26 15:07:24 +00:00
var result = { 'data' : { 'items' : items } } ;
callback ( result ) ;
} ) ;
}
} ,
2011-01-26 12:12:51 +00:00
scrollbarVisible : true ,
2010-11-26 15:07:24 +00:00
sort : [
{
key : "name" ,
operator : "+"
}
]
} ) . bindEvent ( {
2011-09-17 17:40:15 +00:00
select : function ( data ) {
2010-12-25 10:14:38 +00:00
var info = $ ( '<div>' ) . addClass ( 'OxSelectable' ) ,
2010-12-24 10:31:20 +00:00
hash = '#' ;
2011-01-26 12:12:51 +00:00
if ( data . ids . length )
2011-09-17 18:36:30 +00:00
data . ids . forEach ( function ( id ) {
info . append ( $ ( "<h2>" ) . html ( id ) ) ;
2011-01-26 13:58:13 +00:00
var $doc = $ ( '<pre>' )
2011-09-17 18:36:30 +00:00
. html ( app . actions [ id ] . doc . replace ( '/\n/<br>\n/g' ) )
2011-01-26 13:58:13 +00:00
. appendTo ( info ) ;
2011-09-17 18:36:30 +00:00
var $code = $ ( '<code class="python">' )
. html ( app . actions [ id ] . code [ 1 ] . replace ( '/\n/<br>\n/g' ) )
2011-01-26 13:58:13 +00:00
. hide ( ) ;
2011-12-28 13:31:48 +00:00
/ *
var $button = Ox . Button ( {
type : "image" ,
options : [
2011-05-30 14:24:56 +00:00
{ id : "one" , title : "right" } ,
{ id : "two" , title : "down" } ,
2011-01-26 13:25:26 +00:00
] ,
} )
. addClass ( "margin" )
. click ( function ( ) { $code . toggle ( ) } )
2011-12-28 13:31:48 +00:00
. appendTo ( info ) ;
* /
2011-09-19 12:29:55 +00:00
var f = app . actions [ id ] . code [ 0 ] ;
2011-12-28 13:31:48 +00:00
$ ( '<span>' )
. html ( ' View Source (' + f + ')' )
. click ( function ( ) { $code . toggle ( ) } )
. appendTo ( info )
2011-10-29 17:46:46 +00:00
$ ( '<pre>' ) . append ( $code ) . appendTo ( info )
2011-01-26 13:58:13 +00:00
hljs . highlightBlock ( $code [ 0 ] , ' ' ) ;
2011-09-17 18:36:30 +00:00
hash += id + ','
2011-01-26 12:12:51 +00:00
} ) ;
else
2011-05-28 11:18:28 +00:00
info . html ( app . site . default _info ) ;
2011-01-26 12:12:51 +00:00
2010-12-24 10:31:20 +00:00
document . location . hash = hash . substring ( 0 , hash . length - 1 ) ;
2010-11-26 15:07:24 +00:00
app . $ui . actionInfo . html ( info ) ;
}
} ) ;
}
2011-04-26 20:57:52 +00:00
} ) ;