/*******************************************************************************
 * Copyright (c) 2008 IBM Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
dojo.provide("org.eclipse.cosmos.provisional.dr.ps.components.widget.DataView");
dojo.require("org.eclipse.cosmos.provisional.dr.ps.components.utility.common");
dojo.require("dijit.layout.ContentPane");

 dojo.declare(
	'org.eclipse.cosmos.provisional.dr.ps.components.widget.DataView',
	[org.eclipse.cosmos.provisional.dr.ps.components.widget.WidgetContainer], 
	{
		queryText: "",
		mdrName: "",
        openWith: "",
        
        dataview: function(){
			var query = this.queryText;
			var postData = "mdrName="+this.mdrName+"&query="+query;
			if (this.openWith == "TabularView") {
                console.debug("Tabular");
				var deferred = dojo.rawXhrPost({
				url: "json?service=org/eclipse/cosmos/internal/dr/drs/service/outputter/DataViewOutputter",
				postData: postData,
				handle: function(response, ioArgs){
					dojo.publish("DataView", [{contextMap:{queryResponse:response,nodeClass:"ActualDataView"}}]);
					return response;
				}
			  });
            } else {
            	var deferred = dojo.rawXhrPost({
				url: "json?service=org/eclipse/cosmos/internal/dr/drs/service/outputter/DataViewOutputter",
				postData: postData,
				handle: function(response, ioArgs){
					dojo.publish("DataView", [{contextMap:{queryResponse:response,nodeClass:"ActualTreeView"}}]);
					return response;
				}
			  });
            }
		},
		initWidget: function(UIContext, contextMap){
			this.inherited(arguments);
			if (this.mdrName)
				this.dataview();
	    }
	    
	}
);
