Blame view

datalets/shared_js/behaviors/AjaxJsonDataRequestBehavior.js 1.34 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  /**

   * Created by Luigi Serra on 25/06/2015.

   */

  var AjaxJsonDataRequestBehavior ={

      properties: {

          /**

           * It contains the json data from async xhr call returned from core-ajax core component

           *

           * @attribute json_results

           * @type object

           * @default 'null'.

           */

          json_results: {

              type: Object,

              value: {}

          }

      },

      requestData: function(){

  

          var comp = this;

  

          $.ajax({

              url: this._component.dataUrl,

              dataType: "json",

              success: function(e){

                  comp.handleResponse(e);

              }

          });

      },

      /**

       * Called when core-ajax component receive the json data from called url. It is responsible to

       * extract data from response, coded in json, and refine it by using JsonPath queries in the query attribute.

       * After this phase it parses the resulting object to populate the structure(keys,values) to fill the final table by using

       * angularJs syntax.

       *

       * @method handleResponse

       */

      handleResponse: function(e) {

          this.properties.json_results.value = e;

          this.runWorkcycle();

      },

      getPropertyName: function(query){

          return query.substring(query.lastIndexOf("['") + 2, query.lastIndexOf("']") );

      }

  }