';
// find already used items
$request = $DB->request([
'FROM' => PluginFormcreatorTarget_Actor::getTable(),
@@ -2021,6 +2041,19 @@ protected function showActorSettingsForType($actorType, array $actors) {
echo '
';
}
+ foreach (($PLUGIN_HOOKS['formcreator_actors_type'] ?? []) as $plugin => $classes) {
+ foreach ($classes as $plugin_target) {
+ if (!is_a($plugin_target, PluginFormcreatorPluginTargetInterface::class, true)) {
+ continue;
+ }
+
+ // Show custom form
+ echo '
';
+ echo $plugin_target::getForm($this->getForm());
+ echo '
';
echo __('Email followup');
Dropdown::showYesNo('use_notification', 1);
@@ -2035,11 +2068,11 @@ protected function showActorSettingsForType($actorType, array $actors) {
Html::closeForm();
- $img_user = '
';
- $img_group = '
';
- $img_supplier = '
';
- $img_mail = '
';
- $img_nomail = '
';
+ $img_user = static::getUserImage();
+ $img_group = static::getGroupImage();
+ $img_supplier = static::getSupplierImage();
+ $img_mail = static::getMailImage();
+ $img_nomail = static::getNoMailImage();
foreach ($actors[$actorRole] as $id => $values) {
echo '
';
@@ -2104,6 +2137,20 @@ protected function showActorSettingsForType($actorType, array $actors) {
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_AUTHORS_SUPERVISOR :
echo $img_user . ' ' . __('Form author\'s supervisor', 'formcreator') . '';
break;
+ default:
+ foreach (($PLUGIN_HOOKS['formcreator_actors_type'] ?? []) as $plugin => $classes) {
+ foreach ($classes as $plugin_target) {
+ if (!is_a($plugin_target, PluginFormcreatorPluginTargetInterface::class, true)) {
+ continue;
+ }
+
+ if ($values['actor_type'] == $plugin_target::getId()) {
+ echo $plugin_target::getDisplayedValue($values['actor_value']);
+ break 2;
+ }
+ }
+ }
+ break;
}
echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' ';
echo $this->getDeleteImage();
@@ -2417,4 +2464,24 @@ public static function findForFormAnswer(PluginFormcreatorFormAnswer $formAnswer
return $targets;
}
+
+ public static function getUserImage() {
+ return '';
+ }
+
+ public static function getGroupImage() {
+ return '';
+ }
+
+ public static function getSupplierImage() {
+ return '';
+ }
+
+ public static function getMailImage() {
+ return '';
+ }
+
+ public static function getNoMailImage() {
+ return '';
+ }
}
diff --git a/inc/plugintargetinterface.class.php b/inc/plugintargetinterface.class.php
new file mode 100644
index 000000000..0afbfdb00
--- /dev/null
+++ b/inc/plugintargetinterface.class.php
@@ -0,0 +1,47 @@
+.
+ * ---------------------------------------------------------------------
+ * @copyright Copyright © 2011 - 2021 Teclib'
+ * @license http://www.gnu.org/licenses/gpl.txt GPLv3+
+ * @link https://github.com/pluginsGLPI/formcreator/
+ * @link https://pluginsglpi.github.io/formcreator/
+ * @link http://plugins.glpi-project.org/#/plugin/formcreator
+ * ---------------------------------------------------------------------
+ */
+
+if (!defined('GLPI_ROOT')) {
+ die("Sorry. You can't access this file directly");
+}
+
+interface PluginFormcreatorPluginTargetInterface
+{
+ const ACTOR_TYPE_USER = 1;
+ const ACTOR_TYPE_GROUP = 2;
+
+ public static function getId(): int;
+ public static function getLabel(): string;
+ public static function getForm(PluginFormcreatorForm $form): string;
+ public static function getDisplayedValue($value): string;
+ public static function getActorType(): int;
+ public static function getActorId(PluginFormcreatorFormAnswer $formanswer, int $value): int;
+}
diff --git a/inc/target_actor.class.php b/inc/target_actor.class.php
index d0f66931d..021030bdf 100644
--- a/inc/target_actor.class.php
+++ b/inc/target_actor.class.php
@@ -62,7 +62,9 @@ class PluginFormcreatorTarget_Actor extends CommonDBChild implements PluginFormc
const ACTOR_ROLE_SUPPLIER = 4;
static function getEnumActorType() {
- return [
+ global $PLUGIN_HOOKS;
+
+ $types = [
self::ACTOR_TYPE_AUTHOR => __('Form author', 'formcreator'),
self::ACTOR_TYPE_VALIDATOR => __('Form validator', 'formcreator'),
self::ACTOR_TYPE_PERSON => __('Specific person', 'formcreator'),
@@ -76,6 +78,20 @@ static function getEnumActorType() {
self::ACTOR_TYPE_QUESTION_ACTORS => __('Actors from the question', 'formcreator'),
self::ACTOR_TYPE_AUTHORS_SUPERVISOR => __('Form author\'s supervisor', 'formcreator'),
];
+
+ // Add extra plugin types
+ foreach (($PLUGIN_HOOKS['formcreator_actors_type'] ?? []) as $plugin => $classes) {
+ foreach ($classes as $plugin_target) {
+ if (!is_a($plugin_target, PluginFormcreatorPluginTargetInterface::class, true)) {
+ continue;
+ }
+
+ $types[$plugin_target::getId()] = $plugin_target::getLabel();
+ }
+ }
+
+ asort($types);
+ return $types;
}
static function getEnumRole() {
diff --git a/js/scripts.js b/js/scripts.js
index 272ca3e74..91584137a 100644
--- a/js/scripts.js
+++ b/js/scripts.js
@@ -1222,28 +1222,8 @@ var plugin_formcreator = new function() {
}
this.changeActor = function(type, value) {
- $('#block_' + type + '_user').hide();
- $('#block_' + type + '_question_user').hide();
- $('#block_' + type + '_group').hide();
- $('#block_' + type + '_question_group').hide();
- $('#block_' + type + '_group_from_object').hide();
- $('#block_' + type + '_tech_group_from_object').hide();
- $('#block_' + type + '_question_actors').hide();
- $('#block_' + type + '_supplier').hide();
- $('#block_' + type + '_question_supplier').hide();
-
- // The numbers match PluginFormcreatorTarget_Actor::ACTOR_TYPE_* constants
- switch (value) {
- case '3' : $('#block_' + type + '_user').show(); break;
- case '4' : $('#block_' + type + '_question_user').show(); break;
- case '5' : $('#block_' + type + '_group').show(); break;
- case '6' : $('#block_' + type + '_question_group').show(); break;
- case '9' : $('#block_' + type + '_question_actors').show(); break;
- case '7' : $('#block_' + type + '_supplier').show(); break;
- case '8' : $('#block_' + type + '_question_supplier').show(); break;
- case '10': $('#block_' + type + '_group_from_object').show(); break;
- case '11': $('#block_' + type + '_tech_group_from_object').show(); break;
- }
+ $('div[data-actor-type^=' + type + ']').hide();
+ $('div[data-actor-type=' + type + '_' + value + ']').show();
}
this.updateWizardFormsView = function (item) {
@@ -1295,31 +1275,6 @@ var plugin_formcreator = new function() {
);
}
- this.changeActor = function(type, value) {
- $('#block_' + type + '_user').hide();
- $('#block_' + type + '_question_user').hide();
- $('#block_' + type + '_group').hide();
- $('#block_' + type + '_question_group').hide();
- $('#block_' + type + '_group_from_object').hide();
- $('#block_' + type + '_tech_group_from_object').hide();
- $('#block_' + type + '_question_actors').hide();
- $('#block_' + type + '_supplier').hide();
- $('#block_' + type + '_question_supplier').hide();
-
- // The numbers match PluginFormcreatorTarget_Actor::ACTOR_TYPE_* constants
- switch (value) {
- case '3' : $('#block_' + type + '_user').show(); break;
- case '4' : $('#block_' + type + '_question_user').show(); break;
- case '5' : $('#block_' + type + '_group').show(); break;
- case '6' : $('#block_' + type + '_question_group').show(); break;
- case '9' : $('#block_' + type + '_question_actors').show(); break;
- case '7' : $('#block_' + type + '_supplier').show(); break;
- case '8' : $('#block_' + type + '_question_supplier').show(); break;
- case '10': $('#block_' + type + '_group_from_object').show(); break;
- case '11': $('#block_' + type + '_tech_group_from_object').show(); break;
- }
- }
-
this.deleteActor = function (item) {
var item = item.closest('div[data-itemtype="PluginFormcreatorTarget_Actor"][data-id]');
var id = item.getAttribute('data-id');