]> git.proxmox.com Git - pve2-api-doc.git/blobdiff - data/PVEAPI.js
add usage information
[pve2-api-doc.git] / data / PVEAPI.js
index 664878cfae66f477895170a16d4ad4e9a243c762..ff3cd447fde239547a2a3eb8368e0df8db937783 100644 (file)
@@ -1,9 +1,3 @@
-Ext.require([
-    'Ext.tree.*',
-    'Ext.data.*',
-    'Ext.window.MessageBox'
-]);
-
 // avoid errors when running without development tools
 if (!Ext.isDefined(Ext.global.console)) {   
     var console = { 
@@ -53,7 +47,7 @@ Ext.onReady(function() {
 
        metaData.style = 'white-space:pre-wrap;'
 
-       return  value;
+       return Ext.htmlEncode(value);
     };
 
     var render_type = function(value, metaData, record) {
@@ -85,18 +79,35 @@ Ext.onReady(function() {
     var render_docu = function(data) {
        var md = data.info;
 
-       console.log(data);
+       // console.dir(data);
 
        var items = [];
 
+       var clicmdhash = {
+           GET: 'get',
+           POST: 'create',
+           PUT: 'set',
+           DELETE: 'delete'
+       };
+
        Ext.Array.each(['GET', 'POST', 'PUT', 'DELETE'], function(method) {
            var info = md[method];
            if (info) {
 
+               var usage = "";
+
+               usage += "<table><tr><td>HTTP:&nbsp;&nbsp;&nbsp;</td><td>" + method + " /api2/json" + data.path + "</td></tr><tr><td>&nbsp</td></tr>";
+               usage += "<tr><td>CLI:</td><td>pvesh " + clicmdhash[method] + " " + data.path + "</td></tr></table>";
+
                var sections = [
                    {
                        title: 'Description',
-                       html: info.description,
+                       html: Ext.htmlEncode(info.description),
+                       bodyPadding: 10
+                   },
+                   {
+                       title: 'Usage',
+                       html: usage,
                        bodyPadding: 10
                    }
                ];
@@ -181,23 +192,29 @@ Ext.onReady(function() {
                var permhtml = '';
                if (!info.permissions) {
                    permhtml = "Root only.";
-               } else if (info.permissions.user) {
-                   if (info.permissions.user === 'world') {
-                       permhtml += "Accessible without any authententification.";
-                   } else if (info.permissions.user === 'all') {
-                       permhtml += "Accessible by all authententicated users.";
+               } else {
+                   if (info.permissions.description) {
+                       permhtml += "<div style='white-space:pre-wrap;padding-bottom:10px;'>" +
+                           Ext.htmlEncode(info.permissions.description) + "</div>";
+                   }
+
+                   if (info.permissions.user) {
+                       if (!info.permissions.description) {
+                           if (info.permissions.user === 'world') {
+                               permhtml += "Accessible without any authententification.";
+                           } else if (info.permissions.user === 'all') {
+                               permhtml += "Accessible by all authententicated users.";
+                           } else {
+                               permhtml += 'Onyl accessible by user "' + 
+                                   info.permissions.user + '"';
+                           }
+                       }
+                   } else if (info.permissions.check) {
+                       permhtml += "<pre>Check: " + 
+                           Ext.htmlEncode(Ext.JSON.encode(info.permissions.check))  + "</pre>";
                    } else {
-                       permhtml += 'Onyl accessible by user "' + 
-                           info.permissions.user + '"';
+                       permhtml += "Unknown systax!";
                    }
-               } else if (info.permissions.path && info.permissions.privs) {
-                   permhtml += '<table><tr><td>Path:</td><td>' + 
-                       info.permissions.path + '</td></tr>' +
-                       '<tr><td style="padding-right:10px;">Permissions:</td><td>' + 
-                       info.permissions.privs.join(' ') + 
-                       '</td></tr></table>';
-               } else {
-                   permhtml += "Root only.";
                }
 
                sections.push({