diff --git a/ajax/form_duplicate_target.php b/ajax/form_duplicate_target.php new file mode 100644 index 000000000..964bb61ae --- /dev/null +++ b/ajax/form_duplicate_target.php @@ -0,0 +1,48 @@ +. + * --------------------------------------------------------------------- + * @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 + * --------------------------------------------------------------------- + */ + +include ('../../../inc/includes.php'); + +// Check if plugin is activated... +if (!(new Plugin())->isActivated('formcreator')) { + http_response_code(404); + die(); +} + +if (!isset($_REQUEST['itemtype']) || !isset($_REQUEST['items_id']) || !isset($_REQUEST['action'])) { + http_response_code(500); + die(); +} + +Session::checkRight('entity', UPDATE); +if (!PluginFormcreatorCommon::getForm()->duplicateTarget($_REQUEST)) { + http_response_code(500); +} \ No newline at end of file diff --git a/inc/abstractitiltarget.class.php b/inc/abstractitiltarget.class.php index 90bc24e07..050d34d2e 100644 --- a/inc/abstractitiltarget.class.php +++ b/inc/abstractitiltarget.class.php @@ -2493,4 +2493,17 @@ public static function getMailImage() { public static function getNoMailImage() { return ''; } + + public function getCloneRelations(): array { + return [ + PluginFormcreatorTarget_Actor::class, + PluginFormcreatorCondition::class, + ]; + } + + public function prepareInputForClone($input) { + $input = parent::prepareInputForClone($input); + $input['_skip_create_actors'] = true; + return $input; + } } diff --git a/inc/abstracttarget.class.php b/inc/abstracttarget.class.php index c7962ac33..8c9be59c3 100644 --- a/inc/abstracttarget.class.php +++ b/inc/abstracttarget.class.php @@ -31,7 +31,7 @@ */ use Glpi\Application\View\TemplateRenderer; -use Glpi\Toolbox\Sanitizer; +use \Glpi\Features\Clonable; if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); @@ -43,6 +43,7 @@ abstract class PluginFormcreatorAbstractTarget extends CommonDBChild implements PluginFormcreatorConditionnableInterface, PluginFormcreatorTranslatableInterface { + use Clonable; use PluginFormcreatorConditionnableTrait; use PluginFormcreatorExportableTrait; use PluginFormcreatorTranslatable; @@ -553,4 +554,9 @@ protected function showDestinationEntitySetings($rand) { echo ''; echo ''; } + + public function prepareInputForClone($input) { + unset($input['uuid']); + return $input; + } } diff --git a/inc/condition.class.php b/inc/condition.class.php index c11644228..e2b5db8ad 100644 --- a/inc/condition.class.php +++ b/inc/condition.class.php @@ -374,4 +374,9 @@ public function deleteObsoleteItems(CommonDBTM $container, array $exclude) : boo } return $this->deleteByCriteria($keepCriteria); } + + public function prepareInputForClone($input) { + unset($input['uuid']); + return $input; + } } diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 4197efb84..7a1ae5ed1 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -311,4 +311,6 @@ public function show(string $domain, bool $canEdit = true): string; * @return void */ public function setFormAnswer(PluginFormcreatorFormAnswer $form_answer): void; + + public function getRawValue(); } diff --git a/inc/form.class.php b/inc/form.class.php index c5132b639..7d0dd26e2 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -522,7 +522,17 @@ public function showTargets($ID, $options = []) { echo ''; echo ''; + echo ' '; + echo 'clone(); + return true; + } + + /** + * Delete a target for the form * * @param aray $input * @return boolean diff --git a/inc/target_actor.class.php b/inc/target_actor.class.php index 021030bdf..7f3866712 100644 --- a/inc/target_actor.class.php +++ b/inc/target_actor.class.php @@ -29,6 +29,7 @@ * --------------------------------------------------------------------- */ +use Glpi\Features\Clonable; use GlpiPlugin\Formcreator\Exception\ImportFailureException; use GlpiPlugin\Formcreator\Exception\ExportFailureException; @@ -38,6 +39,7 @@ class PluginFormcreatorTarget_Actor extends CommonDBChild implements PluginFormcreatorExportableInterface { + use Clonable; use PluginFormcreatorExportableTrait; static public $itemtype = 'itemtype'; @@ -311,4 +313,10 @@ public function deleteObsoleteItems(CommonDBTM $container, array $exclude) : boo } return $this->deleteByCriteria($keepCriteria); } + + public function prepareInputForClone($input) { + $input['actor_value_' . $input['actor_type']] = $input['actor_value']; + unset($input['uuid']); + return $input; + } } diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index e3c8b14ef..ab66212c0 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -34,6 +34,7 @@ use Glpi\Application\View\TemplateRenderer; use Glpi\Toolbox\Sanitizer; + if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } diff --git a/js/scripts.js b/js/scripts.js index 4abe046af..742732dd7 100644 --- a/js/scripts.js +++ b/js/scripts.js @@ -1442,7 +1442,24 @@ function plugin_formcreator_addTarget(items_id) { }); } -$(document).on('click', '.formcreator_delete_target', function() { +$(document).on('click', '.plugin_formcreator_duplicate_target', function() { + if(confirm(i18n.textdomain('formcreator').__('Are you sure you want to duplicate this target:', 'formcreator'))) { + $.post({ + url: formcreatorRootDoc + '/ajax/form_duplicate_target.php', + data: { + action: 'duplicate_target', + itemtype: $(this).data('itemtype'), + items_id: $(this).data('items-id'), + } + }).done(function () { + reloadTab(); + }).fail(function () { + displayAjaxMessageAfterRedirect(); + }); + } +}); + +$(document).on('click', '.plugin_formcreator_delete_target', function() { if(confirm(i18n.textdomain('formcreator').__('Are you sure you want to delete this target:', 'formcreator'))) { $.post({ url: formcreatorRootDoc + '/ajax/form_delete_target.php',