Blame view

controllets/select-fields-controllet/select-fields-controllet.html 4.4 KB
89558a41   Renato De Donato   datatype, provide...
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
  <link rel="import" href="../../bower_components/polymer/polymer.html" />
  
  <link rel="import" href="../../bower_components/paper-material/paper-material.html" />
  <link rel="import" href="../../bower_components/paper-menu/paper-menu.html">
  <link rel="import" href="../../bower_components/paper-item/paper-item.html">
  
  <dom-module id="select-fields-controllet">
  
      <style is="custom-style">
  
          #select_fields_controllet_container {
              height: 100%;
              width: 100%;
          }
  
          #select_fields_controllet_container * {
              font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
              font-size: 16px;
              line-height: 24px;
          }
  
          #select_fields_controllet_container #header {
              background: #B6B6B6;
              height: 24px;
              padding: 12px;
              text-align: center;
              font-weight: 700;
              cursor: pointer;
          }
  
          #select_fields_controllet_container #menu_container {
              position: relative;
              height: calc(100% - 48px);
              width: 100%;
          }
  
          paper-menu {
              padding: 0px;
          }
  
          paper-item {
              cursor: pointer;
              color: #000000;
              margin: 4px;
          }
  
          paper-item.iron-selected {
              background: #2196F3;
              color: #FFFFFF;
          }
  
          paper-item:focus:before {
              opacity: 0 !important;
              background: white;
          }
  
          paper-item:focus:after {
              opacity: 0 !important;
              background: white;
          }
  
          paper-item:hover:not(.iron-selected) {
              background-color: rgba(0, 0, 0, 0.12);
          }
  
      </style>
  
      <template>
  
          <paper-material id="select_fields_controllet_container" elevation="5">
  
              <div id="header" on-click="_invertSelection"><span id="fields"></span></div>
              <div id="menu_container">
                  <paper-menu id="menu" multi>
                      <template is="dom-repeat" items="{{fields}}">
                          <paper-item>{{item}}</paper-item>
                      </template>
                  </paper-menu>
              </div>
  
          </paper-material>
  
      </template>
  
      <script>
          Polymer({
  
              is : 'select-fields-controllet',
  
              properties : {
  
                  fields : {
                      type  : Array,
                      value : []
                  },
  
  //                preselectedFields : {
  //                    type : Array,
  //                    value : []
  //                }
              },
  
              listeners: {
                  'iron-activate': '_fireSelectedFields'
              },
  
              ready : function() {
                  $(this.$.menu_container).perfectScrollbar();
              },
  
              attached : function() {
                  this._translate();
  
  //                if (this.preselectedFields.length > 0)
  //                    this._preselectFields();
              },
  
              setFields : function(fields) {
                  this.fields = fields;
              },
  
              setSelectFields : function(selectFields) {
                  for(var i=0; i<selectFields.length; i++)
                      this.$.menu.select(selectFields[i]);
                  this._fireSelectedFields();
              },
  
              reset: function() {
                  this.$.menu.selectedValues = [];
                  this.setFields([]);
              },
  
              _translate : function() {
                  this.$.fields.innerHTML = ln["fields_" + ln["localization"]];
              },
  
  //            _preselectFields : function() {
  //                for(var i=0; i<this.preselectedFields.length; i++)
  //                    this.$.menu.select(this.preselectedFields[i]);
  //                this._fireSelectedFields();
  //            },
  
              _fireSelectedFields : function() {
                  this.debounce('_fireSelectedFields', function () {
                      this.fire('select-fields-controllet_selected-fields', {selectedFields: this.$.menu.selectedValues});
                  }, 300);
              },
  
              _invertSelection : function() {
  //                for(var i=this.fields.length-1; i>=0; i--)
                  for(var i=0; i<this.fields.length; i++)
                      this.$.menu.select(i);
  
                  $(this.$.menu_container).animate({ scrollTop: 0}, 0);
  
                  this._fireSelectedFields();
              }
  
          });
  
      </script>
  
  </dom-module>