// Copyright (c) 2019, JINGROW
// For license information, please see license.txt

jingrow.ui.form.on("Personal Data Deletion Request", {
	refresh: function (frm) {
		if (
			jingrow.user.has_role("System Manager") &&
			(frm.pg.status == "Pending Approval" || frm.pg.status == "On Hold")
		) {
			frm.add_custom_button(__("Delete Data"), function () {
				return jingrow.call({
					pg: frm.pg,
					method: "trigger_data_deletion",
					freeze: true,
					callback: function () {
						frm.refresh();
					},
				});
			});
		}

		if (jingrow.user.has_role("System Manager") && frm.pg.status == "Pending Approval") {
			frm.add_custom_button(__("Put on Hold"), function () {
				return jingrow.call({
					pg: frm.pg,
					method: "put_on_hold",
					callback: function () {
						frm.refresh();
					},
				});
			});
		}
	},
});
