/**
 * 
 */
package com.smartgwt.sample.client;

import com.google.gwt.core.client.JavaScriptObject;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler;
import com.smartgwt.client.widgets.grid.events.SelectionEvent;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.layout.VStack;

/**
 * @author gsaxena
 *
 */
public class WnDgNewWorkflow extends WnDialog {

	private final Button btnNew;
	private Record rcSelWrkfl;
	private final DynamicForm  frmNewWorkflow;
	/**
	 * 
	 */
	public WnDgNewWorkflow() {
		super(500,500,"New Workflow","icons/New.png");
		
		// final WnOpenWorkflow thisWorkflowWindow = this;
	
        final Label lbInsr = new Label("<b>Please select a workflow to open</b>");
        lbInsr.setHeight("2%");
        vsRoot.addMember(lbInsr);
        
        frmNewWorkflow = addDFNewWorkflow();
        frmNewWorkflow.setWidth("100%");  
        frmNewWorkflow.setHeight("85%");  
        frmNewWorkflow.setLayoutAlign(Alignment.LEFT);
        vsRoot.addMember(frmNewWorkflow);
            
        btnNew = new Button("New");
        hsForBtns.addMember(btnNew);
        hsForBtns.addMember(btnCancel);
        
        vsRoot.addMember(hsForBtns);
        
    //    this.addItem(vsRoot); ?? needed      
        this.show();
	}

	/**
	 * @return the rcSelWrkfl
	 */
	public Record getRcSelWrkfl() {
		// GS_ASK: how can I set a record object automatically based on values in a form
		boolean isValid = frmNewWorkflow.validate();
		rcSelWrkfl = new Record();
		if (isValid==true) {
		rcSelWrkfl.setAttribute("workflowID", -1);
		rcSelWrkfl.setAttribute("workflowName", (String) frmNewWorkflow.getValue("workflowName"));
		rcSelWrkfl.setAttribute("briefDescription", (String) frmNewWorkflow.getValue("briefDescription"));
		rcSelWrkfl.setAttribute("version", -1);
		}
		else
		{
			rcSelWrkfl.setAttribute("workflowID", -99);
		}
		
		return rcSelWrkfl;
	}

	
	/**
	 * @return the btnOpen
	 */
	public Button getBtnNew() {
		return btnNew;
	}

	private DynamicForm  addDFNewWorkflow() {
		// TODO Auto-generated method stub
	       DataSource dataSource = DataSource.get("dsGenericWorkflow");
	       dataSource.setClientOnly(true);
	       DynamicForm dfNewWorkflow = new DynamicForm();
	       dfNewWorkflow.setDataSource(dataSource);    
	        
	        return dfNewWorkflow;
	}

	/**
	 * @param jsObj
	 */
	public WnDgNewWorkflow(JavaScriptObject jsObj) {
		super(jsObj);
		btnNew=null;
		frmNewWorkflow=null;
		// TODO Auto-generated constructor stub
	}

}
