package com.mars.helios.heliosweb.client.datasource;

import com.smartgwt.client.data.fields.DataSourceTextField;
import java.util.List;

/**
 * Data Source for access to cached grid data over rest URLs.
 *
 * @author Yannick Kirschhoffer <yannick.kirschhoffer@cgi.com>
 */
public class HeliosGridDS extends AbstractHeliosDS {

    public static final String PROPERTY_GRIDID = "grid-id";
    public static final String PROPERTY_CONNECTIONID = "connection-id";

    public HeliosGridDS(String connectionId, String gridId, List<String> headers) {
        super("api/rest/grid");

        DataSourceTextField[] fields = new DataSourceTextField[headers.size()];

        for (int fieldIndex = 0; fieldIndex < fields.length; fieldIndex++) {
            fields[fieldIndex] = new DataSourceTextField(headers.get(fieldIndex));
        }

        this.setFields(fields);
        this.setDisableQueuing(false);
        this.setJsonSuffix("");
        this.setJsonPrefix("");

        super.setExtraJSONParameters(
                "\"" + PROPERTY_CONNECTIONID + "\": \"" + connectionId
                + "\", \"" + PROPERTY_GRIDID + "\": \"" + gridId + "\"");
    }
}
