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
|
'use strict';
define(
[
'flight/lib/component'
],
function(defineComponent) {
return defineComponent(composeBox);
function composeBox() {
this.defaultAttrs({
newMailType: 'newMail',
forwardMailType: 'forward',
replyMailType: 'reply',
hintClass: 'hint',
selectedFolders: [],
selectedMailItems: [],
//selectors
composeControl: '.compose',
newControlSelector: '#new_mail',
cancelSelector: '#cancel_composed',
sendSelector: '#send_composed',
toSelector: '#compose_to',
subjectSelector: '#compose_subject',
messageSelector: '#compose_message',
recipientSelector: '#recipient_select',
recipientHintSelector: '#recipient_hint',
selectedRecipientSelector: '#recipient_select :selected',
hintSelector: 'div.hint'
});
this.newMail = function() {
this.requestComposeBox(this.attr.newMailType);
};
this.forward = function() {
this.requestComposeBox(this.attr.forwardMailType, this.attr.selectedMailItems);
};
this.reply = function() {
this.requestComposeBox(this.attr.replyMailType, this.attr.selectedMailItems);
};
this.requestComposeBox = function(type, relatedMailId) {
this.trigger('uiComposeBoxRequested', {type: type, relatedMailId: relatedMailId});
};
this.launchComposeBox = function(ev, data) {
var focusSelector = (data.type == this.attr.replyMailType) ? 'messageSelector' : 'toSelector';
this.$node.html(data.markup).show();
this.select(focusSelector).focus();
};
this.cancel = function() {
this.$node.html('').hide();
};
this.requestSend = function() {
var data = {
to_id: this.select('selectedRecipientSelector').attr('id'),
subject: this.select('subjectSelector').text(),
message: this.select('messageSelector').text(),
currentFolder: this.attr.selectedFolders[0]
};
this.trigger('uiSendRequested', data);
this.$node.hide();
};
this.enableSend = function() {
this.select('recipientHintSelector').attr('disabled', 'disabled');
this.select('sendSelector').removeAttr('disabled');
};
this.removeHint = function(ev, data) {
$(ev.target).html('').removeClass(this.attr.hintClass);
};
this.updateMailItemSelections = function(ev, data) {
this.attr.selectedMailItems = data.selectedIds;
}
this.updateFolderSelections = function(ev, data) {
this.attr.selectedFolders = data.selectedIds;
}
this.after('initialize', function() {
this.on(document, 'dataComposeBoxServed', this.launchComposeBox);
this.on(document, 'uiForwardMail', this.forward);
this.on(document, 'uiReplyToMail', this.reply);
this.on(document, 'uiMailItemSelectionChanged', this.updateMailItemSelections);
this.on(document, 'uiFolderSelectionChanged', this.updateFolderSelections);
//the following bindings use delegation so that the event target is read at event time
this.on(document, "click", {
'cancelSelector': this.cancel,
'sendSelector': this.requestSend,
'newControlSelector': this.newMail
});
this.on('change', {
'recipientSelector': this.enableSend
});
this.on('keydown', {
'hintSelector': this.removeHint
});
});
}
}
);
|