Blame view

datalets/datatable-datalet/datatable-datalet.html 4.54 KB
73bcce88   luigser   COMPONENTS
1
  <!--

5e6ba8af   isisadmin   datalet doc update
2
3
  @license

      The MIT License (MIT)

73bcce88   luigser   COMPONENTS
4
  

5e6ba8af   isisadmin   datalet doc update
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
      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.

  -->

ae17a8dc   Luigi Serra   Controllet and da...
25
  <!--

950d181d   Luigi Serra   license updates
26
27
  * Developed by :

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

ae17a8dc   Luigi Serra   Controllet and da...
28
29
  *

  -->

5e6ba8af   isisadmin   datalet doc update
30
31
32
33
34
  

  <link rel="import" href="../base-ajax-json-jsonpath-datalet/base-ajax-json-jsonpath-datalet.html">

  

  <!--

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

73bcce88   luigser   COMPONENTS
35
36
37
  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.

  

5e6ba8af   isisadmin   datalet doc update
38
  Example:

73bcce88   luigser   COMPONENTS
39
  

5e6ba8af   isisadmin   datalet doc update
40
41
42
      <datatable-datalet

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

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

73bcce88   luigser   COMPONENTS
43
44
      </datatables-datalet>

  

5e6ba8af   isisadmin   datalet doc update
45
46
47
48
  @element datatable-datalet

  @status v0.1

  @demo demo/index.html

  @group datalets

73bcce88   luigser   COMPONENTS
49
  -->

73bcce88   luigser   COMPONENTS
50
51
52
  

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

      <template>

a1f0799c   isisadmin   datalet global re...
53
          <link rel="stylesheet" href="js/DataTables-master/media/css/jquery.dataTables.min.css">

73bcce88   luigser   COMPONENTS
54
55
56
  

          <table id="datatable" class="table table-striped table-bordered" cellspacing="0" style="height: auto; width: auto;">

          </table>

ec5b0925   isisadmin   datalet chaching ...
57
          <base-ajax-json-jsonpath-datalet data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}"></base-ajax-json-jsonpath-datalet>

73bcce88   luigser   COMPONENTS
58
59
60
      </template>

  

      <script src="js/DataTables-master/media/js/jquery.dataTables.js"></script>

73bcce88   luigser   COMPONENTS
61
62
63
  

      <script>

          var DatatableBehavior = {

73bcce88   luigser   COMPONENTS
64
  

5bc002a2   isisadmin   datalet refactoring
65
              presentData: function(){

9d4a34db   Luigi Serra   selection control...
66
                  if(!this.data || this.data[0] == undefined) return;

73bcce88   luigser   COMPONENTS
67
68
69
                  html = "";

                  html += '<thead>'+

                             '<tr>';

a1f0799c   isisadmin   datalet global re...
70
71
                  for(var x = 0; x<this.data.length; x++){

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

73bcce88   luigser   COMPONENTS
72
73
74
75
76
                  }

                  html +=  '</tr>' +

                           '</thead>' +

                           '<tfoot>' +

                           '<tr>';

a1f0799c   isisadmin   datalet global re...
77
78
                  for(var x = 0; x<this.data.length; x++){

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

73bcce88   luigser   COMPONENTS
79
80
81
82
                  }

                  html += '</tr>' +

                          '</tfoot>' +

                          '<tbody>';

a1f0799c   isisadmin   datalet global re...
83
                  for(var i = 0; i<this.data[0].data.length; i++){

73bcce88   luigser   COMPONENTS
84
                      html += '<tr>';

a1f0799c   isisadmin   datalet global re...
85
86
                      for(var x = 0; x<this.data.length; x++){

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

73bcce88   luigser   COMPONENTS
87
88
89
90
91
                      }

                      html += '</tr>';

                  }

                  html += '</tbody>';

  

f748e9cf   Luigi Serra   new controllet an...
92
                  $(this._component.$.datatable).html(html);

73bcce88   luigser   COMPONENTS
93
94
95
96
97
98
                  $(this._component.$.datatable).DataTable();

              }

          };

  

          Polymer({

              is : 'datatable-datalet' ,

e5b73e81   isisadmin   addded behavior p...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  

              properties: {

                  /**

                   * It's the component behavior

                   *

                   * @attribute behavior

                   * @type Object

                   * @default {}

                   */

                  behavior : {

                      type : Object,

                      value : {}

                  }

              },

  

73bcce88   luigser   COMPONENTS
114
              ready: function(){

e5b73e81   isisadmin   addded behavior p...
115
                  this.behavior =  $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, DatatableBehavior);

eb240478   Luigi Serra   public room cards...
116
                  this.async(function(){this.behavior.init(this)},1000);

73bcce88   luigser   COMPONENTS
117
              }

73bcce88   luigser   COMPONENTS
118
          });

e5b73e81   isisadmin   addded behavior p...
119
  

73bcce88   luigser   COMPONENTS
120
121
122
      </script>

  </dom-module>