From ff7cdb583551a245d0ca72da5e7027b46169b499 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Mon, 1 Jun 2015 18:15:48 +0200 Subject: [PATCH] Support alertify dialogs of custom type. --- static/js/controllers/uicontroller.js | 8 +++++- static/js/services/alertify.js | 38 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/static/js/controllers/uicontroller.js b/static/js/controllers/uicontroller.js index 2d927f4e..4a38d6a6 100644 --- a/static/js/controllers/uicontroller.js +++ b/static/js/controllers/uicontroller.js @@ -24,6 +24,12 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", "screensharing", "localStatus", "dialogs", "rooms", "constraints", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing, localStatus, dialogs, rooms, constraints) { + alertify.dialog.registerCustom({ + baseType: 'notify', + type: 'webrtcUnsupported', + message: translation._("Your browser does not support WebRTC. No calls possible.") + }); + // Avoid accidential reloads or exits when in a call. $($window).on("beforeunload", function(event) { if (appData.flags.manualUnload || !$scope.peer) { @@ -714,7 +720,7 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web return; } if (!$window.webrtcDetectedVersion) { - alertify.dialog.alert(translation._("Your browser does not support WebRTC. No calls possible.")); + alertify.dialog.custom("webrtcUnsupported"); return; } if (mediaStream.config.Renegotiation && $window.webrtcDetectedBrowser === "firefox" && $window.webrtcDetectedVersion < 38) { diff --git a/static/js/services/alertify.js b/static/js/services/alertify.js index 02e14e88..cbf7c32a 100644 --- a/static/js/services/alertify.js +++ b/static/js/services/alertify.js @@ -89,7 +89,38 @@ define(["angular"], function(angular) { }); }; + var registeredCustomDialog = []; var dialog = { + /** + * registerCustom registers a custom dialog. To overwrite an existing custom dialog simply use the same id. + * + * @param {Object} config Preferences for the custom dialog with the following properties: + * @param {String} config.baseType Existing dialog type to use as initial values and from which a template will be used. + * @param {String} config.type The ID of the custom dialog. The template name which is saved in $templateCache. If the the type is 'notify' the templateUrl must be '/dialogs/notify.html'. + * @param {String} [config.template] A custom template to use for the dialog instead of the baseType template. + * @param {String} [config.title] The title which the baseType modal dialog should display. If none is provided the baseType title is used. + * @param {String} [config.message] The message which the baseType modal dialog should display. + * @param {Function} [config.ok_cb] The callback function to be called on success. + * @param {Function} [config.err_cb] The callback function to be called on error. + */ + registerCustom: function(config) { + var conf = angular.extend({}, config); + if (!conf || + conf && !conf.type || + conf && !conf.baseType) { + throw Error("Custom template not configured correctly."); + } + var templateUrl = '/dialogs/' + conf.type + '.html'; + if (conf.template) { + $templateCache.put(templateUrl, conf.template); + } else { + $templateCache.put(templateUrl, $templateCache.get('/dialogs/' + conf.baseType + '.html')); + } + if (!conf.title) { + conf.title = api.defaultMessages[conf.baseType]; + } + registeredCustomDialog[conf.type] = conf; + }, exec: function(n, title, message, ok_cb, err_cb) { if (!message && title) { message = title; @@ -104,6 +135,13 @@ define(["angular"], function(angular) { } return dlg; }, + custom: function(type) { + var config = registeredCustomDialog[type]; + if (!config) { + throw new Error('The custom dialog type "' + type + '" is not registered.'); + } + return dialog.exec(config.type, config.title, config.message, config.ok_cb, config.err_cb); + }, error: function(title, message, ok_cb, err_cb) { return dialog.exec("error", title, message, ok_cb, err_cb); },