Blame view

controllets/treeview-controllet/treeview-controllet.html 10.9 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  <link rel="import" href="../../bower_components/polymer/polymer.html">

  <link rel="import" href="../../bower_components/paper-styles/color.html">

  <link rel="import" href="../../bower_components/paper-item/paper-item.html">

  <link rel="import" href="../../bower_components/paper-card/paper-card.html">

  

  

  

  <dom-module id="treeview-controllet">

      <template>

          <style is="custom-style">

  

              :host ::content .list {

                  margin: .5rem;

                  display: block;

                  list-style-type: none;

              }

  

              :host ::content .list__item {

                  margin: 0 0 .5rem 0;

                  padding: 0;

              }

  

              :host ::content .label--checkbox {

                  position: relative;

                  margin: .5rem;

                  font-family: Arial, sans-serif;

                  line-height: 135%;

                  cursor: pointer;

                  padding-left: 30px;

                  padding-top: 0px;

              }

  

              :host ::content .checkbox + label {

                  /*text-indent: -5000px;

                  height: 20px;

                  width: auto;*/

              }

  

              :host ::content input[type="checkbox"]:not(:checked), :host ::content input[type="checkbox"]:checked {

                   position: relative;

                   left: 10px;

                   visibility: visible;

              }

  

              :host ::content .checkbox {

                  position: relative;

                  /*top: -0.375rem;*/

                  top: 3px;

                  margin: 0 1rem 0 0;

                  cursor: pointer;

                  min-height: 0;

                  max-height: 0;

              }

  

              :host ::content .checkbox:before {

                  -webkit-transition: all 0.3s ease-in-out;

                  -moz-transition: all 0.3s ease-in-out;

                  transition: all 0.3s ease-in-out;

                  content: "";

                  position: absolute;

                  left: 0;

                  z-index: 1;

                  width: 1.2em;

                  height: 1.2em;

                  border: 2px solid #DDDDDD;

              }

  

              :host ::content .checkbox:checked:before {

                  -webkit-transform: rotate(-45deg);

                  -moz-transform: rotate(-45deg);

                  -ms-transform: rotate(-45deg);

                  -o-transform: rotate(-45deg);

                  transform: rotate(-45deg);

                  height: 1em;

                  border-color: var(--paper-blue-500);

                  border-top-style: none;

                  border-right-style: none;

              }

  

              :host ::content .checkbox:after {

                  content: "";

                  position: absolute;

                  top: -0.125em;

                  left: 0;

                  width: 1.4em;

                  height: 1.4em;

                  background: #fff;

                  cursor: pointer;

              }

  

              :host ::content .select-all{

                  position:relative;

                  float:left;

                  left: 20px;

                  top: -3px;

              }

  

              :host ::content div.hiding-panel{

                  width: auto;

                  padding: 3px;

                  height: 30px;

                  border: 1px;

                  background: #fff;

                  border-radius: 0.125rem;

                  box-shadow: 0 0.125rem 0.3125rem 0 rgba(0, 0, 0, 0.25);

              }

  

              :host ::content div.panel-title{

                  position: relative;

                  float: left;

                  padding-left: 10px;

                  font-weight: bolder;

                  color: #000000;

              }

  

              :host ::content iron-icon.panel-hide-trigger {

                  position: relative;

                  float: left;

                  height: 24px;

                  width: 24px;

                  border-radius: 50%;

                  /*background: var(--paper-pink-500);*/

                  background: #348ED5;

                  color: white;

                  line-height: 64px;

              }

  

              :host ::content iron-icon.panel-hide-trigger:hover {

                  /*color: var(--google-gray-700);*/

                  color : #000000;

              }

  

              :host ::content .items-list{

                  display: none;

              }

  

          </style>

  

          <div class="vertical-section">

              <div id="treeview_placeholder" class="horizontal-section"></div>

          </div>

  

      </template>

  

      <script>

  

          Polymer({

  

              is : 'treeview-controllet',

  

              listeners : {

                  'tap' : '_clickHandler'

              },

  

              properties : {

  

                  fieldsMap : {

                      type : Map,

                      value : null

                  }

  

              },

  

              createFieldsContainer : function(id, heading, level){

  

                  var ul = document.createElement('ul');

                  ul.className     = "list";

                  ul.id                  = id;

                  ul.innerHTML           = '<div class="hiding_panel">' +

                                              '<iron-icon icon="chevron-right" class="panel-hide-trigger"></iron-icon>' +

                                              '<div class="panel-title">' + heading + '</div>' +

                                              '<input id="'+ heading +'" type="checkbox" class="checkbox select-all">' +

                                           '</div>' +

cb1aab91   Luigi Serra   Controllets update
174
175
176
                                           '<br>';

                                           /*'<div class="items-list"></div>';*/

                  ul.innerHTML += (id.indexOf("records") != -1)  ?  '<div class="items-list" style="display:block;"></div>' : '<div class="items-list"></div>';

73bcce88   luigser   COMPONENTS
177
178
179
180
181
182
183
184
185
186
187
188
189
  

                  return ul;

  

              },

  

              createListItem : function(id, label) {

                  return '<li class="list__item">'

                              + '<input id="'+ id +'" type="checkbox" class="checkbox">'

                              + '<div class="label--checkbox">'+ label +'</div>'

                       + '</li>';

              },

  

              analyzeObject : function(parent_list, curr_field, object) {

0b818d7e   Luigi Serra   Selection control...
190
                  if(object == null) return;

73bcce88   luigser   COMPONENTS
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
                  if(curr_field != null){

                      if(object == null) object = "";

  

                      if(object.constructor == Array){//Deal with flat array case

                          if(object[0].constructor != Object){

                              //MATERIAL CHECKBOX UL

                              this.fieldsMap[parent_list[parent_list.length - 2]].children[2].innerHTML += this.createListItem(parent_list.toString(), curr_field);

                              return;

                          }

                      }

                      if(object.constructor == Array || object.constructor == Object){

                          var panel = this.createFieldsContainer(curr_field, parent_list[parent_list.length - 1], parent_list.length);

                          this.fieldsMap[curr_field] = panel;

                          //MATERIAL CHECKBOX UL

                          this.fieldsMap[parent_list[parent_list.length - 2]].appendChild(this.fieldsMap[curr_field]);

                      }else{

                          //MATERIAL CHECKBOX UL

                          this.fieldsMap[parent_list[parent_list.length - 2]].children[2].innerHTML += this.createListItem(parent_list.toString(), curr_field);

                      }

                  }

                  if(object.constructor == Array || object.constructor == Object) {

                      var obj = (object.constructor == Array) ? object[0] : object;

                      if(Object.prototype.toString.call(obj) === '[object String]') return;//Deal with flat array case

                      for (var field in obj) {

                          var parents = new Array();

                          parent_list.every(function (element, index, array) {

                              parents.push(element);

                              return true;

                          });

                          parents.push(field);

                          this.analyzeObject(parents, field, obj[field]);

                      }

                  }

              },

  

              init : function(data){

                  //crete root node and insert it in to shadow dom

                  var mainPanel = this.createFieldsContainer("root", "Data fields", 0);

                  //MATERIAL CHECKBOX UL

                  mainPanel.children[2].style.display = "block";

  

                  this.$.treeview_placeholder.innerHTML = "";

                  this.$.treeview_placeholder.appendChild(mainPanel);

                  this.fieldsMap = new Map;

                  this.fieldsMap["root"] = mainPanel;

                  //call recursive analyze function for current json to get all fields user can select

                  this.analyzeObject(new Array("root"), null, data);

  

              },

  

              fireSelectedFields : function(){

  

                  var cbs = Polymer.dom(this.$.treeview_placeholder).querySelectorAll('input[type=checkbox]:checked');

                  var fields = Array();

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

                      if(cbs[i].className.includes("select-all")) continue;

                      fields.push(cbs[i].id.replace("root,",""));

                  }

  

                  this.fire('treeview-controllet-fileds-selected', {fields : fields});

              },

  

              _clickHandler : function(e){

                  if(!e.target.control) {

                      switch((e.target.className.indexOf("iron-icon") != -1) ? "panel-hide-trigger" : e.target.className){

                          case 'checkbox':

  

                              this.fireSelectedFields();

  

                              break;

                          case 'panel-hide-trigger':

  

                              if(e.target.parentNode.parentNode.children[2].style.display == "block") {

                                  e.target.parentNode.parentNode.children[2].style.cssText = "display: none;";

                                  e.target.icon = "chevron-right";

  

                              }else{

                                  e.target.parentNode.parentNode.children[2].style.cssText = "display: block;";

                                  e.target.icon = "expand-more";

                              }

                              break;

                          case 'checkbox select-all':

                                  var childs = e.srcElement.parentNode.parentNode.children[2].childNodes;

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

                                      childs[i].children[0].checked = e.srcElement.checked;

                                  }

  

                                  this.fireSelectedFields();

  

                              break;

                      }

                  }

              }

          });

  

      </script>

  

  </dom-module>