<reponame>Ebkarlibya/etms_s3_backup<filename>etms_s3_backup/etms_s3_backup/doctype/etms_s3_backup/etms_s3_backup.js<gh_stars>0// Copyright (c) 2023, envkt@example.com and contributors
// For license information, please see license.txt

frappe.ui.form.on('ETMS S3 Backup', {
		refresh: function (frm) {
			frm.clear_custom_buttons();
			frm.events.take_backup(frm);
		},
	
		take_backup: function (frm) {
			if (frm.doc.access_key_id && frm.doc.secret_access_key) {
				frm.add_custom_button(__("Take Backup Now"), function () {
					frm.dashboard.set_headline_alert("S3 Backup Started!");
					frappe.call({
						method: "etms_s3_backup.etms_s3_backup.doctype.etms_s3_backup.etms_s3_backup.take_backups_s3",
						callback: function (r) {
							if (!r.exc) {
								frappe.msgprint(__("S3 Backup complete!"));
								frm.dashboard.clear_headline();
							}
						},
					});
				}).addClass("btn-primary");
			}
		},
});
