3 angular.module('dashboardApp')
4 .factory('Modal', function ($rootScope, $modal) {
7 * @param {Object} scope - an object to be merged with modal's scope
8 * @param {String} modalClass - (optional) class(es) to be applied to the modal
9 * @return {Object} - the instance $modal.open() returns
11 function openModal(scope, modalClass) {
12 var modalScope = $rootScope.$new();
14 modalClass = modalClass || 'modal-default';
16 angular.extend(modalScope, scope);
19 templateUrl: 'components/modal/modal.html',
20 windowClass: modalClass,
28 /* Confirmation modals */
32 * Create a function to open a delete confirmation modal (ex. ng-click='myModalFn(name, arg1, arg2...)')
33 * @param {Function} del - callback, ran when delete is confirmed
34 * @return {Function} - the function to open the modal (ex. myModalFn)
36 delete: function(del) {
37 del = del || angular.noop;
40 * Open a delete confirmation modal
41 * @param {String} name - name or info to show on modal
42 * @param {All} - any additional args are passed straight to del callback
45 var args = Array.prototype.slice.call(arguments),
49 deleteModal = openModal({
52 title: 'Confirm Delete',
53 html: '<p>Are you sure you want to delete <strong>' + name + '</strong> ?</p>',
55 classes: 'btn-danger',
61 classes: 'btn-default',
64 deleteModal.dismiss(e);
70 deleteModal.result.then(function(event) {
71 del.apply(event, args);