etherpad-lite/static/js/pad_connectionstatus.js

88 lines
2.2 KiB
JavaScript
Raw Normal View History

/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/
2011-03-26 14:10:41 +01:00
/**
* Copyright 2009 Google Inc.
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* http://www.apache.org/licenses/LICENSE-2.0
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2011-07-07 19:59:34 +02:00
var padconnectionstatus = (function()
{
2011-03-26 14:10:41 +01:00
2011-07-07 19:59:34 +02:00
var status = {
what: 'connecting'
};
2011-03-26 14:10:41 +01:00
var self = {
2011-07-07 19:59:34 +02:00
init: function()
{
$('button#forcereconnect').click(function()
{
window.location.reload();
2011-03-26 14:10:41 +01:00
});
},
2011-07-07 19:59:34 +02:00
connected: function()
{
status = {
what: 'connected'
};
2011-03-26 14:10:41 +01:00
padmodals.hideModal(500);
},
2011-07-07 19:59:34 +02:00
reconnecting: function()
{
status = {
what: 'reconnecting'
};
2011-03-26 14:10:41 +01:00
$("#connectionbox").get(0).className = 'modaldialog cboxreconnecting';
padmodals.showModal("#connectionbox", 500);
},
2011-07-07 19:59:34 +02:00
disconnected: function(msg)
{
2011-08-16 21:02:30 +02:00
if(status.what == "disconnected")
return;
2011-07-07 19:59:34 +02:00
status = {
what: 'disconnected',
why: msg
};
2011-03-26 14:10:41 +01:00
var k = String(msg).toLowerCase(); // known reason why
2011-08-16 21:02:30 +02:00
if (!(k == 'userdup' || k == 'deleted' || k == 'looping' || k == 'slowcommit' || k == 'initsocketfail' || k == 'unauth'))
2011-07-07 19:59:34 +02:00
{
2011-03-26 14:10:41 +01:00
k = 'unknown';
}
2011-08-16 21:02:30 +02:00
2011-07-07 19:59:34 +02:00
var cls = 'modaldialog cboxdisconnected cboxdisconnected_' + k;
2011-03-26 14:10:41 +01:00
$("#connectionbox").get(0).className = cls;
padmodals.showModal("#connectionbox", 500);
2011-07-07 19:59:34 +02:00
$('button#forcereconnect').click(function()
{
2011-06-02 02:55:09 +02:00
window.location.reload();
});
2011-03-26 14:10:41 +01:00
},
2011-07-07 19:59:34 +02:00
isFullyConnected: function()
{
2011-03-26 14:10:41 +01:00
return status.what == 'connected';
},
2011-07-07 19:59:34 +02:00
getStatus: function()
{
return status;
}
2011-03-26 14:10:41 +01:00
};
return self;
}());