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 | |
4baeda09 | 47 | },\r |
69ae0848 D |
48 | \r |
49 | \r | |
4baeda09 | 50 | saveSettings: function () {\r |
5bed0536 | 51 | var settings = _kiwi.global.settings;\r |
19cc6364 | 52 | \r |
039a3156 D |
53 | // Stop settings being updated while we're saving one by one\r |
54 | _kiwi.global.settings.off('change', this.loadSettings, this);\r | |
55 | \r | |
93fa049c | 56 | settings.set('theme', $('.setting-theme', this.$el).val());\r |
039a3156 | 57 | settings.set('channel_list_style', $('.setting-channel_list_style', this.$el).val());\r |
93fa049c | 58 | settings.set('scrollback', $('.setting-scrollback', this.$el).val());\r |
ddd74e86 | 59 | settings.set('show_joins_parts', $('.setting-show_joins_parts', this.$el).is(':checked'));\r |
2bbb5225 | 60 | settings.set('show_timestamps', $('.setting-show_timestamps', this.$el).is(':checked'));\r |
19cc6364 | 61 | \r |
5bed0536 | 62 | settings.save();\r |
039a3156 D |
63 | \r |
64 | // Continue listening for setting changes\r | |
65 | _kiwi.global.settings.on('change', this.loadSettings, this);\r | |
4baeda09 D |
66 | }\r |
67 | });\r | |
68 | \r | |
69 | \r | |
70 | \r | |
da848c4f | 71 | var Applet = Backbone.Model.extend({\r |
4baeda09 D |
72 | initialize: function () {\r |
73 | this.set('title', 'Settings');\r | |
74 | this.view = new View();\r | |
4baeda09 D |
75 | }\r |
76 | });\r | |
da848c4f D |
77 | \r |
78 | \r | |
79 | _kiwi.model.Applet.register('kiwi_settings', Applet);\r | |
4baeda09 | 80 | })(); |