Last active
February 3, 2016 23:37
-
-
Save lbenie/0bb722802ed7eb6b28f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Opens a modal | |
* @param {Object} scope - an object to be merged with modal's scope | |
* @param {String} modalClass - (optional) class(es) to be applied to the modal | |
* @param {String} size - (optional) size to be applied to the modal | |
* @param {String} templateUrl - (optional) template to be applied to the modal | |
* @param {String} controller - (optional) controller to be applied to the modal | |
* @return {Object} - the instance $uibModal.open() returns | |
*/ | |
function openModal(scope = {}, modalClass = 'modal-default', size = 'sm', templateUrl = 'components/modal/modal.html', controller = '') { | |
var modalScope = $rootScope.$new(); | |
angular.extend(modalScope, scope); | |
return $uibModal.open({ | |
templateUrl: templateUrl, | |
windowClass: modalClass, | |
scope: modalScope, | |
size: size, | |
controller: controller | |
}); | |
} | |
return { | |
/* Confirmation modals */ | |
confirm: { | |
/** | |
* Create a function to open a delete confirmation modal (ex. ng-click='myModalFn(name, arg1, arg2...)') | |
* @param {Function} del - callback, ran when delete is confirmed | |
* @return {Function} - the function to open the modal (ex. myModalFn) | |
*/ | |
delete(del = angular.noop) { | |
/** | |
* Open a delete confirmation modal | |
* @param {String} name - name or info to show on modal | |
* @param {All} - any additional args are passed straight to del callback | |
*/ | |
return function() { | |
var args = Array.prototype.slice.call(arguments), | |
name = args.shift(), | |
deleteModal; | |
deleteModal = openModal({ | |
modal: { | |
dismissable: true, | |
title: 'Confirm Delete', | |
html: '<p>Are you sure you want to delete <strong>' + name + '</strong> ?</p>', | |
buttons: [{ | |
classes: 'btn-danger', | |
text: 'Delete', | |
click: function(e) { | |
deleteModal.close(e); | |
} | |
}, { | |
classes: 'btn-default', | |
text: 'Cancel', | |
click: function(e) { | |
deleteModal.dismiss(e); | |
} | |
}] | |
} | |
}, 'myModalClass', 'mySize', 'myTemplate.html', 'myController.js'); | |
deleteModal.result.then(function(event) { | |
del.apply(event, args); | |
}); | |
}; | |
} | |
} | |
} |
it's my pleasure
THANK YOU!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much. This makes so much sense now that I see it.