-
Notifications
You must be signed in to change notification settings - Fork 2
/
precanned-replies.js
174 lines (156 loc) · 4.76 KB
/
precanned-replies.js
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
// (c) Combodo SARL 2011 - 2016
function GetWizardHelperJsonPrecannedReply() {
var aReturn = {};
if(typeof oWizardHelper != 'undefined') {
oWizardHelper.UpdateWizard();
aReturn = oWizardHelper.ToJSON();
}
return aReturn;
}
function SelectPrecannedReply(sObjectClass, iObjectKey, sLogAttCode)
{
if ($('#precanned_button_'+sLogAttCode).prop('disabled')) return; // Disabled, do nothing
if ($('#precanned_dlg').length == 0)
{
$('body').append('<div id="precanned_dlg"></div>');
}
$('#precanned_button_'+sLogAttCode).prop('disabled', true);
$('#v_precanned_'+sLogAttCode).html('<img src="../images/indicator.gif" />');
var $aJsonData = {'json' : GetWizardHelperJsonPrecannedReply()};
if(Object.keys($aJsonData['json']).length === 0) {
$aJsonData = {
'object_class': $('[data-role="ibo-object-details"]').attr('data-object-class'),
'object_id': $('[data-role="ibo-object-details"]').attr('data-object-id')
}
}
var theMap = $.extend($aJsonData, {
operation: 'select_precanned',
obj_class: sObjectClass,
obj_id: iObjectKey,
log_attcode: sLogAttCode,
});
// Run the query and get the result back directly in HTML
$.post( AddAppContext(GetAbsoluteUrlModulesRoot()+'precanned-replies/ajax.php'), theMap,
function(data)
{
var dlg = $('#precanned_dlg');
dlg.html(data);
dlg.dialog({
width: $(window).width()*0.8,
height: $(window).height()*0.8,
autoOpen: false,
modal: true,
title: Dict.S('UI:Dlg-PickAReply'),
close: function() {OnClosePrecannedReply(sLogAttCode);},
buttons: [
{
text: Dict.S('UI:Button:Cancel'),
class: "ibo-is-alternative ibo-is-neutral",
click: function() {
$(this).dialog('close');
}
},
{
text: Dict.S('UI:Button:Add'),
class: "ibo-is-regular ibo-is-primary",
id: "btn_ok_{{ oUIBlock.sLinkedSetId }}",
click: function() {
PrecannedDoSelect(sLogAttCode);
}
},
],}
);
var data_area = $('#dr_precanned_select');
//data_area.css('max-height', (0.5*$(document).height())+'px'); // Stay within the document's boundaries
//data_area.css('overflow', 'auto'); // Stay within the document's boundaries
dlg.dialog('open');
},
'html'
);
}
function OnClosePrecannedReply(sLogAttCode)
{
$('#precanned_button_'+sLogAttCode).prop('disabled', false);
$('#v_precanned_'+sLogAttCode).html('');
}
function PrecannedDoSelect(sLogAttCode)
{
var selected = $('#datatable_search_form_result_precanned_select input:checked');
if (selected.length > 0)
{
var aSelected = new Array();
var index = 0;
selected.each( function () { aSelected[index++] = this.value; });
var $aJsonData = {'json' : GetWizardHelperJsonPrecannedReply()};
if(Object.keys($aJsonData['json']).length === 0) {
$aJsonData = {
'object_class': $('[data-role="ibo-object-details"]').attr('data-object-class'),
'object_id': $('[data-role="ibo-object-details"]').attr('data-object-id')
}
}
var theMap = $.extend($aJsonData, {
operation: 'add_precanned',
selected: aSelected,
log_attcode: sLogAttCode
});
// Run the query and get the result back directly in HTML
$.post( AddAppContext(GetAbsoluteUrlModulesRoot()+'precanned-replies/ajax.php'), theMap,
function(aJson)
{
var sText = aJson[0].text;
var iPrecannedId = aJson[0].id;
var sInstanceCode = $('[data-role="ibo-caselog-entry-form"][data-attribute-code="'+sLogAttCode+'"] textarea').attr('id');
if (typeof CombodoCKEditorHandler !== 'undefined') {
CombodoCKEditorHandler.InsertHtmlInsideInstance('#' +sInstanceCode, sText);
}
else {
CKEDITOR.instances[sInstanceCode].insertHtml(sText);
}
var aFiles = aJson[0].files;
var index = 0;
while(index < aFiles.length)
{
$('#emry_event_bus_'+sLogAttCode).trigger('add_blob', [
aFiles[index]['container_class'],
aFiles[index]['container_id'],
aFiles[index]['blob_attcode'],
aFiles[index]['file_name']
])
index++;
}
$('#emry_enabled_'+sLogAttCode).prop('checked', true);
},
'json'
);
}
var dlg = $('#precanned_dlg');
dlg.dialog('close');
dlg.html('');
}
function PrecannedDoSearch(sLogAttCode)
{
var theMap = {};
// Gather the parameters from the search form
$('#fs_precanned_select :input').each( function() {
if (this.name != '')
{
var val = $(this).val(); // supports multiselect as well
if (val !== null)
{
theMap[this.name] = val;
}
}
});
theMap['operation'] = 'search_precanned';
theMap['log_attcode'] = sLogAttCode;
// Run the query and get the result back directly in HTML
$.post( AddAppContext(GetAbsoluteUrlModulesRoot()+'precanned-replies/ajax.php'), theMap,
function(data)
{
var res = $('#dr_precanned_select');
res.html(data);
},
'html'
);
return false; // Stay on page
}