1 _kiwi
.view
.ServerSelect = function () {
2 // Are currently showing all the controlls or just a nick_change box?
5 var model
= Backbone
.View
.extend({
7 'submit form': 'submitForm',
8 'click .show_more': 'showMore',
9 'change .have_pass input': 'showPass',
10 'change .have_key input': 'showKey',
11 'click .icon-key': 'channelKeyIconClick'
14 initialize: function () {
17 think_nick
: _kiwi
.global
.i18n
.translate('client_views_serverselect_form_title').fetch(),
18 nickname
: _kiwi
.global
.i18n
.translate('client_views_serverselect_nickname').fetch(),
19 have_password
: _kiwi
.global
.i18n
.translate('client_views_serverselect_enable_password').fetch(),
20 password
: _kiwi
.global
.i18n
.translate('client_views_serverselect_password').fetch(),
21 channel
: _kiwi
.global
.i18n
.translate('client_views_serverselect_channel').fetch(),
22 channel_key
: _kiwi
.global
.i18n
.translate('client_views_serverselect_channelkey').fetch(),
23 require_key
: _kiwi
.global
.i18n
.translate('client_views_serverselect_channelkey_required').fetch(),
24 key
: _kiwi
.global
.i18n
.translate('client_views_serverselect_key').fetch(),
25 start
: _kiwi
.global
.i18n
.translate('client_views_serverselect_connection_start').fetch(),
26 server_network
: _kiwi
.global
.i18n
.translate('client_views_serverselect_server_and_network').fetch(),
27 server
: _kiwi
.global
.i18n
.translate('client_views_serverselect_server').fetch(),
28 port
: _kiwi
.global
.i18n
.translate('client_views_serverselect_port').fetch(),
29 powered_by
: _kiwi
.global
.i18n
.translate('client_views_serverselect_poweredby').fetch()
32 this.$el
= $(_
.template($('#tmpl_server_select').html().trim(), text
));
34 // Remove the 'more' link if the server has disabled server changing
35 if (_kiwi
.app
.server_settings
&& _kiwi
.app
.server_settings
.connection
) {
36 if (!_kiwi
.app
.server_settings
.connection
.allow_change
) {
37 this.$el
.find('.show_more').remove();
38 this.$el
.addClass('single_server');
42 this.more_shown
= false;
44 _kiwi
.gateway
.bind('onconnect', this.networkConnected
, this);
45 _kiwi
.gateway
.bind('connecting', this.networkConnecting
, this);
46 _kiwi
.gateway
.bind('onirc_error', this.onIrcError
, this);
50 _kiwi
.gateway
.off('onconnect', this.networkConnected
, this);
51 _kiwi
.gateway
.off('connecting', this.networkConnecting
, this);
52 _kiwi
.gateway
.off('onirc_error', this.onIrcError
, this);
57 submitForm: function (event
) {
58 event
.preventDefault();
60 // Make sure a nick is chosen
61 if (!$('input.nick', this.$el
).val().trim()) {
62 this.setStatus(_kiwi
.global
.i18n
.translate('client_views_serverselect_nickname_error_empty').fetch());
63 $('input.nick', this.$el
).select();
67 if (state
=== 'nick_change') {
68 this.submitNickChange(event
);
70 this.submitLogin(event
);
73 $('button', this.$el
).attr('disabled', 1);
77 submitLogin: function (event
) {
78 // If submitting is disabled, don't do anything
79 if ($('button', this.$el
).attr('disabled')) return;
82 nick
: $('input.nick', this.$el
).val(),
83 server
: $('input.server', this.$el
).val(),
84 port
: $('input.port', this.$el
).val(),
85 ssl
: $('input.ssl', this.$el
).prop('checked'),
86 password
: $('input.password', this.$el
).val(),
87 channel
: $('input.channel', this.$el
).val(),
88 channel_key
: $('input.channel_key', this.$el
).val(),
89 options
: this.server_options
92 this.trigger('server_connect', values
);
95 submitNickChange: function (event
) {
96 _kiwi
.gateway
.changeNick(null, $('input.nick', this.$el
).val());
97 this.networkConnecting();
100 showPass: function (event
) {
101 if (this.$el
.find('tr.have_pass input').is(':checked')) {
102 this.$el
.find('tr.pass').show().find('input').focus();
104 this.$el
.find('tr.pass').hide().find('input').val('');
108 channelKeyIconClick: function (event
) {
109 this.$el
.find('tr.have_key input').click();
112 showKey: function (event
) {
113 if (this.$el
.find('tr.have_key input').is(':checked')) {
114 this.$el
.find('tr.key').show().find('input').focus();
116 this.$el
.find('tr.key').hide().find('input').val('');
120 showMore: function (event
) {
121 if (!this.more_shown
) {
122 $('.more', this.$el
).slideDown('fast');
123 $('.show_more', this.$el
)
124 .children('.icon-caret-down')
125 .removeClass('icon-caret-down')
126 .addClass('icon-caret-up');
127 $('input.server', this.$el
).select();
128 this.more_shown
= true;
130 $('.more', this.$el
).slideUp('fast');
131 $('.show_more', this.$el
)
132 .children('.icon-caret-up')
133 .removeClass('icon-caret-up')
134 .addClass('icon-caret-down');
135 $('input.nick', this.$el
).select();
136 this.more_shown
= false;
140 populateFields: function (defaults
) {
141 var nick
, server
, port
, channel
, channel_key
, ssl
, password
;
143 defaults
= defaults
|| {};
145 nick
= defaults
.nick
|| '';
146 server
= defaults
.server
|| '';
147 port
= defaults
.port
|| 6667;
148 ssl
= defaults
.ssl
|| 0;
149 password
= defaults
.password
|| '';
150 channel
= defaults
.channel
|| '';
151 channel_key
= defaults
.channel_key
|| '';
153 $('input.nick', this.$el
).val(nick
);
154 $('input.server', this.$el
).val(server
);
155 $('input.port', this.$el
).val(port
);
156 $('input.ssl', this.$el
).prop('checked', ssl
);
157 $('input#server_select_show_pass', this.$el
).prop('checked', !(!password
));
158 $('input.password', this.$el
).val(password
);
160 $('tr.pass', this.$el
).show();
162 $('input.channel', this.$el
).val(channel
);
163 $('input#server_select_show_channel_key', this.$el
).prop('checked', !(!channel_key
));
164 $('input.channel_key', this.$el
).val(channel_key
);
165 if (!(!channel_key
)) {
166 $('tr.key', this.$el
).show();
170 this.server_options
= {};
172 if (defaults
.encoding
)
173 this.server_options
.encoding
= defaults
.encoding
;
180 show: function (new_state
) {
181 new_state
= new_state
|| 'all';
185 if (new_state
=== 'all') {
186 $('.show_more', this.$el
).show();
188 } else if (new_state
=== 'more') {
189 $('.more', this.$el
).slideDown('fast');
191 } else if (new_state
=== 'nick_change') {
192 $('.more', this.$el
).hide();
193 $('.show_more', this.$el
).hide();
194 $('input.nick', this.$el
).select();
200 infoBoxShow: function() {
201 var $side_panel
= this.$el
.find('.side_panel');
203 // Some theme may hide the info panel so check before we
205 if (!$side_panel
.is(':visible'))
209 width
: parseInt($side_panel
.css('left'), 10) + $side_panel
.find('.content:first').outerWidth()
213 infoBoxHide: function() {
214 var $side_panel
= this.$el
.find('.side_panel');
216 width
: parseInt($side_panel
.css('left'), 10)
220 infoBoxSet: function($info_view
) {
221 this.$el
.find('.side_panel .content')
226 setStatus: function (text
, class_name
) {
227 $('.status', this.$el
)
229 .attr('class', 'status')
230 .addClass(class_name
||'')
233 clearStatus: function () {
234 $('.status', this.$el
).hide();
237 networkConnected: function (event
) {
238 this.setStatus(_kiwi
.global
.i18n
.translate('client_views_serverselect_connection_successfully').fetch() + ' :)', 'ok');
239 $('form', this.$el
).hide();
242 networkConnecting: function (event
) {
243 this.setStatus(_kiwi
.global
.i18n
.translate('client_views_serverselect_connection_trying').fetch(), 'ok');
246 onIrcError: function (data
) {
247 $('button', this.$el
).attr('disabled', null);
250 case 'nickname_in_use':
251 this.setStatus(_kiwi
.global
.i18n
.translate('client_views_serverselect_nickname_error_alreadyinuse').fetch());
252 this.show('nick_change');
253 this.$el
.find('.nick').select();
255 case 'erroneus_nickname':
256 this.setStatus(_kiwi
.global
.i18n
.translate('client_views_serverselect_nickname_invalid').fetch());
257 this.show('nick_change');
258 this.$el
.find('.nick').select();
260 case 'password_mismatch':
261 this.setStatus(_kiwi
.global
.i18n
.translate('client_views_serverselect_password_incorrect').fetch());
262 this.show('nick_change');
263 this.$el
.find('.password').select();
268 showError: function (error_reason
) {
269 var err_text
= _kiwi
.global
.i18n
.translate('client_views_serverselect_connection_error').fetch();
272 switch (error_reason
) {
274 err_text
= _kiwi
.global
.i18n
.translate('client_views_serverselect_server_notfound').fetch();
278 err_text
+= ' (' + _kiwi
.global
.i18n
.translate('client_views_serverselect_connection_refused').fetch() + ')';
282 err_text
+= ' (' + error_reason
+ ')';
286 this.setStatus(err_text
, 'error');
287 $('button', this.$el
).attr('disabled', null);
293 return new model(arguments
);