]> source.dussan.org Git - vaadin-framework.git/commitdiff
Export fetchRootConfig status so it can be read by TK (#14053)
authorManolo Carrasco <manolo@vaadin.com>
Mon, 21 Jul 2014 12:21:40 +0000 (14:21 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 22 Jul 2014 11:06:50 +0000 (11:06 +0000)
Offline apps need to know when server errors are 500 or 400 in
order to switch appropriatelly to the offline mode.
Also we need exported the fetchRootConfig method and a
reliable way to get loaded apps.

Related with change I29635982514071e63221a9771d6729da14273ad3 [1]
see temporal workaround in TouchKitServlet
[1] https://dev.vaadin.com/review/#/c/4037/

Change-Id: I339ca697d035508a67d1eb24480cd12c4b9c6c0e

WebContent/VAADIN/vaadinBootstrap.js

index df46d8bc725ceda6765b74dfbb48f1b864b86f95..ced077138fc435a54f1c18feace18d33829c3f76 100644 (file)
                                return value;
                        };
                        
-                       var fetchRootConfig = function() {
+                       var fetchRootConfig = function(callback) {
                                log('Fetching root config');
                                var url = getConfig('browserDetailsUrl');
                                if (!url) {
                                r.open('POST', url, true);
                                r.onreadystatechange = function (aEvt) {  
                                        if (r.readyState == 4) {
+                                               // Save responseStatus so as Offline Applications know what happened
+                                               // when loading root configuration from server, and depending on the
+                                               // error status display an error message or the offline UI.
+                                               config.rootResponseStatus = r.status;
+                                               config.rootResponseText = r.responseText;
+
                                                var text = r.responseText;
                                                if (r.status == 200){
                                                        log("Got root config response", text);
                                                        appDiv.innerHTML = text;
                                                        appDiv.style['overflow'] = 'auto';
                                                }
+
+                                               // Run the fetchRootConfig callback if present.
+                                               callback && callback(r);
                                        }  
                                };
                                // send parameters as POST data
                        
                        //Export public data
                        var app = {
-                               'getConfig': getConfig
+                               getConfig: getConfig,
+                               // Used when the app was started in offline, so as it is possible
+                               // to defer root configuration loading until network is available.
+                               fetchRootConfig: fetchRootConfig
                        };
                        apps[appId] = app;
                        
                        return app;
                },
                clients: {},
+               getAppIds: function() {
+                       var ids = [ ];
+                       for (var id in apps) {
+                               if (apps.hasOwnProperty(id)) {
+                                       ids.push(id);
+                               }
+                       }
+                       return ids;
+               },
                getApp: function(appId) {
-                       var app = apps[appId]; 
-                       return app;
+                       return apps[appId];
                },
                loadTheme: loadTheme,
                registerWidgetset: function(widgetset, callback) {