View | Details | Raw Unified | Return to bug 27202
Collapse All | Expand All

(-)/usr/share/univention-management-console-frontend/js/umc/modules/computerroom.js.bak (-29 / +61 lines)
Lines 98-103 Link Here
98
	_currentSchool: null,
98
	_currentSchool: null,
99
	_currentRoom: null,
99
	_currentRoom: null,
100
100
101
	_nUpdateFailures: 0,
102
101
	_vncEnabled: false,
103
	_vncEnabled: false,
102
104
103
	uninitialize: function() {
105
	uninitialize: function() {
Lines 606-611 Link Here
606
		this.changeRoom();
608
		this.changeRoom();
607
	},
609
	},
608
610
611
	_acquireRoom: function(school, room, promptAlert) {
612
		promptAlert = promptAlert === undefined || promptAlert;  // default value == true
613
		return umc.tools.umcpCommand('computerroom/room/acquire', {
614
			school: school,
615
			room: room
616
		}).then(dojo.hitch(this, function(response) {
617
			if ( response.result.success === false ) {
618
				// we could not acquire the room
619
				if (promptAlert) {
620
					// prompt a message if wanted
621
					if ( response.result.message == 'ALREADY_LOCKED' ) {
622
						umc.dialog.alert(this._('Failed to open a new session for the room.'));
623
					} else if ( response.result.message == 'EMPTY_ROOM' ) {
624
						umc.dialog.alert( this._( 'The room is empty or the computers are not configured correctly. Please select another room.' ) );
625
					}
626
				}
627
				throw new Error('Could not acquire room');
628
			}
629
			this._currentRoom = room;
630
			this._currentSchool = school;
631
632
			// reload the grid
633
			this.queryRoom();
634
635
			// update the header text containing the room
636
			this._updateHeader(room);
637
			this._grid._updateFooterContent();
638
		}));
639
	},
640
609
	changeRoom: function() {
641
	changeRoom: function() {
610
		// define a cleanup function
642
		// define a cleanup function
611
		var dialog = null, form = null, okButton = null;
643
		var dialog = null, form = null, okButton = null;
Lines 636-642 Link Here
636
			// show confirmation dialog if room is already locked
668
			// show confirmation dialog if room is already locked
637
			var room = _getRoom(vals.room);
669
			var room = _getRoom(vals.room);
638
			if (room.locked) {
670
			if (room.locked) {
639
				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), [{
671
				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), [{
640
					name: 'cancel',
672
					name: 'cancel',
641
					label: this._('Cancel'),
673
					label: this._('Cancel'),
642
					'default': true
674
					'default': true
Lines 651-685 Link Here
651
				});
683
				});
652
			}
684
			}
653
685
654
			deferred = deferred.then(function () {
686
			deferred = deferred.then(dojo.hitch(this, function () {
655
				// try to acquire the session
656
				okButton.set('disabled', true);
687
				okButton.set('disabled', true);
657
				return umc.tools.umcpCommand('computerroom/room/acquire', {
688
				return this._acquireRoom(vals.school, vals.room);
658
					school: vals.school,
689
			})).then(dojo.hitch(this, function() {
659
					room: vals.room
660
				});
661
			}).then(dojo.hitch(this, function(response) {
662
				okButton.set('disabled', false);
663
				if ( response.result.success === false ) {
664
					// we could not acquire the room
665
					if ( response.result.message == 'ALREADY_LOCKED' ) {
666
						umc.dialog.alert(this._('Failed to open a new session for the room.'));
667
					} else if ( response.result.message == 'EMPTY_ROOM' ) {
668
						umc.dialog.alert( this._( 'The room is empty or the computers are not configured correctly. Please select another room.' ) );
669
					}
670
					return;
671
				}
672
				this._currentRoom = vals.room;
673
				this._currentSchool = vals.school;
674
675
				// reload the grid
676
				this.queryRoom();
677
678
				// update the header text containing the room
679
				this._updateHeader(vals.room);
680
				this._grid._updateFooterContent();
681
682
				// destroy the dialog
690
				// destroy the dialog
691
				okButton.set('disabled', false);
683
				_cleanup();
692
				_cleanup();
684
			}), function() {
693
			}), function() {
685
				// catch error that has been thrown to cancel chain
694
				// catch error that has been thrown to cancel chain
Lines 773-781 Link Here
773
	},
782
	},
774
783
775
	_updateRoom: function() {
784
	_updateRoom: function() {
776
		this.umcpCommand( 'computerroom/update' ).then( dojo.hitch( this, function( response ) {
785
		this.umcpCommand( 'computerroom/update', {}, false ).then( dojo.hitch( this, function( response ) {
777
			var demo = false, demo_server = null, demo_user = null, demo_systems = 0;
786
			var demo = false, demo_server = null, demo_user = null, demo_systems = 0;
778
787
788
			this._nUpdateFailures = 0; // update was successful
789
779
			if (response.result.locked) {
790
			if (response.result.locked) {
780
				// somebody stole our session...
791
				// somebody stole our session...
781
				// break the update loop, prompt a message and ask for choosing a new room
792
				// break the update loop, prompt a message and ask for choosing a new room
Lines 855-860 Link Here
855
				systems: demo_systems
866
				systems: demo_systems
856
			};
867
			};
857
868
869
		} ), dojo.hitch(this, function(err) {
870
			// error case, update went wrong, try to reinitiate the computer room (see Bug #27202)
871
			console.log('WARN: the command \'computerroom/update\' failed:', err);
872
			this._nUpdateFailures++;
873
			if (this._nUpdateFailures < 5 && this._currentSchool && this._currentRoom) {
874
				// try several times to reconnect and then give up
875
				this._acquireRoom(this._currentSchool, this._currentRoom, false).then(function() {
876
					// success :) .... nothing needs to be done as _acquireRoom() takes care of anything
877
				}, dojo.hitch(this, function() {
878
					// failure :( ... try again after some idle time
879
					this._updateTimer = window.setTimeout( dojo.hitch( this, '_updateRoom', {} ), 1000 * this._nUpdateFailures );
880
				}));
881
			}
882
			else {
883
				// fall back, automatic reinitialization failed, show initial dialog to choose a room
884
				this._nUpdateFailures = 0;
885
				this._currentSchool = 0;
886
				this._currentRoom = 0;
887
				this.changeRoom();
888
				umc.dialog.alert(this._('Lost the connection to the computer room. Please try to reopen the computer room.'));
889
			}
858
		} ) );
890
		} ) );
859
	}
891
	}
860
});
892
});

Return to bug 27202