]>
git.proxmox.com Git - pve-docs.git/blob - api-viewer/PVEAPI.js
1 // avoid errors when running without development tools
2 if (!Ext
.isDefined(Ext
.global
.console
)) {
9 Ext
.onReady(function() {
11 Ext
.define('pve-param-schema', {
12 extend
: 'Ext.data.Model',
14 'name', 'type', 'typetext', 'description', 'verbose_description',
15 'enum', 'minimum', 'maximum', 'minLength', 'maxLength',
16 'pattern', 'title', 'requires', 'format', 'default',
17 'disallow', 'extends', 'links',
25 var store
= Ext
.create('Ext.data.TreeStore', {
26 model
: Ext
.define('pve-api-doc', {
27 extend
: 'Ext.data.Model',
29 'path', 'info', 'text',
45 var render_description = function(value
, metaData
, record
) {
46 var pdef
= record
.data
;
48 value
= pdef
.verbose_description
|| value
;
50 // TODO: try to render asciidoc correctly
52 metaData
.style
= 'white-space:pre-wrap;'
54 return Ext
.htmlEncode(value
);
57 var render_type = function(value
, metaData
, record
) {
58 var pdef
= record
.data
;
60 return pdef
['enum'] ? 'enum' : (pdef
.type
|| 'string');
63 var render_format = function(value
, metaData
, record
) {
64 var pdef
= record
.data
;
66 metaData
.style
= 'white-space:normal;'
69 return Ext
.htmlEncode(pdef
.typetext
);
72 return pdef
['enum'].join(' | ');
78 return Ext
.htmlEncode(pdef
.pattern
);
83 var render_docu = function(data
) {
97 Ext
.Array
.each(['GET', 'POST', 'PUT', 'DELETE'], function(method
) {
98 var info
= md
[method
];
103 usage
+= "<table><tr><td>HTTP: </td><td>" + method
+ " /api2/json" + data
.path
+ "</td></tr><tr><td> </td></tr>";
104 usage
+= "<tr><td>CLI:</td><td>pvesh " + clicmdhash
[method
] + " " + data
.path
+ "</td></tr></table>";
108 title
: 'Description',
109 html
: Ext
.htmlEncode(info
.description
),
119 if (info
.parameters
&& info
.parameters
.properties
) {
121 var pstore
= Ext
.create('Ext.data.Store', {
122 model
: 'pve-param-schema',
126 groupField
: 'optional',
135 Ext
.Object
.each(info
.parameters
.properties
, function(name
, pdef
) {
142 var groupingFeature
= Ext
.create('Ext.grid.feature.Grouping',{
143 enableGroupingMenu
: false,
144 groupHeaderTpl
: '<tpl if="groupValue">Optional</tpl><tpl if="!groupValue">Required</tpl>'
150 features
: [groupingFeature
],
165 renderer
: render_type
,
170 dataIndex
: 'default',
176 renderer
: render_format
,
180 header
: 'Description',
181 dataIndex
: 'description',
182 renderer
: render_description
,
192 var retinf
= info
.returns
;
193 var rtype
= retinf
.type
;
194 if (!rtype
&& retinf
.items
)
201 returnhtml
= '<pre>items: ' + Ext
.htmlEncode(JSON
.stringify(retinf
.items
, null, 4)) + '</pre>';
204 if (retinf
.properties
) {
205 returnhtml
= returnhtml
|| '';
206 returnhtml
+= '<pre>properties:' + Ext
.htmlEncode(JSON
.stringify(retinf
.properties
, null, 4));
210 title
: 'Returns: ' + rtype
,
217 if (!info
.permissions
) {
218 permhtml
= "Root only.";
220 if (info
.permissions
.description
) {
221 permhtml
+= "<div style='white-space:pre-wrap;padding-bottom:10px;'>" +
222 Ext
.htmlEncode(info
.permissions
.description
) + "</div>";
225 if (info
.permissions
.user
) {
226 if (!info
.permissions
.description
) {
227 if (info
.permissions
.user
=== 'world') {
228 permhtml
+= "Accessible without any authentication.";
229 } else if (info
.permissions
.user
=== 'all') {
230 permhtml
+= "Accessible by all authenticated users.";
232 permhtml
+= 'Onyl accessible by user "' +
233 info
.permissions
.user
+ '"';
236 } else if (info
.permissions
.check
) {
237 permhtml
+= "<pre>Check: " +
238 Ext
.htmlEncode(Ext
.JSON
.encode(info
.permissions
.check
)) + "</pre>";
240 permhtml
+= "Unknown systax!";
245 title
: 'Required permissions',
262 var ct
= Ext
.getCmp('docview');
263 ct
.setTitle("Path: " + data
.path
);
269 var tree
= Ext
.create('Ext.tree.Panel', {
270 title
: 'Resource Tree',
278 selectionchange: function(v
, selections
) {
281 var rec
= selections
[0];
282 render_docu(rec
.data
);
287 Ext
.create('Ext.container.Viewport', {
289 renderTo
: Ext
.getBody(),
294 title
: 'Documentation',