/* PasswordDialog.java

	Purpose:
		
	Description:
		
	History:
		Wed, Apr 30, 2014  2:25:58 PM, Created by RaymondChao

Copyright (C) 2014 Potix Corporation. All Rights Reserved.

*/
package org.zkoss.zssex.ui.dialog;

import java.util.Map;

import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zssex.ui.dialog.impl.DialogCallbackEvent;
import org.zkoss.zssex.ui.dialog.impl.DialogCtrlBase;
import org.zkoss.zul.Button;
import org.zkoss.zul.Label;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 * 
 * @author RaymondChao
 */
public class PasswordCtrl extends DialogCtrlBase {
	private static final long serialVersionUID = 7451012702741297011L;

	private final static String URI = "~./zssex/dlg/passwordDialog.zul";
	
	public final static String ARG_PASSWORD = "password";
	
	private final static String ARG_HINT = "hint";
	
	private final static String ARG_CAUTION = "caution";
	
	@Wire
	private Button okBtn;
	
	@Wire
	private Label hintLabel, cautionLabel;
	
	@Wire
	private Textbox passwordBox;
	
	public static void show(EventListener<DialogCallbackEvent> callback,
			final String title, final String hint, final String caution) {
		Map arg = newArg(callback);
		arg.put(ARG_HINT, hint);
		arg.put(ARG_CAUTION, caution);
		Window comp = (Window) Executions.createComponents(URI, null, arg);
		comp.setTitle(title);
		comp.doModal();
		return;
	}
	
	public void doAfterCompose(Window comp) throws Exception {
		super.doAfterCompose(comp);
		
		Map arg = Executions.getCurrent().getArg();
		String hint = (String) arg.get(ARG_HINT);
		String caution = (String) arg.get(ARG_CAUTION);
		hintLabel.setValue(hint);
		cautionLabel.setValue(caution);
		
	}
	
	@Listen("onOK = window; onClick = #okBtn")
	public void onOK() {
		detach();
		postCallback(ON_OK, newMap(
			newEntry(ARG_PASSWORD, passwordBox.getValue())));
	}
	
	@Listen("onCancel = window; onClick = #cancelBtn")
	public void onCancel() {
		detach();
		postCallback(ON_CANCEL, null);
	}
}