refactor: change alert duration to 3 and modern js

This commit is contained in:
Ankush Menat 2022-05-11 18:52:14 +05:30
parent 7f14222700
commit d35a13ec7e

View File

@ -48,10 +48,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
.then((r) => { .then((r) => {
const data = r && r.message; const data = r && r.message;
if (!data || Object.keys(data).length === 0) { if (!data || Object.keys(data).length === 0) {
frappe.show_alert({ this.show_alert(__("Cannot find Item with this Barcode"), "red");
message: __("Cannot find Item with this Barcode"),
indicator: "red",
});
this.clean_up(); this.clean_up();
return; return;
} }
@ -79,10 +76,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
if (!row) { if (!row) {
if (this.dont_allow_new_row) { if (this.dont_allow_new_row) {
frappe.show_alert({ this.show_alert(__("Maximum quantity scanned for item {0}.", [item_code]), "red");
message: __("Maximum quantity scanned for item {0}.", [item_code]),
indicator: "red"
});
this.clean_up(); this.clean_up();
return; return;
} }
@ -170,36 +164,17 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
show_scan_message(idx, exist = null, qty = 1) { show_scan_message(idx, exist = null, qty = 1) {
// show new row or qty increase toast // show new row or qty increase toast
if (exist) { if (exist) {
frappe.show_alert( this.show_alert(__("Row #{0}: Qty increased by {1}", [idx, qty]), "green");
{
message: __("Row #{0}: Qty increased by {1}", [idx, qty]),
indicator: "green",
},
5
);
} else { } else {
frappe.show_alert( this.show_alert(__("Row #{0}: Item added", [idx]), "green")
{
message: __("Row #{0}: Item added", [idx]),
indicator: "green",
},
5
);
} }
} }
is_duplicate_serial_no(row, serial_no) { is_duplicate_serial_no(row, serial_no) {
const is_duplicate = !!serial_no && !!row[this.serial_no_field] const is_duplicate = row[this.serial_no_field]?.includes(serial_no);
&& row[this.serial_no_field].includes(serial_no);
if (is_duplicate) { if (is_duplicate) {
frappe.show_alert( this.show_alert(__("Serial No {0} is already added", [serial_no]), "orange");
{
message: __("Serial No {0} is already added", [serial_no]),
indicator: "orange",
},
5
);
} }
return is_duplicate; return is_duplicate;
} }
@ -228,4 +203,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
this.scan_barcode_field.set_value(""); this.scan_barcode_field.set_value("");
refresh_field(this.items_table_name); refresh_field(this.items_table_name);
} }
show_alert(msg, indicator, duration=3) {
frappe.show_alert({message: msg, indicator: indicator}, duration);
}
}; };