Blame view

controllets/draggable-element-controllet/draggable-element-controllet.html 12.6 KB
938d1928   Luigi Serra   Update documentat...
1
2
  <!--

  @license

584d6ecd   Luigi Serra   Update components...
3
      The MIT License (MIT)

938d1928   Luigi Serra   Update documentat...
4
  

584d6ecd   Luigi Serra   Update components...
5
      Copyright (c) 2015 Dipartimento di Informatica - Università di Salerno - Italy

938d1928   Luigi Serra   Update documentat...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  

      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
  *

  -->

938d1928   Luigi Serra   Update documentat...
30
  

73bcce88   luigser   COMPONENTS
31
32
  <link rel="import" href="../../bower_components/polymer/polymer.html">

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

f748e9cf   Luigi Serra   new controllet an...
33
34
  <link rel="import" href="../../bower_components/paper-material/paper-material.html">

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

73bcce88   luigser   COMPONENTS
35
  

938d1928   Luigi Serra   Update documentat...
36
37
38
39
40
41
42
  <!--

  `draggable-element-controllet` is a controllet that represents a draggable element. It can be a target or source. When it's a suorce is possible to drag the content in to a

   container( a draggable-element-controllet with target feature active). When it's a target it manage the drag-and event to get the the text and id value of the source content.

   During the dragging phase all the target border will be emphasize to facilitate the drop phase.

  

  Example:

  

4e7eacf4   Luigi Serra   Controllets and d...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
      SOURCE

  

      <draggable-element-controllet

         identifier="MyId"

         label="MyLablel">

      </draggable-element-controllet>

  

      TARGET

  

      <draggable-element-controllet

         is-target="true"

         heading="MyHeading"

         description="MyDescription"

         number="MyIndex">

      </draggable-element-controllet>

938d1928   Luigi Serra   Update documentat...
58
59
60
61
62
63
64
65
66
  

  

  @element draggable-element-controllet

  @status beta

  @homepage

  @group controllets

  -->

  

  

73bcce88   luigser   COMPONENTS
67
68
69
70
  <dom-module id="draggable-element-controllet">

      <template>

  

          <style is="custom-style">

73bcce88   luigser   COMPONENTS
71
  

f748e9cf   Luigi Serra   new controllet an...
72
73
74
75
              :host{

                  font-size: 0.84em;

              }

  

73bcce88   luigser   COMPONENTS
76
              .drag-content-target{

f748e9cf   Luigi Serra   new controllet an...
77
                  margin-bottom: 6em;

73bcce88   luigser   COMPONENTS
78
79
80
81
82
                  width: 13.5em;

                  font-weight: bolder;

              }

  

              .drag-content-source{

74249687   Luigi Serra   Cross browser con...
83
                  height: 1.5em;

73bcce88   luigser   COMPONENTS
84
                  width: 12.5em;

73bcce88   luigser   COMPONENTS
85
86
              }

  

f748e9cf   Luigi Serra   new controllet an...
87
              .draggable-card-source{

73bcce88   luigser   COMPONENTS
88
89
90
                  position: relative;

                  float: left;

                  margin : 0.625em;

f748e9cf   Luigi Serra   new controllet an...
91
                  height: 1.5em;

73bcce88   luigser   COMPONENTS
92
                  width: 13.5em;

f748e9cf   Luigi Serra   new controllet an...
93
94
                  border-width : 0.0625em;

                  background-color: #e8e8e8;;

73bcce88   luigser   COMPONENTS
95
                  padding: 1em;

73bcce88   luigser   COMPONENTS
96
97
98
                  overflow: hidden;

              }

  

f748e9cf   Luigi Serra   new controllet an...
99
              .draggable-card-target{

73bcce88   luigser   COMPONENTS
100
101
102
                  position: relative;

                  float: left;

                  margin : 0.625em;

74249687   Luigi Serra   Cross browser con...
103
                  height: 1.5em;

73bcce88   luigser   COMPONENTS
104
                  width: 13.5em;

f748e9cf   Luigi Serra   new controllet an...
105
106
107
                  border-width : 0.0625em;

                  background-color: #2196f3;;

                  color: #ffffff;

73bcce88   luigser   COMPONENTS
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
                  padding: 1em;

                  overflow: hidden;

              }

  

              .avatar {

                  display: inline-block;

                  position: relative;

                  float: left;

                  height: 2em;

                  width: 2em;

                  border-radius: 50%;

                  background: var(--paper-blue-500);

                  color: white;

                  line-height: 2em;

                  font-size: 0.9375em;

                  text-align: center;

              }

  

              .heading{

f748e9cf   Luigi Serra   new controllet an...
127
                  /*width: 12.5em;*/

73bcce88   luigser   COMPONENTS
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
              }

  

              .big {

                  display: inline-block;

                  position: relative;

                  float: left;

                  font-size: 1em;

                  padding: 0.5em 0.25em 0.5em;

                  color: var(--google-grey-500);

              }

  

              .medium {

                  font-size: 0.8125em;

                  padding-bottom: 0px;

                  display: inline-block;

f748e9cf   Luigi Serra   new controllet an...
143
                  /*width: 12.5em;*/

73bcce88   luigser   COMPONENTS
144
145
146
147
148
149
150
151
152
153
154
              }

  

              .unselectable {

                  -webkit-touch-callout: none;

                  -webkit-user-select: none;

                  -khtml-user-select: none;

                  -moz-user-select: none;

                  -ms-user-select: none;

                  user-select: none;

              }

  

f748e9cf   Luigi Serra   new controllet an...
155
156
157
158
159
160
161
162
163
164
165
166
              #delete{

                  position: relative;

                  top: 24px;

                  left: 200px;

                  width: 24px;

                  height: 24px;

                  z-index: 1;

                  --iron-icon-height: 18px;

                  --iron-icon-width: 18px;

                  --paper-fab-background:#cccccc;

              }

  

73bcce88   luigser   COMPONENTS
167
168
169
170
171
172
173
174
175
176
177
          </style>

  

          <template is="dom-if" if="{{isTarget}}">

              <div class="drag-content-target" draggable="false">

                  <div class="card-content">

                      <div class="heading">

                          <div class="avatar">{{number}}</div>

                          <div class="big">{{heading}}</div><br>

                      </div>

                      <div class="medium">{{description}}</div>

                  </div>

f748e9cf   Luigi Serra   new controllet an...
178
179
                  <paper-fab id="delete" mini icon="clear" on-click="_handleDeleteClick"></paper-fab>

                  <paper-material elevation="2" id="target_dragged_identifier" class='draggable-card-target dd-content-target unselectable'>{{label}}</paper-material>

73bcce88   luigser   COMPONENTS
180
181
182
183
              </div>

          </template>

  

          <template is="dom-if" if="{{!isTarget}}">

74249687   Luigi Serra   Cross browser con...
184
              <div id="source" class="drag-content-source" draggable="true" ondragstart="event.dataTransfer.setData('text/plain', 'This text may be dragged')" on-track="_handleTrack" on-drag="_handleOnDrag" on-dragstart="_handleStartDrag" on-dragenter="_handleEnterDrag">

f748e9cf   Luigi Serra   new controllet an...
185
                  <paper-material elevation="2" id="{{identifier}}" class='draggable-card-source unselectable'>{{label}}</paper-material>

73bcce88   luigser   COMPONENTS
186
187
188
189
190
191
192
193
194
195
196
              </div>

          </template>

  

      </template>

  

      <script>

  

          Polymer({

  

              is: 'draggable-element-controllet',

  

938d1928   Luigi Serra   Update documentat...
197
198
199
200
201
202
              /**

               * Fired when the user drags a suorce in to a target element.

               *

               * @event draggable-element-controllet_content-dragged

               */

  

73bcce88   luigser   COMPONENTS
203
204
205
              targets : null,

  

              properties: {

938d1928   Luigi Serra   Update documentat...
206
207
208
209
210
211
212
                  /**

                   * It's a boolean flag to give to the controllet the role of target.

                   *

                   * @attribute isTarget

                   * @type Boolean

                   * @default false

                   */

73bcce88   luigser   COMPONENTS
213
214
215
216
                  isTarget : {

                      type : Boolean,

                      value: false

                  },

938d1928   Luigi Serra   Update documentat...
217
218
219
220
221
222
223
                  /**

                   * It's a string value the represent the current number of target. It will be use in the label section.

                   *

                   * @attribute number

                   * @type Strig

                   * @default '0'

                   */

73bcce88   luigser   COMPONENTS
224
225
                  number: {

                      type: String,

035bbee3   Luigi Serra   Datalets and cont...
226
                      value : "1"

73bcce88   luigser   COMPONENTS
227
                  },

938d1928   Luigi Serra   Update documentat...
228
229
230
231
232
233
234
                  /**

                   * It's the name of the target field

                   *

                   * @attribute heading

                   * @type Strig

                   * @default 'Heading'

                   */

73bcce88   luigser   COMPONENTS
235
236
237
238
                  heading : {

                      type : String,

                      value : "Heading"

                  },

938d1928   Luigi Serra   Update documentat...
239
240
241
242
243
244
245
                  /**

                   * It's the description of the target field

                   *

                   * @attribute description

                   * @type Strig

                   * @default 'Description'

                   */

73bcce88   luigser   COMPONENTS
246
247
248
249
                  description: {

                      type: String,

                      value: "Description"

                  },

938d1928   Luigi Serra   Update documentat...
250
251
252
253
254
255
256
                  /**

                   * It's the value of the source field

                   *

                   * @attribute label

                   * @type Strig

                   * @default 'Label'

                   */

73bcce88   luigser   COMPONENTS
257
258
                  label : {

                      type : String,

24be6abb   Luigi Serra   selection control...
259
                      value : undefined

73bcce88   luigser   COMPONENTS
260
                  },

938d1928   Luigi Serra   Update documentat...
261
262
263
264
265
266
267
                  /**

                   * It's the identifier associated to the source field element

                   *

                   * @attribute identifier

                   * @type Strig

                   * @default ''

                   */

73bcce88   luigser   COMPONENTS
268
269
270
271
272
273
274
275
276
277
278
279
                  identifier : {

                      type : String,

                      value : ""

                  },

  

                  value : {

                      type : String,

                      value : ""

                  }

  

              },

  

74249687   Luigi Serra   Cross browser con...
280
281
282
              ready : function(){

              },

  

73bcce88   luigser   COMPONENTS
283
              _handleStartDrag : function(e){

f974e824   Luigi Serra   Bugs fix
284
285
                  /*var target = EventUtil.getCurrentTarget(e);

                  target.style.cursor = 'move';*/

74249687   Luigi Serra   Cross browser con...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
                  return true;

              },

  

              _handleEnterDrag : function(e){

                  /*var target = e.target;

                  if(target.draggable == false && (target.className.indexOf("dd-content-target") != -1)){

  

                      target.parentNode.parentNode.value = e.srcElement.id;

                      target.innerHTML = e.srcElement.innerText;

  

                      this.fire('draggable-element-controllet_content-dragged', {target: target, source: e.srcElement});

                  }

  

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

                      this.targets[i].children[0].children[1].className = "draggable-card dd-content-target unselectable style-scope draggable-element-controllet";

                  }*/

                  return false;

f974e824   Luigi Serra   Bugs fix
303
              },

938d1928   Luigi Serra   Update documentat...
304
305
306
307
308
309
310
              /**

               * Callback associated to event on-drag for the source element. When the user is dragging a source element all the target border will be emphasized.

               *

               * @method _handleOnDrag

               *

               * @param {Event} e

               */

f974e824   Luigi Serra   Bugs fix
311
              _handleOnDrag : function(e){

73bcce88   luigser   COMPONENTS
312
313
                  this.targets = document.querySelectorAll('draggable-element-controllet[is-target=true]');

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

f748e9cf   Luigi Serra   new controllet an...
314
                      this.targets[i].children[0].children[2].elevation = "5";

73bcce88   luigser   COMPONENTS
315
316
317
                  }

  

              },

938d1928   Luigi Serra   Update documentat...
318
319
320
321
322
323
324
325
              /**

               * Callback associated to event on-trak for the source element. When the user stops dragging a source element the relative target is recognized and an event will be

               * fired to broadcast to all listeners the information about the current dragging operation.

               *

               * @method _handleTrack

               *

               * @param {Event} e

               */

73bcce88   luigser   COMPONENTS
326
327
328
329
330
331
332
333
              _handleTrack : function(e) {

  

                  switch(e.detail.state) {

                      case 'start':

                          break;

                      case 'track':

                          break;

                      case 'end':

74249687   Luigi Serra   Cross browser con...
334
  

73bcce88   luigser   COMPONENTS
335
                          var target = e.detail.hover();

74249687   Luigi Serra   Cross browser con...
336
  

73bcce88   luigser   COMPONENTS
337
338
                          if(target.draggable == false && (target.className.indexOf("dd-content-target") != -1)){

  

74249687   Luigi Serra   Cross browser con...
339
340
                              target.parentNode.parentNode.value = e.target.id;

                              target.innerHTML = e.target.innerHTML;

73bcce88   luigser   COMPONENTS
341
  

74249687   Luigi Serra   Cross browser con...
342
                              this.fire('draggable-element-controllet_content-dragged', {target: target, source: e.target});

73bcce88   luigser   COMPONENTS
343
344
345
                          }

  

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

f748e9cf   Luigi Serra   new controllet an...
346
                              this.targets[i].children[0].children[2].elevation = "2";

73bcce88   luigser   COMPONENTS
347
348
349
350
                          }

  

                          break;

                  }

f748e9cf   Luigi Serra   new controllet an...
351
352
353
354
355
356
357
358
359
360
361
362
              },

              /**

               * Manage the delete operation of the content.

               *

               * @param e

               * @private

               */

              _handleDeleteClick: function(e){

                  this.value = "";

                  e.currentTarget.nextElementSibling.innerHTML = "";

  

                  this.fire('draggable-element-controllet_content-dragged', {target: e.target, source: e.target});

73bcce88   luigser   COMPONENTS
363
364
365
366
367
368
              }

          });

  

      </script>

  

  </dom-module>