-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.precanned-replies.php
202 lines (172 loc) · 6.93 KB
/
main.precanned-replies.php
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
// Copyright (C) 2010 Combodo SARL
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* Module precanned-replies
*
* @author Erwan Taloc <[email protected]>
* @author Romain Quetiez <[email protected]>
* @author Denis Flaven <[email protected]>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
/**
* Pre-defined replies for fast answer to helpdesk tickets
*
* @author Erwan Taloc <[email protected]>
* @author Romain Quetiez <[email protected]>
* @author Denis Flaven <[email protected]>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
// Declare a class that implements iBackgroundProcess (will be called by the cron)
// Extend the class AsyncTask to create a queue of asynchronous tasks (process by the cron)
// Declare a class that implements iApplicationUIExtension (to tune object display and edition form)
// Declare a class that implements iApplicationObjectExtension (to tune object read/write rules)
class PrecannedRepliesPlugIn implements iApplicationUIExtension, iApplicationObjectExtension
{
const XML_LEGACY_VERSION = '';
/**
* Compare static::XML_LEGACY_VERSION with ITOP_DESIGN_LATEST_VERSION and returns true if the later is <= to the former.
* If static::XML_LEGACY_VERSION, return false
*
* @return bool
*
* @since 1.2.0
*/
public static function UseLegacy(){
return false;
}
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false)
{
if (self::IsTargetObject($oObject) && !$oObject->IsNew())
{
$oPage->LinkScriptFromModule('precanned-replies/precanned-replies.js');
$sButtonLabel = Dict::S('UI:Button-AddReply');
$oPage->add_dict_entry('UI:Dlg-PickAReply');
$sButtonLTooltip = $sButtonLabel;
$sButtonLabel = Dict::S('UI:Button-AddReply:Short');
$sObjectClass = get_class($oObject);
$iObjectId = $oObject->GetKey();
// Iterate on the caselogs applicables to object class
$aAttCodes = self::GetLogAttCodes($oObject);
foreach($aAttCodes as $sAttCode) {
$oPage->add_ready_script(
<<<JS
$('[data-role=\"ibo-caselog-entry-form\"][data-attribute-code=\"$sAttCode\"] [data-role=\"ibo-caselog-entry-form--action-buttons--extra-actions\"]').append('<div id=\"precanned_replies_$sAttCode\" style=\"display:inline-block;\"><button type=\"button\" class=\"emry-button ibo-button ibo-is-regular ibo-is-neutral\" id=\"precanned_button_$sAttCode\" value=\"$sButtonLabel\" onClick=\"SelectPrecannedReply(\'$sObjectClass\', \'$iObjectId\', \'$sAttCode\')\" data-tooltip-content=\"$sButtonLTooltip\"><span class=\"ibo-button--icon fas fa-file-invoice\"></span><span class=\"ibo-button--label\">$sButtonLabel</span></button><span id=\"v_precanned_$sAttCode\"></span></div>');
CombodoTooltip.InitTooltipFromMarkup($('#precanned_button'), true);
JS
);
}
}
}
public function OnDisplayRelations($oObject, WebPage $oPage, $bEditMode = false)
{
}
public function OnFormSubmit($oObject, $sFormPrefix = '')
{
if (self::IsTargetObject($oObject))
{
}
}
public function OnFormCancel($sTempId)
{
}
public function EnumUsedAttributes($oObject)
{
return array();
}
public function GetIcon($oObject)
{
return '';
}
public function GetHilightClass($oObject)
{
// Possible return values are:
// HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
return HILIGHT_CLASS_NONE;
}
public function EnumAllowedActions(DBObjectSet $oSet)
{
// No action
return array();
}
public function OnIsModified($oObject)
{
return false;
}
public function OnCheckToWrite($oObject)
{
return array();
}
public function OnCheckToDelete($oObject)
{
return array();
}
public function OnDBUpdate($oObject, $oChange = null)
{
}
public function OnDBInsert($oObject, $oChange = null)
{
}
public function OnDBDelete($oObject, $oChange = null)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Plug-ins specific functions
//
///////////////////////////////////////////////////////////////////////////////////////////////////////
protected function IsTargetObject(DBObject $oObject) : bool
{
return (count(self::GetLogAttCodes($oObject) ) > 0);
}
// Get an array of applicable caselog AttCodes for the class of the object
// Merge the caselogs of the object class and its parent classes
// Return an empty array if no caselog is applicable
public static function GetLogAttCodes(DBObject $oObject) : array
{
$aParams = []; // merge the caselogs of the object class and its parent classes
$aCaselogs = []; // return an array of applicable caselog AttCodes
$aConfig = self::GetConfig();
$sObjClass = get_class($oObject);
foreach($aConfig as $sClass => $sClassParam) {
if (MetaModel::IsParentClass($sClass,$sObjClass)) {
$aClassParam = explode(',', $sClassParam);
$aClassParam = array_map('trim', $aClassParam);
$aParams = array_unique(array_merge($aParams, $aClassParam));
}
}
foreach($aParams as $i => $sAttCode) {
if (MetaModel::IsValidAttCode($sObjClass, $sAttCode) && (MetaModel::GetAttributeDef($sObjClass, $sAttCode) instanceof AttributeCaseLog)) {
$aCaselogs[] = $sAttCode;
}
}
return $aCaselogs;
}
// return an array of $sClassName => $sCaseLogs // comma separated AttCodes
public static function GetConfig() : array
{ // Get multi-classes param table
$aConfig = MetaModel::GetModuleSetting('precanned-replies', 'targets', array());
// Merge legacy params in multi-classes format
$sSingleClass = MetaModel::GetModuleSetting('precanned-replies', 'target_class', '');
if (($sSingleClass !== '') && (!array_key_exists($sSingleClass, $aConfig))) {
$aConfig[$sSingleClass]= MetaModel::GetModuleSetting('precanned-replies', 'target_caselog', '');
}
// No config available, set the default in the multi-classes format
if (empty($aConfig)) {
$aConfig['UserRequest'] = 'public_log';
}
return $aConfig;
}
}