generator-ngstack
Version:
Based on DaftMonk generator-angular-fullstack, this is a custom mean stack yeoman generator
83 lines (70 loc) • 2.34 kB
text/coffeescript
'use strict'
(->
### ###
Modal = ($rootScope,$modal) ->
###
Opens a modal
{Object} scope - an object to be merged with modal's scope
{String} modalClass - (optional) class(es) to be applied to the modal
{Object} - the instance $modal.open() returns
###
openModal = (scope, modalClass) ->
modalScope = $rootScope.$new()
scope = scope or {}
modalClass = modalClass or 'modal-default'
angular.extend modalScope, scope
$modal.open
templateUrl: 'components/modal/modal.html'
windowClass: modalClass
scope: modalScope
# Public API here
# Confirmation modals
confirm:
###
Create a function to open a delete confirmation modal (ex. ng-click='myModalFn(name, arg1, arg2...)')
{Function} del - callback, ran when delete is confirmed
{Function} - the function to open the modal (ex. myModalFn)
###
delete: (del) ->
del = del or angular.noop
###
Open a delete confirmation modal
{String} name - name or info to show on modal
{All} - any additional args are passed staight to del callback
###
->
args = Array::slice.call arguments
name = args.shift()
deleteModal = undefined
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: (e) ->
deleteModal.close e
return
}
{
classes: 'btn-default'
text: 'Cancel'
click: (e) ->
deleteModal.dismiss e
return
}
]
, 'modal-danger')
deleteModal.result.then (event) ->
del.apply event, args
return
return
Modal
.$inject = ['$rootScope','$modal']
angular
.module '<%= scriptAppName %>'
.factory 'Modal', Modal
)()