]> git.proxmox.com Git - pmg-gui.git/commitdiff
use new proxmoxlib.js (package proxmox-widget-toolkit)
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 30 Jan 2017 12:43:32 +0000 (13:43 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 30 Jan 2017 12:43:32 +0000 (13:43 +0100)
index.html
js/SystemConfiguration.js
js/Utils.js
js/Workspace.js

index 42e3f4aa5d2c7a4e03c7970d47d77e4fd0e70139..7e18a6a14d8f2e0aafa3dd2c9b0bee98ad7dbbe0 100644 (file)
     <script type="text/javascript" src="/pve2/ext6/ext-all.js"></script>
     <script type="text/javascript" src="/pve2/ext6/charts.js"></script>
     [% END %]
+    <script type="text/javascript">
+      Proxmox = {
+        Setup: { auth_cookie_name: 'PMGAuthCookie' },
+        NodeName: '[% nodename %]',
+        UserName: '[% username %]',
+        CSRFPreventionToken: '[% csrftoken %]'
+      };
+    </script>
+    <script type="text/javascript" src="/proxmoxlib.js"></script>
     <script type="text/javascript" src="/pve2/js/pmgmanagerlib.js"></script>
     <script type="text/javascript" src="/pve2/ext6/locale/locale-[% lang %].js"></script>
     <script type="text/javascript">
-      if (typeof(PMG) === 'undefined') PMG = {};
-      PMG.UserName = '[% username %]'
-      PMG.CSRFPreventionToken = '[% csrftoken %]';
       Ext.History.fieldid = 'x-history-field';
       Ext.onReady(function() { Ext.create('PMG.StdWorkspace');});
     </script>    
index 8c6af2dd38434c018e16988cfd8806f3ceb2061c..39b518b3bdfb66f045e777f0cd929bcf78ac1bcb 100644 (file)
@@ -10,8 +10,9 @@ Ext.define('PMG.SystemConfiguration', {
            html: "Network"
        },
        {
-            title: gettext('Time'),
-           html: "Time"
+           title: gettext('Time'),
+            xtype: 'proxmoxNodeTimeView',
+           nodename: Proxmox.NodeName
        },
        {
             title: gettext('Backup'),
index 3e75ccd41c815932a2bdd056c35ebcc12e35dbaf..ab033ddb052ff57bb287aa447fe5b3f656a110ea 100644 (file)
 Ext.ns('PMG');
 
-// TODO: implement gettext
-function gettext(buf) { return buf; }
-
-// avoid errors related to Accessible Rich Internet Applications
-// (access for people with disabilities)
-// TODO reenable after all components are upgraded
-Ext.enableAria = false;
-Ext.enableAriaButtons = false;
-Ext.enableAriaPanels = false;
-
-// avoid errors when running without development tools
-if (!Ext.isDefined(Ext.global.console)) {
-    var console = {
-       dir: function() {},
-       log: function() {}
-    };
-}
 console.log("Starting PMG Manager");
 
-Ext.Ajax.defaultHeaders = {
-    'Accept': 'application/json'
-};
-
-Ext.Ajax.on('beforerequest', function(conn, options) {
-    if (PMG.CSRFPreventionToken) {
-       if (!options.headers) {
-           options.headers = {};
-       }
-       options.headers.CSRFPreventionToken = PMG.CSRFPreventionToken;
-    }
-});
-
-Ext.define('PMG.Utils', { utilities: {
 
+Ext.define('PMG.Utils', {
+    singleton: true,
     // this singleton contains miscellaneous utilities
 
-    authOK: function() {
-       return (PMG.UserName !== '') && Ext.util.Cookies.get('PMGAuthCookie');
-    },
-
-    authClear: function() {
-       Ext.util.Cookies.clear("PMGAuthCookie");
-    },
-
-    // comp.setLoading() is buggy in ExtJS 4.0.7, so we
-    // use el.mask() instead
-    setErrorMask: function(comp, msg) {
-       var el = comp.el;
-       if (!el) {
-           return;
-       }
-       if (!msg) {
-           el.unmask();
-       } else {
-           if (msg === true) {
-               el.mask(gettext("Loading..."));
-           } else {
-               el.mask(msg);
-           }
-       }
-    },
-
-    extractRequestError: function(result, verbose) {
-       var msg = gettext('Successful');
-
-       if (!result.success) {
-           msg = gettext("Unknown error");
-           if (result.message) {
-               msg = result.message;
-               if (result.status) {
-                   msg += ' (' + result.status + ')';
-               }
-           }
-           if (verbose && Ext.isObject(result.errors)) {
-               msg += "<br>";
-               Ext.Object.each(result.errors, function(prop, desc) {
-                   msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " +
-                       Ext.htmlEncode(desc);
-               });
-           }
-       }
-
-       return msg;
-    },
-
-    // Ext.Ajax.request
-    API2Request: function(reqOpts) {
-
-       var newopts = Ext.apply({
-           waitMsg: gettext('Please wait...')
-       }, reqOpts);
-
-       if (!newopts.url.match(/^\/api2/)) {
-           newopts.url = '/api2/extjs' + newopts.url;
-       }
-       delete newopts.callback;
-
-       var createWrapper = function(successFn, callbackFn, failureFn) {
-           Ext.apply(newopts, {
-               success: function(response, options) {
-                   if (options.waitMsgTarget) {
-                       options.waitMsgTarget.setLoading(false);
-                   }
-                   var result = Ext.decode(response.responseText);
-                   response.result = result;
-                   if (!result.success) {
-                       response.htmlStatus = PMG.Utils.extractRequestError(result, true);
-                       Ext.callback(callbackFn, options.scope, [options, false, response]);
-                       Ext.callback(failureFn, options.scope, [response, options]);
-                       return;
-                   }
-                   Ext.callback(callbackFn, options.scope, [options, true, response]);
-                   Ext.callback(successFn, options.scope, [response, options]);
-               },
-               failure: function(response, options) {
-                   if (options.waitMsgTarget) {
-                       options.waitMsgTarget.setLoading(false);
-                   }
-                   response.result = {};
-                   try {
-                       response.result = Ext.decode(response.responseText);
-                   } catch(e) {}
-                   var msg = gettext('Connection error') + ' - server offline?';
-                   if (response.aborted) {
-                       msg = gettext('Connection error') + ' - aborted.';
-                   } else if (response.timedout) {
-                       msg = gettext('Connection error') + ' - Timeout.';
-                   } else if (response.status && response.statusText) {
-                       msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText;
-                   }
-                   response.htmlStatus = msg;
-                   Ext.callback(callbackFn, options.scope, [options, false, response]);
-                   Ext.callback(failureFn, options.scope, [response, options]);
-               }
-           });
-       };
-
-       createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure);
-
-       var target = newopts.waitMsgTarget;
-       if (target) {
-           // Note: ExtJS bug - this does not work when component is not rendered
-           target.setLoading(newopts.waitMsg);
-       }
-       Ext.Ajax.request(newopts);
-    },
-
     yesText: gettext('Yes'),
-    noText: gettext('No') 
-
-    },
+    noText: gettext('No'),
                          
-    singleton: true,
     constructor: function() {
        var me = this;
-       Ext.apply(me, me.utilities);
-
-       var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
-       var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
-       var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
-       var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
-
-
-       me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
-       me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
-
-       var IPV6_REGEXP = "(?:" +
-           "(?:(?:"                                                  + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
-           "(?:(?:"                                         +   "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
-           "(?:(?:(?:"                           + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
-           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
-           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
-           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
-           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" +                         ")" + IPV6_LS32 + ")|" +
-           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" +                         ")" + IPV6_H16  + ")|" +
-           "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" +                         ")"             + ")"  +
-           ")";
-
-       me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
-       me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
-       me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
-
-       me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
-
-       var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))";
-       me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
 
-       me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
-       me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
-       me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
+       // do whatever you want here
     }
 });
index db1c9936fb24a06332528ba3e6b7a423f4de0be2..a89ac7af1329246f8be6347ed4421fa2fae52d17 100644 (file)
@@ -20,8 +20,8 @@ Ext.define('PMG.Workspace', {
        var me = this;
 
        me.loginData = loginData;
-       PMG.CSRFPreventionToken = loginData.CSRFPreventionToken;
-       PMG.UserName = loginData.username;
+       Proxmox.CSRFPreventionToken = loginData.CSRFPreventionToken;
+       Proxmox.UserName = loginData.username;
 
        // creates a session cookie (expire = null)
        // that way the cookie gets deleted after browser window close
@@ -33,8 +33,8 @@ Ext.define('PMG.Workspace', {
     showLogin: function() {
        var me = this;
 
-       PMG.Utils.authClear();
-       PMG.UserName = null;
+       Proxmox.Utils.authClear();
+       Proxmox.UserName = null;
        me.loginData = null;
 
        if (!me.login) {
@@ -63,7 +63,7 @@ Ext.define('PMG.Workspace', {
 
        me.callParent();
 
-        if (!PMG.Utils.authOK()) {
+        if (!Proxmox.Utils.authOK()) {
            me.showLogin();
        } else {
            if (me.loginData) {
@@ -73,14 +73,14 @@ Ext.define('PMG.Workspace', {
 
        Ext.TaskManager.start({
            run: function() {
-               var ticket = PMG.Utils.authOK();
-               if (!ticket || !PMG.UserName) {
+               var ticket = Proxmox.Utils.authOK();
+               if (!ticket || !Proxmox.UserName) {
                    return;
                }
 
                Ext.Ajax.request({
                    params: {
-                       username: PMG.UserName,
+                       username: Proxmox.UserName,
                        password: ticket
                    },
                    url: '/api2/json/access/ticket',
@@ -110,7 +110,7 @@ Ext.define('PMG.StdWorkspace', {
        me.updateUserInfo();
 
        if (loginData) {
-           PMG.Utils.API2Request({
+           Proxmox.Utils.API2Request({
                url: '/version',
                method: 'GET',
                success: function(response) {
@@ -126,8 +126,8 @@ Ext.define('PMG.StdWorkspace', {
 
        var ui = me.query('#userinfo')[0];
 
-       if (PMG.UserName) {
-           var msg =  Ext.String.format(gettext("You are logged in as {0}"), "'" + PMG.UserName + "'");
+       if (Proxmox.UserName) {
+           var msg =  Ext.String.format(gettext("You are logged in as {0}"), "'" + Proxmox.UserName + "'");
            ui.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg + '</div>');
        } else {
            ui.update('');