/* * 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 . * */ define(["angular"], function(angular) { var modalController = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) { $scope.input = { text: '' }; $scope.id = data.id; $scope.header = data.header || ""; $scope.msg = data.message || ""; $scope.okButtonLabel = data.okButtonLabel || "Ok"; $scope.cancelButtonLabel = data.cancelButtonLabel || "Cancel"; $scope.cancel = function() { $modalInstance.dismiss('Canceled'); }; $scope.save = function() { $modalInstance.close($scope.input.text); }; $scope.hitEnter = function(evt) { if (angular.equals(evt.keyCode, 13) && !(angular.equals($scope.input.text, null) || angular.equals($scope.input.text, ''))) { $scope.save(); } }; $scope.ok = function() { $modalInstance.close('Ok'); }; $scope.close = function() { $modalInstance.close('Close'); }; }]; // Alertify uniquified api wrapper return ["$window", "$modal", "$templateCache", "translation", function($window, $modal, $templateCache, translation) { // Overwrite templates from dialogs with fontawesome/i18n variants. $templateCache.put('/dialogs/error.html', ''); $templateCache.put('/dialogs/wait.html', ''); $templateCache.put('/dialogs/notify.html', ''); $templateCache.put('/dialogs/confirm.html', ''); // Add new template for prompt. $templateCache.put('/dialogs/prompt.html', ''); var defaultMessages = { error: translation._("Error"), notify: translation._("Hint"), confirm: translation._("Please confirm"), prompt: translation._("More information required"), okButtonLabel: translation._("Ok"), cancelButtonLabel: translation._("Cancel"), closeButtonLabel: translation._("Close") }; var promptIdx = 0; var api = { defaultMessages: defaultMessages }; var setupModal = function(data, type) { return $modal.open({ templateUrl: '/dialogs/' + type +'.html', controller: modalController, resolve: { data: function() { return data; } } }); }; var dialog = { exec: function(n, title, message, ok_cb, err_cb) { if (!message && title) { message = title; title = null; } if (!title) { title = api.defaultMessages[n] || n; } var dlg = setupModal({'header': title, 'message': message}, n); if (ok_cb) { dlg.result.then(ok_cb, err_cb); } return dlg; }, error: function(title, message, ok_cb, err_cb) { return dialog.exec("error", title, message, ok_cb, err_cb); }, notify: function(title, message, ok_cb, err_cb) { return dialog.exec("notify", title, message, ok_cb, err_cb); }, alert: function(message, ok_cb, title) { // Legacy function for compatibility with alertify. return dialog.notify(title, message, ok_cb); }, confirm: function(message, ok_cb, err_cb, title) { // Legacy function for compatibility with alertify. return dialog.exec("confirm", null, message, ok_cb, err_cb); }, prompt: function(title, ok_cb, err_cb) { var id = "allertifyPrompt" + (promptIdx++); var data = { okButtonLabel: api.defaultMessages.okButtonLabel || "Ok", cancelButtonLabel: api.defaultMessages.cancelButtonLabel || "Cancel", header: title, id: id }; var dlg = setupModal(data, "prompt"); dlg.result.then(function(text) { if (ok_cb) { ok_cb(text); } }, function() { if (err_cb) { err_cb(); } }); dlg.opened.then(function() { // Crude hack to get auto focus. $window.setTimeout(function() { var element = $window.document.getElementById(id); if (element) { element.focus(); } }, 100); }); } }; // Expose the shit. api.dialog = dialog; return api; }]; });