← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18851: Use localStorage values for headerbar when request for systemSettings fails.

 

------------------------------------------------------------
revno: 18851
committer: Mark Polak <markpo@xxxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-04-09 13:50:27 +0200
message:
  Use localStorage values for headerbar when request for systemSettings fails.
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.menu.ui.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.menu.ui.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.menu.ui.js	2015-03-27 15:19:31 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.menu.ui.js	2015-04-09 11:50:27 +0000
@@ -1094,6 +1094,9 @@
                     function initialise() {
                         getSystemSettings()
                             .success(function(systemSettings) {
+
+                                saveToLocalStorage(systemSettings);
+
                                 requestUserStyle()
                                     .success(function (userStyleUrl) {
                                         var userStyleName = getStyleName(userStyleUrl);
@@ -1108,7 +1111,22 @@
                                     });
                             })
                             .error(function() {
-                                throw new Error('Unable to load systemSettings');
+                                var logo, title, link;
+
+                                //Unable to load system settings defaulting to base styles
+                                addUserStyleStylesheet(getStylesheetUrl());
+
+                                //Load values from localStorage if they are available
+                                if (islocalStorageSupported()) {
+                                    logo = localStorage.getItem('dhis2.menu.ui.headerBar.logo')
+                                    title = localStorage.getItem('dhis2.menu.ui.headerBar.title');
+                                    link = localStorage.getItem('dhis2.menu.ui.headerBar.link');
+                                }
+
+                                //Set values to local storage values or fallback to the defaults
+                                setHeaderLogo(logo);
+                                setHeaderTitle(title);
+                                setHeaderLink(link);
                             });
                     }
 
@@ -1127,7 +1145,6 @@
                             } else {
                                 ctrl.headerBar.logo = getStyleLogoUrl(defaultStyle);
                             }
-
                         }
                     }
 
@@ -1169,6 +1186,23 @@
                             .append('<link href="' + stylesheetUrl + '" type="text/css" rel="stylesheet" media="screen,print" />');
                     }
 
+                    function islocalStorageSupported() {
+                        try {
+                            localStorage.setItem('dhis2.menu.localstorage.test', 'dhis2.menu.localstorage.test');
+                            localStorage.removeItem('dhis2.menu.localstorage.test');
+                            return true;
+                        } catch(e) {
+                            return false;
+                        }
+                    }
+
+                    function saveToLocalStorage(systemSettings) {
+                        if (islocalStorageSupported()) {
+                            localStorage.setItem('dhis2.menu.ui.headerBar.logo', getStyleLogoUrl(defaultStyle))
+                            localStorage.setItem('dhis2.menu.ui.headerBar.title', systemSettings.applicationTitle);
+                            localStorage.setItem('dhis2.menu.ui.headerBar.link', systemSettings.startModule);
+                        }
+                    }
                 }
             });