Merge branch 'development'
[KiwiIRC.git] / client / assets / dev / applet_settings.js
1 (function () {
2 var View = Backbone.View.extend({
3 events: {
4 'click .save': 'saveSettings'
5 },
6
7 initialize: function (options) {
8 this.$el = $($('#tmpl_applet_settings').html());
9
10 // Incase any settings change while we have this open, update them
11 _kiwi.global.settings.on('change', this.loadSettings, this);
12
13 // Now actually show the current settings
14 this.loadSettings();
15
16
17 },
18
19
20 loadSettings: function () {
21 var settings = _kiwi.global.settings;
22
23 // TODO: Tidy this up
24 var theme = settings.get('theme') || 'relaxed';
25 this.$el.find('.setting-theme option').filter(function() {
26 return $(this).val() === theme;
27 }).attr('selected', true);
28
29 var list_style = settings.get('channel_list_style') || 'tabs';
30 this.$el.find('.setting-channel_list_style option').filter(function() {
31 return $(this).val() === list_style;
32 }).attr('selected', true);
33
34 this.$el.find('.setting-scrollback').val(settings.get('scrollback') || '250');
35
36 if (typeof settings.get('show_joins_parts') === 'undefined' || settings.get('show_joins_parts')) {
37 this.$el.find('.setting-show_joins_parts').attr('checked', true);
38 } else {
39 this.$el.find('.setting-show_joins_parts').attr('checked', false);
40 }
41 },
42
43
44 saveSettings: function () {
45 var settings = _kiwi.global.settings;
46
47 // Stop settings being updated while we're saving one by one
48 _kiwi.global.settings.off('change', this.loadSettings, this);
49
50 settings.set('theme', $('.setting-theme', this.$el).val());
51 settings.set('channel_list_style', $('.setting-channel_list_style', this.$el).val());
52 settings.set('scrollback', $('.setting-scrollback', this.$el).val());
53 settings.set('show_joins_parts', $('.setting-show_joins_parts', this.$el).is(':checked'));
54
55 settings.save();
56
57 // Continue listening for setting changes
58 _kiwi.global.settings.on('change', this.loadSettings, this);
59 }
60 });
61
62
63
64 var Applet = Backbone.Model.extend({
65 initialize: function () {
66 this.set('title', 'Settings');
67 this.view = new View();
68 }
69 });
70
71
72 _kiwi.model.Applet.register('kiwi_settings', Applet);
73 })();