/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.pci.transactions.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.DSCallback;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.widgets.grid.ListGrid;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ISOTransactionClient implements EntryPoint
{
	public void onModuleLoad()
	{
		Criteria criteria = null;
		final ListGrid dataGrid = new ListGrid(DataSource.get("ext_transactions_SPPIM"));
		dataGrid.setAutoFetchData(true);
		dataGrid.setCanSelectCells(true);
		dataGrid.setEditByCell(true);
		dataGrid.setGenerateClickOnSpace(true);
		dataGrid.setCanDragSelect(true);
		dataGrid.setCanSelectAll(true);
		dataGrid.setUseCopyPasteShortcuts(true);
		dataGrid.setShowFilterEditor(true);
		dataGrid.setCanEdit(true);
		dataGrid.setShowAllColumns(true);
		dataGrid.setAutoFetchData(false);
		dataGrid.setAutoSaveEdits(false);
		dataGrid.setUseAllDataSourceFields(true);
		dataGrid.fetchData(criteria, new DSCallback()
		{
			@Override
			public void execute(DSResponse response, Object rawData, DSRequest request)
			{
				if (response.getStatus() == DSResponse.STATUS_SUCCESS && response.getData() != null & response.getData().length > 0)
				{
					Record[] records = response.getData();
					if (records.length > 0)
					{
						boolean shortDay = true;
						boolean longDay = false;

						if (shortDay)
						{
							dataGrid.hideField("hour2");
						}
						if (longDay)
						{
							dataGrid.showField("hour2s");
						}
						else
						{
							dataGrid.hideField("hour2s");
						}
					}
				}
			}
		});

		dataGrid.setWidth(1000);
		dataGrid.draw();
	}
}
