summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/app/component_ui/move_to_selector.js
blob: e077e6aff38b352f98ccecc089139013f3aec633 (plain)
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
'use strict';

define(

  [
    'flight/lib/component',
    './with_select'
  ],

  function(defineComponent, withSelect) {

    return defineComponent(moveToSelector, withSelect);

    function moveToSelector() {

      this.defaultAttrs({
        selectionChangedEvent: 'uiMoveToSelectionChanged',
        selectedMailItems: [],
        selectedFolders: [],
        //selectors
        itemSelector: 'li.move-to-item',
        selectedItemSelector: 'li.move-to-item.selected'
      });

      this.requestSelectorWidget = function(ev, data) {
        this.trigger('uiAvailableFoldersRequested', {
          folder: this.attr.selectedFolders[0]
        })
      };

      this.launchSelector = function(ev, data) {
        var controlPosition = $(this.attr.moveActionSelector).offset();
        this.$node.html(data.markup).show().css({
          left: controlPosition.left,
          top: controlPosition.top + $(this.attr.moveActionSelector).outerHeight(),
          width: $(this.attr.moveActionSelector).outerWidth()
        });
        window.setTimeout(
          (function() {
            this.on(document, 'click', this.hideSelector)
          }).bind(this), 0);
      };

      this.hideSelector = function() {
        this.off(document, 'click', this.hideSelector);
        this.$node.hide();
      }

      this.updateMailItemSelections = function(ev, data) {
        this.attr.selectedMailItems = data.selectedIds;
      }

      this.updateFolderSelections = function(ev, data) {
        this.attr.selectedFolders = data.selectedIds;
      }

      this.requestMoveTo = function(ev, data) {
        this.trigger('uiMoveItemsRequested', {
          itemIds: this.attr.selectedMailItems,
          fromFolder: this.attr.selectedFolders[0],
          toFolder: data.selectedIds[0]
        });
        this.$node.hide();
      };

      this.after('initialize', function() {
        //show selector widget
        this.on(document, 'uiMoveMail', this.requestSelectorWidget);
        this.on(document, 'dataMoveToItemsServed', this.launchSelector);
        //listen for other selections
        this.on(document, 'uiMailItemSelectionChanged', this.updateMailItemSelections);
        this.on(document, 'uiFolderSelectionChanged', this.updateFolderSelections);
        //move items
        this.on('uiMoveToSelectionChanged', this.requestMoveTo);

      });
    }
  }
);