Browse Source

Support alertify dialogs of custom type.

pull/213/head
Evan Theurer 10 years ago
parent
commit
ff7cdb5835
  1. 8
      static/js/controllers/uicontroller.js
  2. 38
      static/js/services/alertify.js

8
static/js/controllers/uicontroller.js

@ -24,6 +24,12 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web @@ -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 @@ -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) {

38
static/js/services/alertify.js

@ -89,7 +89,38 @@ define(["angular"], function(angular) { @@ -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) { @@ -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);
},

Loading…
Cancel
Save