luci-base: luci.js: catch base class loading errors
authorJo-Philipp Wich <jo@mein.io>
Mon, 1 Apr 2019 14:36:30 +0000 (16:36 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sun, 7 Jul 2019 13:36:24 +0000 (15:36 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/luci.js

index 767d013d79bf9e71fd2344738d9184bc4d2caaf7..61c3e8274a2114c43a5d0e50fff017e27720524e 100644 (file)
        LuCI = Class.extend({
                __name__: 'LuCI',
                __init__: function(env) {
+
+                       document.querySelectorAll('script[src$="/luci.js"]').forEach(function(s) {
+                               env.base_url = s.getAttribute('src').replace(/\/luci\.js$/, '');
+                       });
+
+                       if (env.base_url == null)
+                               this.error('InternalError', 'Cannot find url of luci.js');
+
                        Object.assign(this.env, env);
 
                        document.addEventListener('poll-start', function(ev) {
                                domReady,
                                this.require('ui'),
                                this.require('form')
-                       ]).then(this.setupDOM.bind(this)).catch(function(error) {
-                               alert('LuCI class loading error:\n' + error);
-                       });
+                       ]).then(this.setupDOM.bind(this)).catch(this.error);
 
                        originalCBIInit = window.cbi_init;
                        window.cbi_init = function() {};
                                return classes[name];
                        }
 
-                       document.querySelectorAll('script[src$="/luci.js"]').forEach(function(s) {
-                               url = '%s/%s.js'.format(
-                                       s.getAttribute('src').replace(/\/luci\.js$/, ''),
-                                       name.replace(/\./g, '/'));
-                       });
-
-                       if (url == null)
-                               L.error('InternalError', 'Cannot find url of luci.js');
-
+                       url = '%s/%s.js'.format(L.env.base_url, name.replace(/\./g, '/'));
                        from = [ name ].concat(from);
 
                        var compileClass = function(res) {