app/assets/javascripts/admin/utils/services/confirm_dialog.js.coffee
angular.module("admin.utils").factory 'ConfirmDialog', ($rootScope, $q, $compile, $templateCache, DialogDefaults) ->
new class ConfirmDialog
open: (type, message, options) ->
deferred = $q.defer()
scope = $rootScope.$new()
scope.message = message
scope.dialog_class = type
scope.confirmText = options?.confirm || t('ok')
scope.cancelText = options?.cancel || t('cancel')
template = $compile($templateCache.get('admin/confirm_dialog.html'))(scope)
template.dialog(DialogDefaults)
template.dialog('open')
$rootScope.$evalAsync()
scope.confirm = ->
deferred.resolve()
template.dialog('close')
$rootScope.$evalAsync()
null
scope.close = ->
deferred.reject()
template.dialog('close')
$rootScope.$evalAsync()
null
deferred.promise