// bind events

jingrow.ui.form.on("ToDo", {
	onload: function (frm) {
		frm.set_query("reference_type", function (txt) {
			return {
				filters: {
					issingle: 0,
				},
			};
		});
	},
	refresh: function (frm) {
		if (frm.pg.reference_type && frm.pg.reference_name) {
			frm.add_custom_button(__(frm.pg.reference_name), function () {
				jingrow.set_route("Form", frm.pg.reference_type, frm.pg.reference_name);
			});
		}

		if (!frm.pg.__islocal) {
			if (frm.pg.status !== "Closed") {
				frm.add_custom_button(
					__("Close"),
					function () {
						frm.set_value("status", "Closed");
						frm.save(null, function () {
							// back to list
							jingrow.set_route("List", "ToDo");
						});
					},
					"fa fa-check",
					"btn-success"
				);
			} else {
				frm.add_custom_button(
					__("Reopen"),
					function () {
						frm.set_value("status", "Open");
						frm.save();
					},
					null,
					"btn-default"
				);
			}
			frm.add_custom_button(
				__("New"),
				function () {
					jingrow.new_pg("ToDo");
				},
				null,
				"btn-default"
			);
		}
	},
});
