Blame view

js/deepClient.js 2.03 KB
00b508a0   luigser   DEEPCLIENT
1
2
3
4
5
6
7
  /**

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

   */

  

  var ComponentService =

  {

  	deep_url:"",

349fcb7c   Luigi Serra   DeepClient javasc...
8
  

00b508a0   luigser   DEEPCLIENT
9
10
      getComponent: function(params){//params = {component, data, fields, placeHolder}

          var request = this.getXMLHttpRequest();

349fcb7c   Luigi Serra   DeepClient javasc...
11
          var component = params.component;

00b508a0   luigser   DEEPCLIENT
12
13
14
15
16
  

          request.onreadystatechange = function(){

              if(request.readyState == 4){

                  try {

                      var resp = JSON.parse(request.response);

b9c8df01   isisadmin   client refactoring
17
                      var link = '<link rel="import" href="' + resp.bridge_link + resp.component_link +'">';

00b508a0   luigser   DEEPCLIENT
18
19
  

                      //Build datalet injecting html code

349fcb7c   Luigi Serra   DeepClient javasc...
20
                      var datalet_code = link + '<' + params.component;

00b508a0   luigser   DEEPCLIENT
21
22
23
24
                      var keys = Object.keys(params.params);

                      for(var i = 0; i < keys.length; i++){

                         datalet_code += ' ' + keys[i] + '="' + params.params[keys[i]] +'"';

                      }

5cce5b3c   isisadmin   client refactoring
25
                      datalet_code += " fields='" + JSON.stringify(params.fields) + "'></" + params.component + ">"; 

00b508a0   luigser   DEEPCLIENT
26
27
28
29
30
31
32
33
34
35
36
37
  

                      (params.placeHolder.constructor == HTMLElement || params.placeHolder.constructor == HTMLDivElement) ? $(params.placeHolder).html(datalet_code) :/*Injection from Web Component*/

                                                                   $("#" + params.placeHolder).html(datalet_code);/*Injection from a static web page*/

  

                  } catch (e){

                      var resp = {

                          status: 'error',

                          data: 'Unknown error occurred: [' + request.response + ']'

                      };

                  }

              }};

  

349fcb7c   Luigi Serra   DeepClient javasc...
38
          request.open('GET', this.deep_url + component);

00b508a0   luigser   DEEPCLIENT
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
          request.send();

      },

  

      getXMLHttpRequest: function ()

      {

          if (window.XMLHttpRequest) {

              return new XMLHttpRequest();

          }

          else {

              try {

                  return new ActiveXObject("MSXML2.XMLHTTP.3.0");

              }

              catch(ex) {

                  return null;

              }

          }

      }

  }