Created
September 19, 2017 23:42
-
-
Save rdiego26/5b6828d38c1dd1551a6bd3dea685fd76 to your computer and use it in GitHub Desktop.
Sweet Alert Angular Factory
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
'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