--- /usr/share/univention-management-console-frontend/js/umc/modules/computerroom.js.bak 2012-10-04 10:42:46.000000000 +0200 +++ /usr/share/univention-management-console-frontend/js/umc/modules/computerroom.js 2012-10-04 12:18:14.000000000 +0200 @@ -98,6 +98,8 @@ _currentSchool: null, _currentRoom: null, + _nUpdateFailures: 0, + _vncEnabled: false, uninitialize: function() { @@ -606,6 +608,36 @@ this.changeRoom(); }, + _acquireRoom: function(school, room, promptAlert) { + promptAlert = promptAlert === undefined || promptAlert; // default value == true + return umc.tools.umcpCommand('computerroom/room/acquire', { + school: school, + room: room + }).then(dojo.hitch(this, function(response) { + if ( response.result.success === false ) { + // we could not acquire the room + if (promptAlert) { + // prompt a message if wanted + if ( response.result.message == 'ALREADY_LOCKED' ) { + umc.dialog.alert(this._('Failed to open a new session for the room.')); + } else if ( response.result.message == 'EMPTY_ROOM' ) { + umc.dialog.alert( this._( 'The room is empty or the computers are not configured correctly. Please select another room.' ) ); + } + } + throw new Error('Could not acquire room'); + } + this._currentRoom = room; + this._currentSchool = school; + + // reload the grid + this.queryRoom(); + + // update the header text containing the room + this._updateHeader(room); + this._grid._updateFooterContent(); + })); + }, + changeRoom: function() { // define a cleanup function var dialog = null, form = null, okButton = null; @@ -636,7 +668,7 @@ // show confirmation dialog if room is already locked var room = _getRoom(vals.room); if (room.locked) { - deferred = umc.dialog.confirm(this._('This computer room is currently in use by %s. You can take control over the room, however, the current teacher will be prompted a notification and its session will be closed.', room.user), [{ + deferred = umc.dialog.confirm(this._('This computer room is currently in use by %s. You can take control over the room, however, the current teacher will be prompted a notification and its session will be closed.', room.user), [{ name: 'cancel', label: this._('Cancel'), 'default': true @@ -651,35 +683,12 @@ }); } - deferred = deferred.then(function () { - // try to acquire the session + deferred = deferred.then(dojo.hitch(this, function () { okButton.set('disabled', true); - return umc.tools.umcpCommand('computerroom/room/acquire', { - school: vals.school, - room: vals.room - }); - }).then(dojo.hitch(this, function(response) { - okButton.set('disabled', false); - if ( response.result.success === false ) { - // we could not acquire the room - if ( response.result.message == 'ALREADY_LOCKED' ) { - umc.dialog.alert(this._('Failed to open a new session for the room.')); - } else if ( response.result.message == 'EMPTY_ROOM' ) { - umc.dialog.alert( this._( 'The room is empty or the computers are not configured correctly. Please select another room.' ) ); - } - return; - } - this._currentRoom = vals.room; - this._currentSchool = vals.school; - - // reload the grid - this.queryRoom(); - - // update the header text containing the room - this._updateHeader(vals.room); - this._grid._updateFooterContent(); - + return this._acquireRoom(vals.school, vals.room); + })).then(dojo.hitch(this, function() { // destroy the dialog + okButton.set('disabled', false); _cleanup(); }), function() { // catch error that has been thrown to cancel chain @@ -773,9 +782,11 @@ }, _updateRoom: function() { - this.umcpCommand( 'computerroom/update' ).then( dojo.hitch( this, function( response ) { + this.umcpCommand( 'computerroom/update', {}, false ).then( dojo.hitch( this, function( response ) { var demo = false, demo_server = null, demo_user = null, demo_systems = 0; + this._nUpdateFailures = 0; // update was successful + if (response.result.locked) { // somebody stole our session... // break the update loop, prompt a message and ask for choosing a new room @@ -855,6 +866,27 @@ systems: demo_systems }; + } ), dojo.hitch(this, function(err) { + // error case, update went wrong, try to reinitiate the computer room (see Bug #27202) + console.log('WARN: the command \'computerroom/update\' failed:', err); + this._nUpdateFailures++; + if (this._nUpdateFailures < 5 && this._currentSchool && this._currentRoom) { + // try several times to reconnect and then give up + this._acquireRoom(this._currentSchool, this._currentRoom, false).then(function() { + // success :) .... nothing needs to be done as _acquireRoom() takes care of anything + }, dojo.hitch(this, function() { + // failure :( ... try again after some idle time + this._updateTimer = window.setTimeout( dojo.hitch( this, '_updateRoom', {} ), 1000 * this._nUpdateFailures ); + })); + } + else { + // fall back, automatic reinitialization failed, show initial dialog to choose a room + this._nUpdateFailures = 0; + this._currentSchool = 0; + this._currentRoom = 0; + this.changeRoom(); + umc.dialog.alert(this._('Lost the connection to the computer room. Please try to reopen the computer room.')); + } } ) ); } });