/*
 * Spreed WebRTC.
 * Copyright (C) 2013-2014 struktur AG
 *
 * This file is part of Spreed WebRTC.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

"use strict";
define([
], function() {

	return ["$window", "$q", function($window, $q) {

		var pinCache = {};

		// XXX(longsleep): This service needs to get rid of all window.alert and prompt calls.
		var roompin = {
			get: function(roomName) {
				var cachedPIN = pinCache[roomName];
				return cachedPIN ? cachedPIN : null;
			},
			clear: function(roomName) {
				delete pinCache[roomName];
				console.log("Cleared PIN for", roomName);
			},
			update: function(roomName, pin) {
				if (pin) {
					pinCache[roomName] = pin;
					$window.alert("PIN for room " + roomName + " is now '" + pin + "'");
				} else {
					roompin.clear(roomName);
					$window.alert("PIN lock has been removed from room " + roomName);
				}
			},
			requestInteractively: function(roomName) {
				var deferred = $q.defer();
				var pin = $window.prompt("Enter the PIN for " + roomName + " below");
				if (pin) {
					pinCache[roomName] = pin;
					deferred.resolve();
				} else {
					deferred.reject();
				}
				return deferred.promise;
			}
		};

		return roompin;

	}];
});

@@ -843,143 +843,103 @@
 q%22, 
-function($window, $q) %7B%0A%0A%09%09var pinCache = %7B%7D;%0A%0A%09%09// XXX(longsleep): This service needs to get rid of all window.alert and prompt calls.
+%22alertify%22, %22translation%22, function($window, $q, alertify, translation) %7B%0A%0A%09%09var pinCache = %7B%7D;
 %0A%09%09v
@@ -1275,74 +1275,90 @@
 %09%09%09%09
-$window.alert(%22PIN for room %22 + roomName + %22 is now '%22 + pin + %22'%22
+alertify.dialog.alert(translation._(%22PIN for room %25s is now '%25s'.%22, roomName, pin)
 );%0A%09
@@ -1408,21 +1408,43 @@
 %09%09%09%09
-$window.alert
+alertify.dialog.alert(translation._
 (%22PI
@@ -1477,19 +1477,21 @@
 om room 
-%22 +
+%25s.%22,
  roomNam
@@ -1488,24 +1488,25 @@
 %22, roomName)
+)
 ;%0A%09%09%09%09%7D%0A%09%09%09%7D
@@ -1592,78 +1592,102 @@
 %09%09%09%09
-var pin = $window.prompt(%22Enter the PIN for %22 + roomName + %22 below%22);%0A
+alertify.dialog.prompt(translation._(%22Enter the PIN for room %25s%22, roomName), function(pin) %7B%0A%09
 %09%09%09%09
@@ -1689,32 +1689,33 @@
 %09%09%09%09%09if (pin) %7B%0A
+%09
 %09%09%09%09%09pinCache%5Bro
@@ -1730,24 +1730,25 @@
 = pin;%0A%09%09%09%09%09
+%09
 deferred.res
@@ -1755,24 +1755,25 @@
 olve();%0A%09%09%09%09
+%09
 %7D else %7B%0A%09%09%09
@@ -1765,24 +1765,76 @@
 %09%09%09%7D else %7B%0A
+%09%09%09%09%09%09deferred.reject();%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D, function() %7B%0A
 %09%09%09%09%09deferre
@@ -1846,24 +1846,26 @@
 ect();%0A%09%09%09%09%7D
+);
 %0A%09%09%09%09return 

Use alertify service instead of alerts.