From f07824bef1a6398428d1ea261e7156ec9b8eec51 Mon Sep 17 00:00:00 2001 From: Evan Theurer Date: Tue, 24 Jun 2014 19:00:54 +0200 Subject: [PATCH] Remove angular-dialog-service dep. --- static/js/libs/angular/dialogs.min.js | 26 ----------- static/js/main.js | 1 - static/js/services/alertify.js | 64 +++++++++++++++++++-------- 3 files changed, 45 insertions(+), 46 deletions(-) delete mode 100644 static/js/libs/angular/dialogs.min.js diff --git a/static/js/libs/angular/dialogs.min.js b/static/js/libs/angular/dialogs.min.js deleted file mode 100644 index fcc1d491..00000000 --- a/static/js/libs/angular/dialogs.min.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - angular-dialog-service - https://github.com/m-e-conroy/angular-dialog-service/ - - Copyright (c) 2013 Michael E Conroy - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - Version: 3.0 - 2014-01-27 - */ -angular.module("dialogs.controllers",["ui.bootstrap.modal"]).controller("errorDialogCtrl",["$scope","$modalInstance","header","msg",function(o,n,e,a){o.header=angular.isDefined(e)?e:"Error",o.msg=angular.isDefined(a)?a:"An unknown error has occurred.",o.close=function(){n.close()}}]).controller("waitDialogCtrl",["$scope","$modalInstance","$timeout","header","msg","progress",function(o,n,e,a,t,r){o.header=angular.isDefined(a)?a:"Please Wait...",o.msg=angular.isDefined(t)?t:"Waiting on operation to complete.",o.progress=angular.isDefined(r)?r:100,o.$on("dialogs.wait.complete",function(){e(function(){n.close()})}),o.$on("dialogs.wait.message",function(n,e){o.msg=angular.isDefined(e.msg)?e.msg:o.msg}),o.$on("dialogs.wait.progress",function(n,e){o.msg=angular.isDefined(e.msg)?e.msg:o.msg,o.progress=angular.isDefined(e.progress)?e.progress:o.progress}),o.getProgress=function(){return{width:o.progress+"%"}}}]).controller("notifyDialogCtrl",["$scope","$modalInstance","header","msg",function(o,n,e,a){o.header=angular.isDefined(e)?e:"Notification",o.msg=angular.isDefined(a)?a:"Unknown application notification.",o.close=function(){n.close()}}]).controller("confirmDialogCtrl",["$scope","$modalInstance","header","msg",function(o,n,e,a){o.header=angular.isDefined(e)?e:"Confirmation",o.msg=angular.isDefined(a)?a:"Confirmation required.",o.no=function(){n.dismiss("no")},o.yes=function(){n.close("yes")}}]),angular.module("dialogs.services",["ui.bootstrap.modal","dialogs.controllers"]).factory("$dialogs",["$modal",function(o){return{error:function(n,e){return o.open({templateUrl:"/dialogs/error.html",controller:"errorDialogCtrl",resolve:{header:function(){return angular.copy(n)},msg:function(){return angular.copy(e)}}})},wait:function(n,e,a){return o.open({templateUrl:"/dialogs/wait.html",controller:"waitDialogCtrl",resolve:{header:function(){return angular.copy(n)},msg:function(){return angular.copy(e)},progress:function(){return angular.copy(a)}}})},notify:function(n,e){return o.open({templateUrl:"/dialogs/notify.html",controller:"notifyDialogCtrl",resolve:{header:function(){return angular.copy(n)},msg:function(){return angular.copy(e)}}})},confirm:function(n,e){return o.open({templateUrl:"/dialogs/confirm.html",controller:"confirmDialogCtrl",resolve:{header:function(){return angular.copy(n)},msg:function(){return angular.copy(e)}}})},create:function(n,e,a,t){var r=angular.isDefined(t.keyboard)?t.keyboard:!0,s=angular.isDefined(t.backdrop)?t.backdrop:!0,l=angular.isDefined(t.windowClass)?t.windowClass:"dialogs-default";return o.open({templateUrl:n,controller:e,keyboard:r,backdrop:s,windowClass:l,resolve:{data:function(){return angular.copy(a)}}})}}}]),angular.module("dialogs",["dialogs.services","ngSanitize"]).run(["$templateCache",function(o){o.put("/dialogs/error.html",''),o.put("/dialogs/wait.html",''),o.put("/dialogs/notify.html",''),o.put("/dialogs/confirm.html",'')}]); \ No newline at end of file diff --git a/static/js/main.js b/static/js/main.js index b8a34907..1726c6fc 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -48,7 +48,6 @@ require.config({ 'rAF': 'libs/rAF', 'humanize': 'libs/humanize', 'sha': 'libs/sha', - 'dialogs': 'libs/angular/dialogs.min', 'sjcl': 'libs/sjcl', 'partials': '../partials', diff --git a/static/js/services/alertify.js b/static/js/services/alertify.js index d4364091..217891af 100644 --- a/static/js/services/alertify.js +++ b/static/js/services/alertify.js @@ -20,8 +20,9 @@ */ define(["angular"], function(angular) { - var promptController = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) { + var controller = {}; + controller.prompt = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) { $scope.input = { text: '' }; @@ -41,20 +42,46 @@ define(["angular"], function(angular) { $scope.save(); } }; + }]; + + controller.confirm = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) { + $scope.header = data.title || ""; + $scope.msg = data.message || ""; + $scope.ok = function() { + $modalInstance.close('ok'); + }; + $scope.cancel = function() { + $modalInstance.dismiss('cancel'); + }; + }]; + + controller.notify = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) { + $scope.header = data.title || ""; + $scope.msg = data.message || ""; + $scope.close = function() { + $modalInstance.close('close'); + }; + }]; + controller.error = ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data) { + $scope.header = data.title || ""; + $scope.msg = data.message || ""; + $scope.close = function() { + $modalInstance.close('close'); + }; }]; // Alertify uniquified api wrapper - return ["$window", "$dialogs", "$templateCache", "translation", function($window, $dialogs, $templateCache, translation) { + 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', ''); + $templateCache.put('/dialogs/confirm.html', ''); // Add new template for prompt. - $templateCache.put('/alertify/prompt.html', ''); + $templateCache.put('/dialogs/prompt.html', ''); var defaultMessages = { error: translation._("Error"), @@ -72,9 +99,18 @@ define(["angular"], function(angular) { defaultMessages: defaultMessages }; + var setupModal = function(data, type) { + return $modal.open({ + templateUrl: '/dialogs/' + type +'.html', + controller: controller[type], + resolve: { + data: function() { return data; } + } + }); + }; + var dialog = { exec: function(n, title, message, ok_cb, err_cb) { - var f = $dialogs[n]; if (!message && title) { message = title; title = null; @@ -82,7 +118,7 @@ define(["angular"], function(angular) { if (!title) { title = api.defaultMessages[n] || n; } - var dlg = f(title, message); + var dlg = setupModal({'title': title, 'message': message}, n); if (ok_cb) { dlg.result.then(ok_cb, err_cb); } @@ -109,8 +145,8 @@ define(["angular"], function(angular) { cancelButtonLabel: api.defaultMessages.cancelButtonLabel || "Cancel", header: title, id: id - } - var dlg = $dialogs.create('/alertify/prompt.html', promptController, data, {}); + }; + var dlg = setupModal(data, "prompt"); dlg.result.then(function(text) { if (ok_cb) { ok_cb(text); @@ -120,21 +156,11 @@ define(["angular"], function(angular) { 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; - api.dialogs = $dialogs; return api;