Add settings ui for theme

// FREEBIE
This commit is contained in:
lilia 2016-08-29 00:03:37 -07:00
parent 7b9894d688
commit 8fbb0d05f5
3 changed files with 72 additions and 32 deletions

View file

@ -413,23 +413,37 @@
<a class='x close' alt='close settings' href='#'></a> <a class='x close' alt='close settings' href='#'></a>
<h2>{{ settings }}</h2> <h2>{{ settings }}</h2>
<hr> <hr>
<h3>{{ notifications }}</h3> <div class='theme-settings'>
<p>{{ notificationSettingsDialog }}</p> <h3>Theme</h3>
<div> <div>
<input type='radio' name='notifications' id='notification-setting-message' value='message'> <input type='radio' name='theme' id='theme-setting-android' value='android'>
<label for='notification-setting-message'>{{ nameAndMessage }} </label> <label for='theme-setting-android'>Android</label>
</div>
<div>
<input type='radio' name='theme' id='theme-setting-ios' value='ios'/>
<label for='theme-setting-ios'>iOS</label>
</div>
</div> </div>
<div> <hr>
<input type='radio' name='notifications' id='notification-setting-name' value='name'/> <div class='notification-settings'>
<label for='notification-setting-name'>{{ nameOnly }} </label> <h3>{{ notifications }}</h3>
</div> <p>{{ notificationSettingsDialog }}</p>
<div> <div>
<input type='radio' name='notifications' id='notification-setting-count' value='count'/> <input type='radio' name='notifications' id='notification-setting-message' value='message'>
<label for='notification-setting-count'>{{ noNameOrMessage }} </label> <label for='notification-setting-message'>{{ nameAndMessage }} </label>
</div> </div>
<div> <div>
<input type='radio' name='notifications' id='notification-setting-off' value='off'/> <input type='radio' name='notifications' id='notification-setting-name' value='name'/>
<label for='notification-setting-off'>{{ disableNotifications }} </label> <label for='notification-setting-name'>{{ nameOnly }} </label>
</div>
<div>
<input type='radio' name='notifications' id='notification-setting-count' value='count'/>
<label for='notification-setting-count'>{{ noNameOrMessage }} </label>
</div>
<div>
<input type='radio' name='notifications' id='notification-setting-off' value='off'/>
<label for='notification-setting-off'>{{ disableNotifications }} </label>
</div>
</div> </div>
</div> </div>
</script> </script>

View file

@ -89,9 +89,15 @@
Whisper.InboxView = Whisper.View.extend({ Whisper.InboxView = Whisper.View.extend({
templateName: 'two-column', templateName: 'two-column',
className: 'inbox', className: 'inbox',
applyTheme: function() {
var theme = storage.get('theme-setting') || 'android';
this.$el.removeClass('ios')
.removeClass('android')
.addClass(theme);
},
initialize: function (options) { initialize: function (options) {
this.render(); this.render();
this.$el.addClass('android'); // theme this.applyTheme();
new Whisper.FontSizeView({ el: this.el }); new Whisper.FontSizeView({ el: this.el });
this.conversation_stack = new Whisper.ConversationStack({ this.conversation_stack = new Whisper.ConversationStack({
el: this.$('.conversation-stack'), el: this.$('.conversation-stack'),
@ -175,9 +181,9 @@
chrome.runtime.reload(); chrome.runtime.reload();
}, },
showSettings: function() { showSettings: function() {
var view = new Whisper.SettingsView().render(); var view = new Whisper.SettingsView();
view.update();
view.$el.appendTo(this.el); view.$el.appendTo(this.el);
view.$el.on('change-theme', this.applyTheme.bind(this));
}, },
filterContacts: function(e) { filterContacts: function(e) {
this.searchView.filterContacts(e); this.searchView.filterContacts(e);

View file

@ -5,29 +5,49 @@
'use strict'; 'use strict';
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
Whisper.SettingsView = Whisper.View.extend({ var RadioButtonGroupView = Whisper.View.extend({
className: 'settings modal', initialize: function(options) {
templateName: 'settings', this.name = options.name;
this.defaultValue = options.defaultValue;
this.populate();
},
events: { events: {
'change': 'change', 'change': 'change'
'click .close': 'remove'
}, },
change: function(e) { change: function(e) {
var value = this.$(e.target).val(); var value = this.$(e.target).val();
storage.put('notification-setting', value); storage.put(this.name, value);
console.log('notification setting changed to', value); console.log(this.name, 'changed to', value);
this.$el.trigger('change-theme');
}, },
update: function() { populate: function() {
var setting = storage.get('notification-setting'); var value = storage.get(this.name, this.defaultValue);
if (!setting) { this.$('#' + this.name + '-' + value).attr('checked', 'checked');
setting = 'message'; },
} });
this.$('#notification-setting-' + setting).attr('checked','checked'); Whisper.SettingsView = Whisper.View.extend({
className: 'settings modal',
templateName: 'settings',
initialize: function() {
this.render();
new RadioButtonGroupView({
el: this.$('.notification-settings'),
defaultValue: 'message',
name: 'notification-setting'
});
new RadioButtonGroupView({
el: this.$('.theme-settings'),
defaultValue: 'message',
name: 'theme-setting'
});
if (textsecure.storage.user.getDeviceId() != '1') { if (textsecure.storage.user.getDeviceId() != '1') {
var syncView = new SyncView().render(); var syncView = new SyncView().render();
this.$('.content').append(syncView.el); this.$('.content').append(syncView.el);
} }
}, },
events: {
'click .close': 'remove'
},
render_attributes: function() { render_attributes: function() {
return { return {
notifications: i18n('notifications'), notifications: i18n('notifications'),