package ibase.client;
import java.util.ArrayList;
import java.util.Date;
import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */

public class GWTDashBoardReport implements EntryPoint
{
	ArrayList<String> parameterList = new ArrayList<String>();
	ArrayList<FilterInfo> filterList = new ArrayList<FilterInfo>();
	HorizontalPanel hpanel= new HorizontalPanel();
	String metadataname = "";
	@SuppressWarnings("unchecked")
	public void onModuleLoad()
		{
			metadataname = Window.Location.getParameter("metadataname") == null ? "" : Window.Location.getParameter("metadataname");
			parameterList.add(metadataname);
			E12DashBoardPage.getJsonForFilterData(new Callback<JSONObject, String>()
			{
				@Override
				public void onSuccess(JSONObject jsnObj)
				{
					getParameterList(jsnObj);
				}
				@Override
				public void onFailure(String result)
				{
					Window.alert("Exception :: onModuleLoad() [" + result + "]");
				}
			}, metadataname);
		}
		
		public void getParameterList(JSONObject metaDataJsnObj)
		{
            Date date = new Date();
			MetaDataDtl dataDtl = new MetaDataDtl();
			filterList          =dataDtl.getFilters(metaDataJsnObj);
			int year=0;
			String month="";
			String monthYear="";
			year= 1900+date.getYear();
			month=String.valueOf(date.getMonth()+1);
            if(month.trim().length()==1)
            {
            	month="0"+month;
            }
            monthYear=year+month;
            if(filterList.size()>0)
            {
				for (FilterInfo filterInfo : filterList)
				{
					if(filterInfo.getColNameId().equals("PRD_CODE"))
					{
						parameterList.add(Window.Location.getParameter(filterInfo.getColNameId()) == null ? monthYear : Window.Location.getParameter(filterInfo.getColNameId()));
					}
					else
					{
						parameterList.add(Window.Location.getParameter(filterInfo.getColNameId()) == null ? "" : Window.Location.getParameter(filterInfo.getColNameId()));
					}
				}
            }
            else
            {
            	parameterList.add(Window.Location.getParameter("metadataname"));
            }
            E12DashBoardPage e12DashBoardPage = new E12DashBoardPage(parameterList,metaDataJsnObj);
		    RootPanel.get("filterDiv").add(e12DashBoardPage);
		}

}
