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

jingrow.ui.form.on("Network Printer Settings", {
	onload(frm) {
		frm.trigger("connect_print_server");
	},
	server_ip(frm) {
		frm.trigger("connect_print_server");
	},
	port(frm) {
		frm.trigger("connect_print_server");
	},
	connect_print_server(frm) {
		if (frm.pg.server_ip && frm.pg.port) {
			jingrow.call({
				pg: frm.pg,
				method: "get_printers_list",
				args: {
					ip: frm.pg.server_ip,
					port: frm.pg.port,
				},
				callback: function (data) {
					frm.set_df_property("printer_name", "options", [""].concat(data.message));
				},
			});
		}
	},
});
