Skip to content

Instantly share code, notes, and snippets.

@rdiego26
Created September 19, 2017 23:42
Show Gist options
  • Save rdiego26/5b6828d38c1dd1551a6bd3dea685fd76 to your computer and use it in GitHub Desktop.
Save rdiego26/5b6828d38c1dd1551a6bd3dea685fd76 to your computer and use it in GitHub Desktop.
Sweet Alert Angular Factory
'use strict';
/**
* SweetAlert wrapper
* @doc https://github.com/oitozero/ngSweetAlert
*/
app.factory('PopUp', ['SweetAlert', function(SweetAlert) {
return {
loading: function(_title) {
SweetAlert.swal({
title: _title,
text: '<img src="/img/loading.gif" alt="Carregando...">',
html: true,
showCancelButton: false,
showConfirmButton: false
});
},
hide: function() {
swal.close();
},
success: function(_title, _message, _cb) {
SweetAlert.swal({
title: _title,
text: _message,
type: 'success',
showCancelButton: false,
confirmButtonColor: '#438eb9',
confirmButtonText: 'OK'
}, _cb);
},
alert: function(_title, _message, _cb) {
SweetAlert.swal({
title: _title,
text: _message,
type: 'warning',
showCancelButton: false,
confirmButtonColor: '#438eb9',
confirmButtonText: 'OK'
}, _cb);
},
info: function(_title, _message) {
SweetAlert.swal({
title: _title,
text: _message,
type: 'info',
showCancelButton: false,
confirmButtonColor: '#438eb9',
confirmButtonText: 'OK'
});
},
confirm: function(_title, _message, _cb, _cancelButtonText, _confirmButtonText) {
SweetAlert.swal({
title: _title,
text: _message,
type: 'warning',
showCancelButton: true,
closeOnConfirm: false,
cancelButtonText: _cancelButtonText || 'Cancelar',
confirmButtonColor: '#438eb9',
confirmButtonText: _confirmButtonText || 'OK'
},
_cb);
},
confirmWithInput: function(_title, _message, _inputType, _inputPlaceholder, _cb) {
SweetAlert.swal({
title: _title,
text: _message,
type: 'input',
inputType: _inputType || 'text',
showCancelButton: true,
closeOnConfirm: false,
confirmButtonColor: '#438eb9',
cancelButtonText: 'Cancelar',
confirmButtonText: 'Finalizar',
animation: 'slide-from-top',
inputPlaceholder: _inputPlaceholder || ''
}, function(inputValue) {
if (inputValue === false) return false;
if (inputValue === "") return false;
try {
inputValue = parseFloat( inputValue.replace(',', '.') );
} catch(error) {
return false;
}
_cb(inputValue);
});
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment