From cf9f8b3f8a98454e84f8e6c315e0dec24c6ed1ad Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 25 Apr 2013 23:00:55 -0700 Subject: [PATCH] toolbar now saves its state for radio buttons. --- UI/Config.js | 5 +++-- UI/Index.html | 3 +++ UI/Instrumentation/StringFormat.js | 11 +++++++++++ UI/MainMenuView.js | 1 - UI/Shared/Toolbar/Radio/RadioButtonView.js | 15 +++++++++++++-- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 UI/Instrumentation/StringFormat.js diff --git a/UI/Config.js b/UI/Config.js index d3e436e94..407199e00 100644 --- a/UI/Config.js +++ b/UI/Config.js @@ -9,8 +9,7 @@ define(['app'], function () { if (value !== undefined) { NzbDrone.Config.SetValue(key, value); } - - else{ + else { return NzbDrone.Config.GetValue(key, 1); } }; @@ -40,6 +39,8 @@ define(['app'], function () { cookie = {}; } + console.log('Config: [{0}] => [{1}] '.format(key, value)); + cookie[key] = value; NzbDrone.Config.SetCookie(cookie); }; diff --git a/UI/Index.html b/UI/Index.html index 803d046d6..2af07e3e8 100644 --- a/UI/Index.html +++ b/UI/Index.html @@ -111,6 +111,9 @@ + + + diff --git a/UI/Instrumentation/StringFormat.js b/UI/Instrumentation/StringFormat.js new file mode 100644 index 000000000..b441cd597 --- /dev/null +++ b/UI/Instrumentation/StringFormat.js @@ -0,0 +1,11 @@ +"use strict"; +String.prototype.format = function () { + var args = arguments; + return this.replace(/{(\d+)}/g, function (match, number) { + if (typeof args[number] !== 'undefined') { + return args[number]; + } else { + return match; + } + }); +}; diff --git a/UI/MainMenuView.js b/UI/MainMenuView.js index 08259f8af..b9ff92f8c 100644 --- a/UI/MainMenuView.js +++ b/UI/MainMenuView.js @@ -40,7 +40,6 @@ define(['app'], function () { }, initialize: function () { - console.log('menu'); this.setElement($('#main-menu-region')); } }); diff --git a/UI/Shared/Toolbar/Radio/RadioButtonView.js b/UI/Shared/Toolbar/Radio/RadioButtonView.js index 49cf7ec2f..dc215f2c5 100644 --- a/UI/Shared/Toolbar/Radio/RadioButtonView.js +++ b/UI/Shared/Toolbar/Radio/RadioButtonView.js @@ -1,15 +1,20 @@ "use strict"; -define(['app'], function () { +define(['app', 'Config'], function () { NzbDrone.Shared.Toolbar.RadioButtonView = Backbone.Marionette.ItemView.extend({ template : 'Shared/Toolbar/ButtonTemplate', className: 'btn', events: { - 'click': 'invokeCallback' + 'click': 'onClick' }, + initialize: function () { + + this.storageKey = this.model.get('menuKey') + ':' + this.model.get('key'); + }, + onRender: function () { if (this.model.get('active')) { this.$el.addClass('active'); @@ -17,6 +22,12 @@ define(['app'], function () { } }, + onClick: function () { + + NzbDrone.Config.SetValue(this.model.get('menuKey'), this.model.get('key')); + this.invokeCallback(); + }, + invokeCallback: function () { if (!this.model.ownerContext) {