forked from Combodo/email-reply
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail-reply.js
More file actions
183 lines (159 loc) · 5.91 KB
/
email-reply.js
File metadata and controls
183 lines (159 loc) · 5.91 KB
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
174
175
176
177
178
179
180
181
182
// (c) Combodo SARL 2012-2015
var aEmailReplyFiles = {};
function EmailReplyAddFile(sCaseLogAttCode, sContainerClass, sContainerId, sBlobAttCode, sFileName, bChecked)
{
var sFileDef = sContainerClass+'::'+sContainerId+'/'+sBlobAttCode;
if (bChecked)
{
var sId = 'emry_file_'+sCaseLogAttCode+'_'+sContainerClass+'_'+sContainerId+'_'+sBlobAttCode;
var sHiddenInput = '<input type="hidden" name="emry_files_'+sCaseLogAttCode+'[]" id="'+sId+'" value="'+sFileDef+'"/>';
$('#emry_form_extension').append(sHiddenInput);
}
if (!(sCaseLogAttCode in aEmailReplyFiles))
{
aEmailReplyFiles[sCaseLogAttCode] = {};
aEmailReplyFiles[sCaseLogAttCode+'_file_count'] = 0;
}
aEmailReplyFiles[sCaseLogAttCode][sFileDef] = { sCaseLogAttCode: sCaseLogAttCode, sContainerClass: sContainerClass, sContainerId: sContainerId, sBlobAttCode: sBlobAttCode, sFileName: sFileName, checked: bChecked };
if (bChecked)
{
aEmailReplyFiles[sCaseLogAttCode+'_file_count']++;
}
EmailReplyUpdateFileCount(sCaseLogAttCode);
}
function EmailReplyRemoveFile(sCaseLogAttCode, sContainerClass, sContainerId, sBlobAttCode)
{
var sFileDef = sContainerClass+'::'+sContainerId+'/'+sBlobAttCode;
var sId = 'emry_file_'+sCaseLogAttCode+'_'+sContainerClass+'_'+sContainerId+'_'+sBlobAttCode;
$('#'+sId).remove();
if (aEmailReplyFiles[sCaseLogAttCode][sFileDef].checked)
{
aEmailReplyFiles[sCaseLogAttCode+'_file_count']--;
}
delete aEmailReplyFiles[sCaseLogAttCode][sFileDef];
EmailReplyUpdateFileCount(sCaseLogAttCode);
}
function EmailReplyUpdateFileCount(sCaseLogAttCode)
{
var iCount = aEmailReplyFiles[sCaseLogAttCode+'_file_count'];
var sEmryEnabledCheckboxSelector = (IsEmailReplyLegacy === true) ? '#emry_enabled_' : '#emry_enabled_toggler_';
var bEmailDisabled = ($(sEmryEnabledCheckboxSelector+sCaseLogAttCode+':checked').length == 0);
var sText = '';
if (bEmailDisabled)
{
$('#emry_file_count_'+sCaseLogAttCode).html('0');
sText = Dict.S('UI-emry-noattachment');
}
else
{
$('#emry_file_count_'+sCaseLogAttCode).html(iCount);
var idx = 0;
var iNbAttachments = 0;
for(var index in aEmailReplyFiles[sCaseLogAttCode])
{
iNbAttachments++;
if (aEmailReplyFiles[sCaseLogAttCode][index].checked)
{
sText += aEmailReplyFiles[sCaseLogAttCode][index].sFileName;
idx++;
if (idx < iCount)
{
sText += ', ';
}
}
}
if (sText == '')
{
sText = Dict.S('UI-emry-noattachment');
}
}
if(IsEmailReplyLegacy === true){
$('#emry_file_list_'+sCaseLogAttCode).attr('title', sText);
}
else{
$('#emry_file_list_'+sCaseLogAttCode).attr('data-tooltip-content', sText);
CombodoTooltip.InitTooltipFromMarkup($('#emry_file_list_'+sCaseLogAttCode), true);
}
if ((iNbAttachments == 0) || bEmailDisabled)
{
$('#emry_select_files_btn_'+sCaseLogAttCode).prop('disabled', true);
}
else
{
$('#emry_select_files_btn_'+sCaseLogAttCode).prop('disabled', false);
}
}
function EmailReplyTooltipContent(sCaseLogAttCode)
{
var iCount = aEmailReplyFiles[sCaseLogAttCode+'_file_count'];
var sEmryEnabledCheckboxSelector = (IsEmailReplyLegacy === true) ? '#emry_enabled_' : '#emry_enabled_toggler_';
var bEmailDisabled = ($(sEmryEnabledCheckboxSelector+sCaseLogAttCode+':checked').length == 0);
if ((bEmailDisabled) || (iCount == 0))
{
sText = '<div style="padding:0;margin:0;font-size:12px;">'+Dict.S('UI-emry-noattachment')+'</div>';
}
else
{
var sText = '<div style="padding:0;margin:0;font-size:12px;">'+Dict.S('UI-emry-attachments-to-be-sent')+'</div>';
var idx = 0;
var iNbAttachments = 0;
for(var index in aEmailReplyFiles[sCaseLogAttCode])
{
if (aEmailReplyFiles[sCaseLogAttCode][index].checked)
{
sText += '<div style="padding:0;margin:0;font-size:12px;">• '+aEmailReplyFiles[sCaseLogAttCode][index].sFileName+'</div>';
idx++;
}
}
sText += '</ul>';
}
return sText;
}
function EmailReplySelectAttachments(sCaseLogAttCode)
{
var oDlg = $('<div id="emry-dlg"><div id="emry-dlg-content" style="max-height:25em;"><img src="../images/indicator.gif"</div></div>');
$('body').append(oDlg);
oDlg.dialog({
modal:true,
width: '70%',
minWidth: 'auto',
maxWidth: '90%',
height: 'auto',
maxHeight: $(window).height()*0.9,
title: Dict.S('UI-emry-select-attachments'),
buttons:[{text: Dict.S('UI:Button:Ok'), click: function() { EmailReplyOnSelectAttachments(sCaseLogAttCode); }}, {text: Dict.S('UI:Button:Cancel'), click: function() { $(this).dialog('close'); }}],
close: function() { $(this).remove(); $('#emry_file_list_'+sCaseLogAttCode).trigger('blur'); $('#emry_select_files_btn_'+sCaseLogAttCode).trigger('blur'); }
});
sUrl = GetAbsoluteUrlModulePage('email-reply', 'ajax.php');
$.post(sUrl, {operation: 'list_attachments', attachments: aEmailReplyFiles[sCaseLogAttCode] }, function(data) {
$('#emry-dlg-content').html(data);
oDlg.dialog('option', 'position', 'center');
});
}
function EmailReplyOnSelectAttachments(sCaseLogAttCode)
{
$('input[name^="emry_files_'+sCaseLogAttCode+'"]').remove();
$iCount = 0;
$('#emry-dlg-content :checkbox').each(function() {
var sFileref = $(this).attr('data-fileref');
var bChecked = $(this).prop('checked');
if (bChecked)
{
var sContainerClass = aEmailReplyFiles[sCaseLogAttCode][sFileref].sContainerClass;
var sContainerId = aEmailReplyFiles[sCaseLogAttCode][sFileref].sContainerId;
var sBlobAttCode = aEmailReplyFiles[sCaseLogAttCode][sFileref].sBlobAttCode;
aEmailReplyFiles[sCaseLogAttCode][sFileref].checked = true;
var sId = 'emry_file_'+sCaseLogAttCode+'_'+sContainerClass+'_'+sContainerId+'_'+sBlobAttCode;
var sHiddenInput = '<input type="hidden" name="emry_files_'+sCaseLogAttCode+'[]" id="'+sId+'" value="'+sFileref+'"/>';
$('#emry_form_extension').append(sHiddenInput);
$iCount++;
}
else
{
aEmailReplyFiles[sCaseLogAttCode][sFileref].checked = false;
}
});
aEmailReplyFiles[sCaseLogAttCode+'_file_count'] = $iCount;
EmailReplyUpdateFileCount(sCaseLogAttCode);
$('#emry-dlg').dialog('close');
}