luci-mod-system: sshkeys.js: explicitely require ui.js
authorJo-Philipp Wich <jo@mein.io>
Sun, 3 Nov 2019 17:03:01 +0000 (18:03 +0100)
committerJo-Philipp Wich <jo@mein.io>
Sun, 3 Nov 2019 17:03:01 +0000 (18:03 +0100)
While ui.js is implicitely autoloaded by other classes, we need to require
it directly in the view to avoid race conditions during rendering.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-system/htdocs/luci-static/resources/view/system/sshkeys.js

index 05d41b0dde49d1ae3ec4bbd5341c75170edad861..8b9673ae114878484e6a861ebe05fe46d449ac62 100644 (file)
@@ -1,5 +1,6 @@
 'use strict';
 'require fs';
+'require ui';
 
 var SSHPubkeyDecoder = L.Class.singleton({
        lengthDecode: function(s, off)
@@ -119,8 +120,8 @@ function renderKeys(keys) {
 function saveKeys(keys) {
        return fs.write('/etc/dropbear/authorized_keys', keys.join('\n') + '\n', 384 /* 0600 */)
                .then(renderKeys.bind(this, keys))
-               .catch(function(e) { L.ui.addNotification(null, E('p', e.message)) })
-               .finally(L.ui.hideModal);
+               .catch(function(e) { ui.addNotification(null, E('p', e.message)) })
+               .finally(ui.hideModal);
 }
 
 function addKey(ev) {
@@ -138,13 +139,13 @@ function addKey(ev) {
        });
 
        if (keys.indexOf(key) !== -1) {
-               L.ui.showModal(_('Add key'), [
+               ui.showModal(_('Add key'), [
                        E('div', { class: 'alert-message warning' }, _('The given SSH public key has already been added.')),
                        E('div', { class: 'right' }, E('div', { class: 'btn', click: L.hideModal }, _('Close')))
                ]);
        }
        else if (!pubkey) {
-               L.ui.showModal(_('Add key'), [
+               ui.showModal(_('Add key'), [
                        E('div', { class: 'alert-message warning' }, _('The given SSH public key is invalid. Please supply proper public RSA or ECDSA keys.')),
                        E('div', { class: 'right' }, E('div', { class: 'btn', click: L.hideModal }, _('Close')))
                ]);
@@ -178,7 +179,7 @@ function removeKey(ev) {
                E('div', { class: 'right' }, [
                        E('div', { class: 'btn', click: L.hideModal }, _('Cancel')),
                        ' ',
-                       E('div', { class: 'btn danger', click: L.ui.createHandlerFn(this, saveKeys, keys) }, _('Delete key')),
+                       E('div', { class: 'btn danger', click: ui.createHandlerFn(this, saveKeys, keys) }, _('Delete key')),
                ])
        ]);
 }
@@ -232,7 +233,7 @@ return L.view.extend({
                                }),
                                E('button', {
                                        'class': 'cbi-button',
-                                       'click': L.ui.createHandlerFn(this, addKey)
+                                       'click': ui.createHandlerFn(this, addKey)
                                }, _('Add key'))
                        ])
                ]);
@@ -242,7 +243,7 @@ return L.view.extend({
                        if (pubkey)
                                list.insertBefore(E('div', {
                                        class: 'item',
-                                       click: L.ui.createHandlerFn(this, removeKey),
+                                       click: ui.createHandlerFn(this, removeKey),
                                        'data-key': key
                                }, [
                                        E('strong', pubkey.comment || _('Unnamed key')), E('br'),