merging waldir-patch-1
[KiwiIRC.git] / client / assets / src / applets / 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().trim());
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 }).prop('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 }).prop('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').prop('checked', true);
38 } else {
39 this.$el.find('.setting-show_joins_parts').prop('checked', false);
40 }
41
42 if (typeof settings.get('show_timestamps') === 'undefined' || !settings.get('show_timestamps')) {
43 this.$el.find('.setting-show_timestamps').prop('checked', false);
44 } else {
45 this.$el.find('.setting-show_timestamps').prop('checked', true);
46 }
47
48 if (typeof settings.get('mute_sounds') === 'undefined' || settings.get('mute_sounds')) {
49 this.$el.find('.setting-mute_sounds').prop('checked', true);
50 } else {
51 this.$el.find('.setting-mute_sounds').prop('checked', false);
52 }
53 },
54
55
56 saveSettings: function () {
57 var settings = _kiwi.global.settings,
58 feedback;
59
60 // Stop settings being updated while we're saving one by one
61 _kiwi.global.settings.off('change', this.loadSettings, this);
62
63 settings.set('theme', $('.setting-theme', this.$el).val());
64 settings.set('channel_list_style', $('.setting-channel_list_style', this.$el).val());
65 settings.set('scrollback', $('.setting-scrollback', this.$el).val());
66 settings.set('show_joins_parts', $('.setting-show_joins_parts', this.$el).is(':checked'));
67 settings.set('show_timestamps', $('.setting-show_timestamps', this.$el).is(':checked'));
68 settings.set('mute_sounds', $('.setting-mute_sounds', this.$el).is(':checked'));
69
70 settings.save();
71
72 feedback = $('.feedback', this.$el);
73 feedback.fadeIn('slow', function () {
74 feedback.fadeOut('slow');
75 })
76
77 // Continue listening for setting changes
78 _kiwi.global.settings.on('change', this.loadSettings, this);
79 }
80 });
81
82
83
84 var Applet = Backbone.Model.extend({
85 initialize: function () {
86 this.set('title', 'Settings');
87 this.view = new View();
88 }
89 });
90
91
92 _kiwi.model.Applet.register('kiwi_settings', Applet);
93 })();