/**
 *
 * File:
 *   slave.ycp
 *
 * Module:
 *   Network/YPServer
 *
 * Summary:
 *   YPServer module.
 *
 * Authors:
 *   Dan Vesely <dan@suse.cz>
 *   Martin Vidner <mvidner@suse.cz>
 *
 * $Id: slave.ycp 18466 2004-08-10 07:15:41Z jsuchome $
 *
 * YPServer module part.
 *
 */


{

    textdomain "nis_server";

    import "Wizard";
    import "Popup";

    import "CWMFirewallInterfaces";
    import "NisServer";
    import "Nis";
    import "IP";
    include "nis_server/routines.ycp";

    /**
     * Slave dialog
     * @return `back, `abort or `next
     */
    define symbol SlaveDialog () ``{

	map<string,any> firewall_widget = GetFirewallWidget ();
	term firewall_layout = firewall_widget["custom_widget"]:`VBox ();

	// help text 1/2
	string helptext = _("<p>Enter the NIS <b>domain</b> and the IP <b>address</b> of the master NIS server.</p>");
	// help text 2/2
	helptext = helptext + _("<p>If this host is also a NIS client using this machine as a server, check the corresponding option.</p>")

	+ firewall_widget["help"]:"";

	term contents = `VBox ();
	contents = add (contents,
	    // textentry label
	    `TextEntry (`id(`domain),_("NIS &domain name:"),NisServer::domain));
	contents = add (contents, `VSpacing (0.5));
	contents = add (contents,
	    // text entry label
	    `TextEntry (`id (`master_ip), _("NIS &master server:"),
		NisServer::ui_master_ip));

	contents = add (contents, `VSpacing ());
	contents = add (contents,
	    // checkbox label
	    `CheckBox (`id (`also_client), _("This host is also a NIS &client"),
		NisServer::start_ypbind));

	contents = add (contents, `VSpacing (2));
	contents = add (contents, firewall_layout);
	contents = `HVSquash (contents);

	// To translators: dialog label
	Wizard::SetContents (_("Slave Server Setup"),
	    contents, helptext, true, true);

	CWMFirewallInterfaces::OpenFirewallInit (firewall_widget, "");

	map event = $[];
	any ui	= nil;

	repeat
	{
	    event	= UI::WaitForEvent ();
	    ui		= event["ID"]:nil;
	    CWMFirewallInterfaces::OpenFirewallHandle(firewall_widget,"",event);
	    if (ui == `cancel)
	    {
		ui = `abort;
	    }

	    if (ui == `next)
	    {
		string master_ip  =
		    (string) UI::QueryWidget (`id (`master_ip), `Value);
		string domainname =
		    (string) UI::QueryWidget (`id (`domain), `Value);
		if (!IP::Check4(master_ip))
		{
		    // To translators: error message
		    UI::SetFocus (`id (`master_ip));
		    Popup::Error (IP::Valid4());
		    ui = `again;
		}
		else if (!Nis::check_nisdomainname (domainname))
		{
		    UI::SetFocus (`id (`domain));
		    Popup::Error (Nis::valid_nisdomainname ());
		    ui = `again;
		}
		if (ui == `next)
		{
		    NisServer::start_ypbind = (boolean)
			UI::QueryWidget (`id (`also_client), `Value);
		    CheckForDHCPClient (domainname);
		    CWMFirewallInterfaces::OpenFirewallStore (
			firewall_widget,"",event);
		}
	    }

	    if (ui == `abort && !Popup::ReallyAbort (true)) ui = `again;
	}
	until (ui == `next || ui == `back || ui == `abort);

	NisServer::ui_master_ip =
	    (string) UI::QueryWidget (`id (`master_ip), `Value);
	NisServer::domain =
	    (string) UI::QueryWidget (`id (`domain), `Value);

	return (symbol) ui;
    }
}
