Blame view

datalets/dynamic-datatable-datalet/dynamic-datatable-datalet.html 5.87 KB
94601c1f   Renato De Donato   trevieww multitable
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
  <!--

  @license

      The MIT License (MIT)

  

      Copyright (c) 2015 Dipartimento di Informatica - Universit� di Salerno - Italy

  

      Permission is hereby granted, free of charge, to any person obtaining a copy

      of this software and associated documentation files (the "Software"), to deal

      in the Software without restriction, including without limitation the rights

      to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

      copies of the Software, and to permit persons to whom the Software is

      furnished to do so, subject to the following conditions:

  

      The above copyright notice and this permission notice shall be included in

      all copies or substantial portions of the Software.

  

      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

      THE SOFTWARE.

  -->

  <!--

  * Developed by :

  * ROUTE-TO-PA Project - grant No 645860. - www.routetopa.eu

  *

  -->

  

98d9d8a5   Renato De Donato   filters+groupby
31
  <link rel="import" href="../base-ajax-json-alasql-datalet/base-ajax-json-alasql-datalet.html">

94601c1f   Renato De Donato   trevieww multitable
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  

  <!--

  The `datatable-datalet` is a porting of Datatables JQuery library in a web component that has built up by using Polymer.

  Pass to this component a data url(CKAN api uri) and a string with one or multiple query in JsonPath format(separated by spaces) and it'll show a

  table with data and query attributes with all Datatables library features.

  

  Example:

  

      <datatable-datalet

          data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=#"

          fields='["field1","field2"]'>

      </datatables-datalet>

  

  @element datatable-datalet

  @status v0.1

  @demo demo/index.html

  @group datalets

  -->

  

  <dom-module id="dynamic-datatable-datalet">

      <template>

          <link rel="stylesheet" type="text/css" href="js/DataTables/datatables.css"/>

  

          <span id="_span"></span>

  

498cdf34   Andrea Petta   leafletjs
57
          <base-ajax-json-alasql-datalet data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}" title="{{title}}" description="{{description}}" export_menu="{{export_menu}}"></base-ajax-json-alasql-datalet>

94601c1f   Renato De Donato   trevieww multitable
58
59
60
61
62
      </template>

  

      <script type="text/javascript" src="js/DataTables/datatables.js"></script>

  

      <script>

430e6f23   Renato De Donato   dynamic-datatale ...
63
          var DynamicDatatableBehavior = {

94601c1f   Renato De Donato   trevieww multitable
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  

              presentData: function(){

                  var html = "<table id=\"dynamic-datatable\" class=\"stripe row-border\" cellspacing=\"0\"  style=\"height: auto; width: auto;\">";

  

                  if(!this.data || this.data[0] == undefined) return;

                  html += '<thead>'+

                             '<tr>';

                  for(var x = 0; x<this.data.length; x++){

                     html += '<th>' + this.data[x].name + '</th>';

                  }

                  html +=  '</tr>' +

                           '</thead>' +

                          '<tbody>';

                  for(var i = 0; i<this.data[0].data.length; i++){

                      html += '<tr>';

                      for(var x = 0; x<this.data.length; x++){

                        html += '<td>' + this.data[x].data[i] + '</td>';

                      }

                      html += '</tr>';

                  }

                  html += '</tbody></table>';

  

                  $(this._component.$._span).html(html);

98d9d8a5   Renato De Donato   filters+groupby
87
                  $(this._component.$._span.childNodes[0]).DataTable({"order": []});

94601c1f   Renato De Donato   trevieww multitable
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
              },

  

              _destroy: function(){

                  if(this._component){//evita caso init

                      $(this._component.$._span).html("");

                      //$(this._component.$.datatable).DataTable().destroy();

                      this._component.behavior.selectData();

                      this._component.behavior.presentData();

                  }

              }

  

          };

  

          Polymer({

              is : 'dynamic-datatable-datalet' ,

  

              properties: {

                  /**

                   * It's the component behavior

                   *

                   * @attribute behavior

                   * @type Object

                   * @default {}

                   */

                  behavior : {

                      type : Object,

                      value : {}

                  },

  

                  fields : {

                      observer: '_reload'

498cdf34   Andrea Petta   leafletjs
119
120
121
122
123
124
125
126
127
128
129
130
                  },

                  /**

                   * Control the export menu

                   * xxxx BITMASK. FROM RIGHT : HTML, PNG, RTF, MY SPACE (eg. 1111 show all, 0000 hide all)

                   *

                   * @attribute export_menu

                   * @type Number

                   * @default 15

                   */

                  export_menu : {

                      type  : Number,

                      value : 15 // xxxx BITMASK. FROM RIGHT : HTML, PNG, RTF, MY SPACE (eg. 1111 show all, 0000 hide all)

94601c1f   Renato De Donato   trevieww multitable
131
132
                  }

  

98d9d8a5   Renato De Donato   filters+groupby
133
134
135
136
  //                filters : {

  //                    observer: '_reload'

  //                }

  

94601c1f   Renato De Donato   trevieww multitable
137
138
139
              },

  

              ready: function(){

0b7cbd33   Renato De Donato   title-desciption
140
141
                  $(this).find("base-datalet")[0].hideFooter();

  

98d9d8a5   Renato De Donato   filters+groupby
142
                  this.behavior =  $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonAlasqlBehavior, DynamicDatatableBehavior);

94601c1f   Renato De Donato   trevieww multitable
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
                  this.async(function(){this.behavior.init(this)}, 0);

              },

  

              _reload: function(){

  

                  if(this.fields.constructor == Array);//fields in selectData --> from Array to String

                  else{

                      this.behavior._destroy();

  //                    this.behavior.selectData();

  //                    this.behavior.presentData();

                  }

              }

          });

  

      </script>

  </dom-module>