Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/luci.git] / modules / luci-base / htdocs / luci-static / resources / luci.js
index 0b7ec6ea86d71d59a6bc22d9ae6d1c62aa78f4c3..4e3c8445a94dc0013a20708e4744f622e7c9c951 100644 (file)
                },
 
                handleReadyStateChange: function(resolveFn, rejectFn, ev) {
-                       var xhr = this.xhr;
+                       var xhr = this.xhr,
+                           duration = Date.now() - this.start;
 
                        if (xhr.readyState !== 4)
                                return;
 
                        if (xhr.status === 0 && xhr.statusText === '') {
-                               rejectFn.call(this, new Error('XHR request aborted by browser'));
+                               if (duration >= this.timeout)
+                                       rejectFn.call(this, new Error('XHR request timed out'));
+                               else
+                                       rejectFn.call(this, new Error('XHR request aborted by browser'));
                        }
                        else {
                                var response = new Response(
-                                       xhr, xhr.responseURL || this.url, Date.now() - this.start);
+                                       xhr, xhr.responseURL || this.url, duration);
 
                                Promise.all(Request.interceptors.map(function(fn) { return fn(response) }))
                                        .then(resolveFn.bind(this, response))
                },
 
                probeSystemFeatures: function() {
+                       var sessionid = classes.rpc.getSessionID();
+
                        if (sysFeatures == null) {
                                try {
-                                       sysFeatures = JSON.parse(window.sessionStorage.getItem('sysFeatures'));
+                                       var data = JSON.parse(window.sessionStorage.getItem('sysFeatures'));
+
+                                       if (this.isObject(data) && this.isObject(data[sessionid]))
+                                               sysFeatures = data[sessionid];
                                }
                                catch (e) {}
                        }
                                        expect: { '': {} }
                                })().then(function(features) {
                                        try {
-                                               window.sessionStorage.setItem('sysFeatures', JSON.stringify(features));
+                                               var data = {};
+                                                   data[sessionid] = features;
+
+                                               window.sessionStorage.setItem('sysFeatures', JSON.stringify(data));
                                        }
                                        catch (e) {}
 
                                                this.handleSaveApply ? E('button', {
                                                        'class': 'cbi-button cbi-button-apply',
                                                        'click': L.ui.createHandlerFn(this, 'handleSaveApply')
-                                               }, _('Save & Apply')) : '', ' ',
+                                               }, [ _('Save & Apply') ]) : '', ' ',
                                                this.handleSave ? E('button', {
                                                        'class': 'cbi-button cbi-button-save',
                                                        'click': L.ui.createHandlerFn(this, 'handleSave')
-                                               }, _('Save')) : '', ' ',
+                                               }, [ _('Save') ]) : '', ' ',
                                                this.handleReset ? E('button', {
                                                        'class': 'cbi-button cbi-button-reset',
                                                        'click': L.ui.createHandlerFn(this, 'handleReset')
-                                               }, _('Reset')) : ''
+                                               }, [ _('Reset') ]) : ''
                                        ]));
                                }