Commit | Line | Data |
---|---|---|
4baeda09 D |
1 | (function () {\r |
2 | var View = Backbone.View.extend({\r | |
3 | events: {\r | |
4 | 'click .save': 'saveSettings'\r | |
5 | },\r | |
19cc6364 | 6 | \r |
4baeda09 D |
7 | initialize: function (options) {\r |
8 | this.$el = $($('#tmpl_applet_settings').html());\r | |
5bed0536 | 9 | \r |
69ae0848 D |
10 | // Incase any settings change while we have this open, update them\r |
11 | _kiwi.global.settings.on('change', this.loadSettings, this);\r | |
12 | \r | |
13 | // Now actually show the current settings\r | |
14 | this.loadSettings();\r | |
da848c4f D |
15 | \r |
16 | \r | |
69ae0848 D |
17 | },\r |
18 | \r | |
19 | \r | |
20 | loadSettings: function () {\r | |
21 | var settings = _kiwi.global.settings;\r | |
22 | \r | |
039a3156 D |
23 | // TODO: Tidy this up\r |
24 | var theme = settings.get('theme') || 'relaxed';\r | |
25 | this.$el.find('.setting-theme option').filter(function() {\r | |
26 | return $(this).val() === theme;\r | |
27 | }).attr('selected', true);\r | |
28 | \r | |
29 | var list_style = settings.get('channel_list_style') || 'tabs';\r | |
30 | this.$el.find('.setting-channel_list_style option').filter(function() {\r | |
31 | return $(this).val() === list_style;\r | |
32 | }).attr('selected', true);\r | |
33 | \r | |
69ae0848 | 34 | this.$el.find('.setting-scrollback').val(settings.get('scrollback') || '250');\r |
ddd74e86 D |
35 | \r |
36 | if (typeof settings.get('show_joins_parts') === 'undefined' || settings.get('show_joins_parts')) {\r | |
37 | this.$el.find('.setting-show_joins_parts').attr('checked', true);\r | |
38 | } else {\r | |
39 | this.$el.find('.setting-show_joins_parts').attr('checked', false);\r | |
40 | }\r | |
2bbb5225 D |
41 | \r |
42 | if (typeof settings.get('show_timestamps') === 'undefined' || !settings.get('show_timestamps')) {\r | |
43 | this.$el.find('.setting-show_timestamps').attr('checked', false);\r | |
44 | } else {\r | |
45 | this.$el.find('.setting-show_timestamps').attr('checked', true);\r | |
46 | }\r | |
b2f25f45 D |
47 | \r |
48 | if (typeof settings.get('mute_sounds') === 'undefined' || settings.get('mute_sounds')) {\r | |
49 | this.$el.find('.setting-mute_sounds').attr('checked', true);\r | |
50 | } else {\r | |
51 | this.$el.find('.setting-mute_sounds').attr('checked', false);\r | |
52 | }\r | |
4baeda09 | 53 | },\r |
69ae0848 D |
54 | \r |
55 | \r | |
4baeda09 | 56 | saveSettings: function () {\r |
18aaad59 JA |
57 | var settings = _kiwi.global.settings,\r |
58 | feedback;\r | |
19cc6364 | 59 | \r |
039a3156 D |
60 | // Stop settings being updated while we're saving one by one\r |
61 | _kiwi.global.settings.off('change', this.loadSettings, this);\r | |
62 | \r | |
93fa049c | 63 | settings.set('theme', $('.setting-theme', this.$el).val());\r |
039a3156 | 64 | settings.set('channel_list_style', $('.setting-channel_list_style', this.$el).val());\r |
93fa049c | 65 | settings.set('scrollback', $('.setting-scrollback', this.$el).val());\r |
ddd74e86 | 66 | settings.set('show_joins_parts', $('.setting-show_joins_parts', this.$el).is(':checked'));\r |
2bbb5225 | 67 | settings.set('show_timestamps', $('.setting-show_timestamps', this.$el).is(':checked'));\r |
b2f25f45 | 68 | settings.set('mute_sounds', $('.setting-mute_sounds', this.$el).is(':checked'));\r |
19cc6364 | 69 | \r |
5bed0536 | 70 | settings.save();\r |
039a3156 | 71 | \r |
18aaad59 JA |
72 | feedback = $('.feedback', this.$el);\r |
73 | feedback.fadeIn('slow', function () {\r | |
74 | feedback.fadeOut('slow');\r | |
75 | })\r | |
76 | \r | |
039a3156 D |
77 | // Continue listening for setting changes\r |
78 | _kiwi.global.settings.on('change', this.loadSettings, this);\r | |
4baeda09 D |
79 | }\r |
80 | });\r | |
81 | \r | |
82 | \r | |
83 | \r | |
da848c4f | 84 | var Applet = Backbone.Model.extend({\r |
4baeda09 D |
85 | initialize: function () {\r |
86 | this.set('title', 'Settings');\r | |
87 | this.view = new View();\r | |
4baeda09 D |
88 | }\r |
89 | });\r | |
da848c4f D |
90 | \r |
91 | \r | |
92 | _kiwi.model.Applet.register('kiwi_settings', Applet);\r | |
4baeda09 | 93 | })(); |