 wdc_base = require '../connector_base/starschema_wdc_base.coffee'
 json_flattener = require './json_flattener.coffee'
 
-
-load_json = (url, success_callback)->
-  $.ajax
-    url: url
-    datatype: "json"
-    success: (data, textStatus, request)->
-      success_callback(data)
-    error: (xhr, ajaxOptions, thrownError)->
-      console.error("Error during search request", thrownError)
-      tableau.abortWithError "Error while trying to load '#{url}'. #{thrownError}"
 
 load_jsonp = (url, success_callback)->
   $.ajax


      data.url = url

    "enter run": (data)->
      wdc_base.set_connection_data( data )
      tableau.submit()

    "enter run_mongo": (data)->
      wdc_base.set_connection_data( data )
      tableau.submit()

  rows: (connection_data, lastRecordToken)->
    offset_str = if lastRecordToken == "" then 0 else lastRecordToken
    offseted_url = "#{connection_data.url}&skip=#{offset_str}"

    load_jsonp offseted_url, (data)->

      {offset: offset, rows: rows, total_rows: total_rows} = data

      # when we reached the last page, it is signaled by returning
      # 0 rows
