Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
yaza-putu committed Mar 5, 2023
2 parents e7d2398 + 70d9ceb commit 93c8b94
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
91 changes: 58 additions & 33 deletions helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
var versioningCdnUrl = "V1.4.17";
const versioningCdnUrl = "V2.0.0";
const confirmSweetFinishDefault = {
text : "Click the ? button to return to the previous page",
cancelButtonFirst : "Continue",
cancelButtonSecond : "Edit",
buttonLabel : "Done"
}
const confirmSweetDeleteDefault = {
title : 'Are you sure?',
body : 'The data will be deleted and cannot be recovered!',
buttonLabel : 'Delete'
}

// read how to use this helper : https://gist.github.com/yaza-putu/6cac370a6fafcc05c3f964427e370504
// add csrf token header ajax sending
$.ajaxSetup({
Expand Down Expand Up @@ -49,16 +61,21 @@ function sweetInfo(message) {
}

// handel success function
function sweetSuccess(message, url = null, reload = false) {
function sweetSuccess(message, url = null, confirmSweetFinish = null, reload = false) {
if (url !== null) {
const text = confirmSweetFinish == null ? confirmSweetFinishDefault.text : confirmSweetFinish.text;
const cancelButtonFirst = confirmSweetFinish == null ? confirmSweetFinishDefault.cancelButtonFirst : confirmSweetFinish.cancelButtonFirst;
const cancelButtonSecond = confirmSweetFinish == null ? confirmSweetFinishDefault.cancelButtonSecond : confirmSweetFinish.cancelButtonSecond;
const buttonLabel = confirmSweetFinish == null ? confirmSweetFinishDefault.buttonLabel : confirmSweetFinish.buttonLabel;

Swal.fire({
title: message,
type: "success",
text: "Klik tombol selesai untuk kembali ke halaman sebelumnya",
text: text.replace('?', buttonLabel),
showCancelButton: true,
cancelButtonText: reload ? 'Edit Lagi' :'Buat Lagi',
cancelButtonText: reload ? cancelButtonSecond : cancelButtonFirst,
confirmButtonColor: "#ff4d4d",
confirmButtonText: "Selesai"
confirmButtonText: buttonLabel
}).then((result) => {
if (result.value) {
window.location.href = url;
Expand Down Expand Up @@ -123,59 +140,59 @@ function toastWarning(message, position = 'top-right') {
}

// snackbar default
function snackbar(message) {
function snackbar(message, position = 'bottom-center') {
Snackbar.show({
text: message,
actionTextColor: '#FFFFFF',
pos: 'bottom-center',
pos: position,
actionText: 'Close'
})
}

// snackbar success
function snackbarSuccess(message) {
function snackbarSuccess(message, position = 'bottom-center') {
Snackbar.show({
text: message,
actionTextColor: '#155724',
pos: 'bottom-center',
pos: position,
actionText: 'Close',
backgroundColor: '#d4edda',
textColor: '#155724'
})
}

// snackbar warning
function snackbarWarning(message) {
function snackbarWarning(message, position = 'bottom-center') {
Snackbar.show({
text: message,
actionTextColor: '#856404',
pos: 'bottom-center',
pos: position,
actionText: 'Close',
backgroundColor: '#fff3cd',
textColor: '#856404'
})
}

// snackbar error
function snackbarError(message) {
function snackbarError(message, position = 'bottom-center') {
Snackbar.show({
text: message,
actionTextColor: '#721c24',
pos: 'bottom-center',
pos: position,
actionText: 'Close',
backgroundColor: '#f8d7da',
textColor: '#721c24'
})
}

// notify success
function notifySuccess(message) {
function notifySuccess(message, x = "right", y = "top") {
notify({
type: "success", //alert | success | error | warning | info
title: "Success",
position: {
x: "right", //right | left | center
y: "top" //top | bottom | center
x: x, //right | left | center
y: y //top | bottom | center
},
icon: paperPlaneImg,
message: message,
Expand All @@ -185,14 +202,14 @@ function notifySuccess(message) {
}

// notify warning
function notifyWarning(message) {
function notifyWarning(message, x = "right", y = "top") {
notify({
type: "warning", //alert | success | error | warning | info
title: "Warning",
theme: "dark-theme",
position: {
x: "right", //right | left | center
y: "top" //top | bottom | center
x: x, //right | left | center
y: y //top | bottom | center
},
icon: paperPlaneImg,
message: message,
Expand All @@ -201,14 +218,14 @@ function notifyWarning(message) {
});
}
// notify error
function notifyError(message) {
function notifyError(message, x = "right", y = "top") {
notify({
type: "error", //alert | success | error | warning | info
title: "Error",
theme: "dark-theme",
position: {
x: "right", //right | left | center
y: "top" //top | bottom | center
x: x, //right | left | center
y: y //top | bottom | center
},
icon: paperPlaneImg,
message: message,
Expand Down Expand Up @@ -281,8 +298,10 @@ function ajaxPost(url , data, button = null) {

if (res.errors || res.invalid) {
new handleValidation(res.errors||res.invalid);
} else if(res.message !== undefined) {
new sweetError(res.message);
} else {
new sweetError('Terjadi Kesalahan');
new sweetError('There is an error');
}

}).always(function () {
Expand Down Expand Up @@ -348,8 +367,10 @@ function ajaxPostFile(url, data, button = null, showLoading = '#loading-body') {

if (res.errors || res.invalid) {
new handleValidation(res.errors||res.invalid);
} else if(res.message !== undefined) {
new sweetError(res.message);
} else {
new sweetError('Terjadi Kesalahan');
new sweetError('There is an error');
}

}).always(function () {
Expand Down Expand Up @@ -378,7 +399,7 @@ function ajaxGet(url, blockUi = false) {
}).done(function (response) {

}).fail(function (response) {
new sweetError('Terjadi Kesalahan');
new sweetError('There is an error');
}).always(function () {
if (blockUi == true) {
new hideBlockUI();
Expand All @@ -388,14 +409,18 @@ function ajaxGet(url, blockUi = false) {
}

// ajax Delete
function ajaxDel(url, id, table = null) {
function ajaxDel(url, id, table = null, confirmSweetDelete = null) {
const title = confirmSweetDelete == null ? confirmSweetDeleteDefault.title : confirmSweetDelete.title;
const body = confirmSweetDelete == null ? confirmSweetDeleteDefault.body : confirmSweetDelete.body;
const buttonLabel = confirmSweetDelete == null ? confirmSweetDeleteDefault.buttonLabel : confirmSweetDelete.buttonLabel;

Swal.fire({
title: "Apakah kamu yakin?",
text: "Data akan dihapus dan tidak akan bisa dikembalikan!",
title: title,
text: body,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#ff4d4d",
confirmButtonText: "Hapus"
confirmButtonText: buttonLabel
}).then((result) => {
if (result.value) {
$.ajax({
Expand All @@ -415,15 +440,15 @@ function ajaxDel(url, id, table = null) {
}
},
error: function (res) {
new sweetError('Terjadi Kesalahan');
new sweetError('There is an error');
}
});
}
});
}

// convert currency
$('.convert-currency').on('keyup', function () {
$(document).on('keyup','.convert-currency', function () {
$(this).val(formatRupiah(this.value, "Rp. "));
})

Expand Down Expand Up @@ -493,9 +518,9 @@ function datatable(table, url, columns= [], columnDefs = [], responsive = true)
}

// show block UI
function showBlockUI() {
function showBlockUI(message = "Please wait a moment ...") {
$.blockUI({
message: 'Mohon Tunggu Sebentar ...',
message: message,
css: {
'z-index': 10002,
border: 'none',
Expand Down

0 comments on commit 93c8b94

Please sign in to comment.