Skip to content
This repository was archived by the owner on Sep 20, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function ngDialog ($document, $compile, $rootScope, $controller, $timeout, $q) {
cancel: cancel,
submit: submit,
confirm: confirm,
reason: reason
reason: reason,
alert: alert
}

function submit (data) {
Expand All @@ -57,6 +58,48 @@ function ngDialog ($document, $compile, $rootScope, $controller, $timeout, $q) {
return deferred.reject('Canceled')
}

function alert (text, title) {
deferred = $q.defer()
title = title || 'this can not be undone';

var alertModal = angular.element(
'<div class="dialog-container">' +
'<div class="dialog" id="dialog-alert">' +
'<div class="dialog-header">' +
'<h2 translate>' + title + '</h2>' +
'</div>' +
'<div class="dialog-body dialog-confirm">' +
'<div class="dialog-inner" translate>' + text + '</div>' +
'</div>' +
'<div class="dialog-footer">' +
'<a class="button button-style" ng-click="accept()" translate>confirm</a>' +
'</div>' +
'</div>' +
'</div>'
)

var scope = $rootScope.$new()

scope.accept = function () {
alertModal.remove()
return deferred.resolve()
}

$compile(alertModal)(scope)

// Attach compiled modal to DOM
body.append(alertModal)

$timeout(function () {
$timeout(function () {
document.querySelector('#dialog-alert').classList.add('show-dialog')
}, 200)
alertModal.addClass('fadeIn')
}, 0)

return deferred.promise
}

function confirm (text) {
deferred = $q.defer()

Expand Down