package com.fit.klinika.client.radnik;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.smartgwt.client.types.TopOperatorAppearance;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.FilterBuilder;
import com.smartgwt.client.widgets.form.fields.DateItem;
import com.smartgwt.client.widgets.form.fields.IntegerItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.VStack;

public class RadnikUI extends Composite {

	private LayoutPanel lpRadnik = new LayoutPanel();
	
	public RadnikUI() {
		initWidget(lpRadnik);
		lpRadnik.setSize("1200", "1300");
		
		 RadnikDS radnikDS = new RadnikDS();
		
		final ListGrid listGridRadnik = new ListGrid();
		listGridRadnik.setSize("1000", "500");
		
		
		listGridRadnik.setDataSource(radnikDS);
		listGridRadnik.setAutoFetchData(true);
		listGridRadnik.setCanRemoveRecords(true);
		final ListGridField idRadnikField = new ListGridField("id");
		//idosobljeField.setHidden(true);
		idRadnikField.setCanFilter(false);
		idRadnikField.setCanEdit(false);
		idRadnikField.setTitle("ID");
		final ListGridField nazivField = new ListGridField("naziv");
		nazivField.setTitle("Ime prezime");
		
		final ListGridField datumField = new ListGridField("datum");
		
		final ListGridField jmbgField = new ListGridField("jmbg");
		//idosobljeField.setHidden(true);
		
		final ListGridField strucnaSpremaField = new ListGridField("strucnaSprema");
		
		final ListGridField idOdeljenjeField = new ListGridField("idodeljenje");
		idOdeljenjeField.setHidden(true);
		idOdeljenjeField.setCanFilter(false);
		final ListGridField nazivOdeljenjaField = new ListGridField("naziv");
		nazivOdeljenjaField.setTitle("Odeljenje");
		final ListGridField idVrstaRadnikaField = new ListGridField("vrsta_radnika_id");
		//idosobljeField.setHidden(true);
		idVrstaRadnikaField.setCanFilter(false);
		idVrstaRadnikaField.setHidden(true);
		final ListGridField nazivVrsteRadnikaField = new ListGridField("nazivVrsteRadnika");
		nazivVrsteRadnikaField.setTitle("Vrsta Radnika");
		
		final ListGridField idDoktorOblastiField = new ListGridField("doktor_oblast_id");
		//idosobljeField.setHidden(true);
		idDoktorOblastiField.setCanFilter(false);
		idDoktorOblastiField.setHidden(true);
		final ListGridField nazivDoktoraOblastField = new ListGridField("nazivDoktoraOblast");
		
		
		listGridRadnik.setFields(idRadnikField,nazivField,datumField,jmbgField,strucnaSpremaField,
				idOdeljenjeField,nazivOdeljenjaField,idVrstaRadnikaField,nazivVrsteRadnikaField,idDoktorOblastiField,nazivDoktoraOblastField);
//		listGridRadnik.setFields(idRadnikField,nazivField,datumField,jmbgField,strucnaSpremaField,
//				idOdeljenjeField,nazivOdeljenjaField);
		
		//listGridRadnik.setFields(idRadnikField,nazivField,datumField,jmbgField,strucnaSpremaField);
				
		
		
		final FilterBuilder fbRadnik = new FilterBuilder();
		
		fbRadnik.setDataSource(radnikDS);
		fbRadnik.setTopOperatorAppearance(TopOperatorAppearance.RADIO);
		
		
		final Button filterRadnikButton = new Button("Filter"); 
		//filterDoktorOblastButton.setTitle("Filter");
		filterRadnikButton.setWidth("40");
		filterRadnikButton.setHeight("40");
		
		
		filterRadnikButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				listGridRadnik.filterData(fbRadnik.getCriteria());
			}
		});
		
		final DynamicForm dfRadnik = new DynamicForm();
		
		final TextItem nazivItem = new TextItem("naziv");
		nazivItem.setTitle("Ime prezime");
		nazivItem.setRequired(true);
		
		final DateItem datumItem = new DateItem("datum");
		datumItem.setTitle("Datum");
		datumItem.setRequired(true);
		
		final IntegerItem jmbgItem = new IntegerItem("jmbg");
		jmbgItem.setTitle("JMBG");
		jmbgItem.setRequired(true);
		
		dfRadnik.setItems(nazivItem,datumItem,jmbgItem);
		
		
		final VStack vstack = new VStack(10);
		vstack.addMember(dfRadnik);
		vstack.addMember(fbRadnik);
		vstack.addMember(filterRadnikButton);
		vstack.addMember(listGridRadnik);
		
		lpRadnik.add(vstack);
		lpRadnik.setWidgetLeftWidth(vstack, 30.0, Unit.PX, 1000.0, Unit.PX);
		lpRadnik.setWidgetTopHeight(vstack, 30.0, Unit.PX, 1000.0, Unit.PX);
		
		
		
	}

}
