1 /*
  2  * Copyright (c) 2014 LabKey Corporation
  3  *
  4  * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
  5  */
  6 
  7 LABKEY.Query.GetData = new function(impl) {
  8 
  9     /**
 10      * Used to render a queryWebPart around a response from GetData.
 11      * @function
 12      * @param {Object} config The config object for renderQueryWebpart is nearly identical to {@link LABKEY.Query.GetData.getRawData},
 13      * except it has an additional parameter <strong><em>webPartConfig</em></strong>, which is a config object for
 14      * {@link LABKEY.QueryWebPart}. Note that the Query returned from GetData is a read-only temporary query, so some
 15      * features of QueryWebPart may be ignored (i.e. <em>showInsertButton</em>, <em>deleteURL</em>, etc.).
 16      * @see LABKEY.QueryWebPart
 17      * @see LABKEY.Query.GetData.getRawData
 18      */
 19     impl.renderQueryWebPart = function(config) {
 20         var jsonData = validateGetDataConfig(config);
 21         jsonData.renderer.type = 'json';
 22         jsonData.renderer.maxRows = 0;
 23 
 24         if (!config.webPartConfig) {
 25             throw new Error("A webPartConfig object is required.");
 26         }
 27 
 28         var requestConfig = {
 29             method: 'POST',
 30             url: LABKEY.ActionURL.buildURL('query', 'getData', config.source.containerPath),
 31             jsonData: jsonData,
 32             success: function(response){
 33                 var json = LABKEY.Utils.decode(response.responseText);
 34                 config.webPartConfig.schemaName = config.source.schemaName;
 35                 config.webPartConfig.queryName = json.queryName;
 36                 new LABKEY.QueryWebPart(config.webPartConfig);
 37             },
 38             failure: function(response, options) {
 39                 if (response.status != 0) {
 40                     LABKEY.Utils.displayAjaxErrorResponse(response, null, true, "Error during GetData call");
 41                 }
 42             }
 43         };
 44 
 45         LABKEY.Ajax.request(requestConfig);
 46     };
 47     return impl;
 48 
 49 }(LABKEY.Query.GetData);
 50