Skip to content

Instantly share code, notes, and snippets.

@rtpm
Last active December 17, 2015 16:59
Show Gist options
  • Save rtpm/5642913 to your computer and use it in GitHub Desktop.
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.
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