Last active
December 17, 2015 16:59
-
-
Save rtpm/5642913 to your computer and use it in GitHub Desktop.
AngularJS notification service for use in Phonegap & desktop browsers. Depends on angular-ui bootstrap & angular-phonegap-notification projects.
This file contains 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
econtainersApp.factory("NotificationService", function ($dialog, notification) { | |
return { | |
showAlert: function (message, alertCallback, title, buttonName) { | |
if (navigator.notification) { | |
notification.alert(message, alertCallback, title, buttonName) | |
} else { | |
var buttonName = (typeof buttonName === "undefined") ? "Ok" : buttonName; | |
var msgbox = $dialog.messageBox(title, message, [{ | |
label: buttonName | |
} | |
]) | |
msgbox.open() | |
.then(function (result) { | |
if (alertCallback) { | |
alertCallback() | |
}; | |
}); | |
} | |
}, | |
showConfirm: function (message, confirmCallback, title, buttonLabels) { | |
if (navigator.notification) { | |
notification.confirm(message, confirmCallback, title, buttonLabels) | |
} else { | |
var buttonLabels = (typeof buttonLabels === "undefined") ? ["Ok", "Cancel"] : buttonLabels; | |
var msgbox = $dialog.messageBox(title, message, (function () { | |
var buttons = []; | |
var result = 1; | |
angular.forEach(buttonLabels, function (value) { | |
buttons.push({ | |
label: value, | |
result: result | |
}); | |
result = result + 1; | |
}); | |
return buttons; | |
})()) | |
msgbox.open() | |
.then(function (result) { | |
confirmCallback(result); | |
}) | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment