add anchors to api

This commit is contained in:
j 2013-03-04 12:00:00 +00:00
parent 6b6e5df976
commit ec88003c30

View file

@ -3,7 +3,9 @@
pandora.ui.apiDialog = function() { pandora.ui.apiDialog = function() {
var actions, var selected = pandora.user.ui.hash && pandora.user.ui.hash.anchor
? pandora.user.ui.hash.anchor : '',
actions,
$loading = Ox.Element() $loading = Ox.Element()
.append( .append(
$('<img>') $('<img>')
@ -40,31 +42,37 @@ pandora.ui.apiDialog = function() {
maximizeButton: true, maximizeButton: true,
minHeight: 256, minHeight: 256,
minWidth: 576, minWidth: 576,
removeOnClose: true,
title: 'API Documentation', title: 'API Documentation',
width: Math.round(window.innerWidth * 0.75) width: Math.round(window.innerWidth * 0.75)
}) })
.bindEvent({ .bindEvent({
close: function() { close: function() {
pandora.UI.set({page: ''}); pandora.UI.set({page: '', 'hash.anchor': ''});
}, },
resize: function() { resize: function() {
$list.size(); $list.size();
},
'pandora_hash.anchor': function(data) {
pandora.user.ui.page == 'api' && that.select(data.value);
} }
}), }),
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>'; 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) { pandora.api.api({docs: true, code: true}, function(results) {
var items = []; var items = [{
id: '',
title: pandora.site.site.name + ' API',
sort: 'aaa'
}];
actions = results.data.actions; actions = results.data.actions;
Ox.forEach(results.data.actions, function(v, k) { Ox.forEach(results.data.actions, function(v, k) {
items.push({ items.push({
'id': k, 'id': k,
'title': k 'title': k,
'sort': k
}); });
}); });
items.sort(function (a, b) {
return a.name > b.name ? 1 : a.name == b.name ? 0 : -1;
});
$list = Ox.TableList({ $list = Ox.TableList({
_tree: true, _tree: true,
@ -80,11 +88,14 @@ pandora.ui.apiDialog = function() {
min: 1, min: 1,
scrollbarVisible: true, scrollbarVisible: true,
selected: [], selected: [],
sort: [{key: 'title', operator: '+'}], sort: [{key: 'sort', operator: '+'}],
unique: 'id' unique: 'id'
}) })
.bindEvent({ .bindEvent({
select: selectSection select: function(data) {
var id = data.ids[0];
pandora.UI.set({'hash.anchor': id});
}
}); });
$text = Ox.Element() $text = Ox.Element()
@ -107,10 +118,9 @@ pandora.ui.apiDialog = function() {
}); });
function selectSection(data) { that.select = function(id) {
if (data.ids.length) { if (id) {
$text.html(''); $text.html('');
data.ids.forEach(function(id) {
$text.append( $text.append(
$('<h2>') $('<h2>')
.html(id) .html(id)
@ -148,11 +158,12 @@ pandora.ui.apiDialog = function() {
.css({ .css({
borderWidth: '1px', borderWidth: '1px',
}).appendTo($text).hide(); }).appendTo($text).hide();
});
} else { } else {
$text.html(overview); $text.html(overview);
} }
return that;
} }
return that; return that;
}; };