add QuotaExceededError exception handling to saveConfig function
[samples/web/ExercisePlanner.git] / js / app.js
index 4081ed8..1836776 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -144,7 +144,12 @@ var ExercisePlanner = function () {
         * (use localStorage)
         */
        ExercisePlanner.prototype.saveConfig = function () {
-               localStorage.setItem('config', JSON.stringify(this.config));
+               try {
+                       localStorage.setItem('config', JSON.stringify(this.config));
+               } catch (e) {
+                       if (e.code === 22) //QuotaExceededError
+                               this.ui.showErrors([{name: 'Not enough memory. Please remove unnecessary files'}]);
+               }
        };
 
        ExercisePlanner.prototype.stopTraining = function () {
@@ -269,10 +274,8 @@ var ExercisePlanner = function () {
         * @param type
         */
        ExercisePlanner.prototype.changeTypeOfPeriods = function changeTypeOfPeriods(type) {
-               if (this.config.currentTypeOfPeriods !== type) {
                        this.config.currentTypeOfPeriods = type;
                        this.updateGraph(this.config.currentTypeOfPeriods);
-               }
        };
 
        /**