From 4f336abeb85598c243377aa7c23abb2a26e33a07 Mon Sep 17 00:00:00 2001 From: Stephen Abello Date: Mon, 23 Oct 2023 15:22:48 +0200 Subject: [PATCH] =?UTF-8?q?=20N=C2=B06861=20-=20Display=20warning=20messag?= =?UTF-8?q?e=20when=20creating/editing=20a=20mandatory=20blob=20in=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/ui.extkeywidget.class.inc.php | 4 +++ .../ui.linksdirectwidget.class.inc.php | 4 +++ .../object/cs.dictionary.itop.object.php | 1 + .../object/da.dictionary.itop.object.php | 1 + .../object/de.dictionary.itop.object.php | 1 + .../object/en.dictionary.itop.object.php | 1 + .../object/es_cr.dictionary.itop.object.php | 1 + .../object/fr.dictionary.itop.object.php | 1 + .../object/hu.dictionary.itop.object.php | 1 + .../object/it.dictionary.itop.object.php | 1 + .../object/ja.dictionary.itop.object.php | 1 + .../object/nl.dictionary.itop.object.php | 1 + .../object/pl.dictionary.itop.object.php | 1 + .../object/pt_br.dictionary.itop.object.php | 1 + .../object/ru.dictionary.itop.object.php | 1 + .../object/sk.dictionary.itop.object.php | 1 + .../object/tr.dictionary.itop.object.php | 1 + .../object/zh_cn.dictionary.itop.object.php | 1 + sources/Application/Helper/FormHelper.php | 35 +++++++++++++++++++ .../Base/Layout/ObjectController.php | 7 ++++ .../Controller/Links/LinkSetController.php | 4 +++ 21 files changed, 70 insertions(+) diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php index cd0f01e83..84dd69a4b 100644 --- a/application/ui.extkeywidget.class.inc.php +++ b/application/ui.extkeywidget.class.inc.php @@ -975,6 +975,10 @@ HTML // Remove blob edition from creation form @see N°5863 to allow blob edition in modal context FormHelper::DisableAttributeBlobInputs($this->sTargetClass, $aFormExtraParams); + if(FormHelper::HasMandatoryAttributeBlobInputs($oNewObj)){ + $oPage->AddUiBlock(FormHelper::GetAlertForMandatoryAttributeBlobInputsInModal()); + } + cmdbAbstractObject::DisplayCreationForm($oPage, $this->sTargetClass, $oNewObj, array(), $aFormExtraParams); $oPage->add(<< diff --git a/application/ui.linksdirectwidget.class.inc.php b/application/ui.linksdirectwidget.class.inc.php index 6488bffa8..a3ed0a4d8 100644 --- a/application/ui.linksdirectwidget.class.inc.php +++ b/application/ui.linksdirectwidget.class.inc.php @@ -143,6 +143,10 @@ JS // Remove blob edition from creation form @see N°5863 to allow blob edition in modal context FormHelper::DisableAttributeBlobInputs($sRealClass, $aFormExtraParams); + + if(FormHelper::HasMandatoryAttributeBlobInputs($oObj)){ + $oPage->AddUiBlock(FormHelper::GetAlertForMandatoryAttributeBlobInputsInModal()); + } cmdbAbstractObject::DisplayCreationForm($oPage, $sRealClass, $oObj, array(), $aFormExtraParams); } diff --git a/dictionaries/ui/application/object/cs.dictionary.itop.object.php b/dictionaries/ui/application/object/cs.dictionary.itop.object.php index 011fc573a..282b2ceb9 100644 --- a/dictionaries/ui/application/object/cs.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/cs.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('CS CZ', 'Czech', 'Čeština', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/da.dictionary.itop.object.php b/dictionaries/ui/application/object/da.dictionary.itop.object.php index 40dfeb55f..959419313 100644 --- a/dictionaries/ui/application/object/da.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/da.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('DA DA', 'Danish', 'Dansk', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/de.dictionary.itop.object.php b/dictionaries/ui/application/object/de.dictionary.itop.object.php index 68dd8b494..a95f8c016 100644 --- a/dictionaries/ui/application/object/de.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/de.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('DE DE', 'German', 'Deutsch', array( 'UI:Object:Modal:Title' => 'Ein Objekt erstellen', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/en.dictionary.itop.object.php b/dictionaries/ui/application/object/en.dictionary.itop.object.php index ed9358bf3..7cf687207 100644 --- a/dictionaries/ui/application/object/en.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/en.dictionary.itop.object.php @@ -19,4 +19,5 @@ Dict::Add('EN US', 'English', 'English', array( 'UI:Object:Modal:Title' => 'Create an object', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/es_cr.dictionary.itop.object.php b/dictionaries/ui/application/object/es_cr.dictionary.itop.object.php index 5a8e751bd..5ad65e4c8 100644 --- a/dictionaries/ui/application/object/es_cr.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/es_cr.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('ES CR', 'Spanish', 'Español, Castellano', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/fr.dictionary.itop.object.php b/dictionaries/ui/application/object/fr.dictionary.itop.object.php index da15236ab..792babcc9 100644 --- a/dictionaries/ui/application/object/fr.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/fr.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('FR FR', 'French', 'Français', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'Ce formulaire contient un attribut fichier obligatoire qui n\'est pas supporté en mode pop-up. La création/modification de cet objet risque d\'être incomplète et pourra être complété dans un formulaire en pleine page.', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/hu.dictionary.itop.object.php b/dictionaries/ui/application/object/hu.dictionary.itop.object.php index 2ead4a47b..a560ec76b 100644 --- a/dictionaries/ui/application/object/hu.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/hu.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('HU HU', 'Hungarian', 'Magyar', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/it.dictionary.itop.object.php b/dictionaries/ui/application/object/it.dictionary.itop.object.php index ad91e6f0a..ab9669d04 100644 --- a/dictionaries/ui/application/object/it.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/it.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('IT IT', 'Italian', 'Italiano', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/ja.dictionary.itop.object.php b/dictionaries/ui/application/object/ja.dictionary.itop.object.php index d82f655a7..cf384f357 100644 --- a/dictionaries/ui/application/object/ja.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/ja.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('JA JP', 'Japanese', '日本語', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/nl.dictionary.itop.object.php b/dictionaries/ui/application/object/nl.dictionary.itop.object.php index eb271666f..69f069982 100644 --- a/dictionaries/ui/application/object/nl.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/nl.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('NL NL', 'Dutch', 'Nederlands', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/pl.dictionary.itop.object.php b/dictionaries/ui/application/object/pl.dictionary.itop.object.php index b7fd4c436..80e8c71a1 100644 --- a/dictionaries/ui/application/object/pl.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/pl.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('PL PL', 'Polish', 'Polski', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/pt_br.dictionary.itop.object.php b/dictionaries/ui/application/object/pt_br.dictionary.itop.object.php index a043d6678..8bb1a9327 100644 --- a/dictionaries/ui/application/object/pt_br.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/pt_br.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('PT BR', 'Brazilian', 'Brazilian', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/ru.dictionary.itop.object.php b/dictionaries/ui/application/object/ru.dictionary.itop.object.php index 23e558c51..68ef89486 100644 --- a/dictionaries/ui/application/object/ru.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/ru.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('RU RU', 'Russian', 'Русский', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/sk.dictionary.itop.object.php b/dictionaries/ui/application/object/sk.dictionary.itop.object.php index 819aeef34..86588dbdb 100644 --- a/dictionaries/ui/application/object/sk.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/sk.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('SK SK', 'Slovak', 'Slovenčina', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/tr.dictionary.itop.object.php b/dictionaries/ui/application/object/tr.dictionary.itop.object.php index ca4108aba..8c54de0a3 100644 --- a/dictionaries/ui/application/object/tr.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/tr.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('TR TR', 'Turkish', 'Türkçe', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/dictionaries/ui/application/object/zh_cn.dictionary.itop.object.php b/dictionaries/ui/application/object/zh_cn.dictionary.itop.object.php index 90f847766..49d3d2038 100644 --- a/dictionaries/ui/application/object/zh_cn.dictionary.itop.object.php +++ b/dictionaries/ui/application/object/zh_cn.dictionary.itop.object.php @@ -18,4 +18,5 @@ */ Dict::Add('ZH CN', 'Chinese', '简体中文', array( 'UI:Object:Modal:Title' => 'Create an object~~', + 'UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text' => 'This form contains a mandatory file attribute which is not supported in modal mode. The creation/modification of this object may be incomplete and may be completed in a full-page form.~~', )); \ No newline at end of file diff --git a/sources/Application/Helper/FormHelper.php b/sources/Application/Helper/FormHelper.php index 43b78393a..8d775f6b5 100644 --- a/sources/Application/Helper/FormHelper.php +++ b/sources/Application/Helper/FormHelper.php @@ -7,6 +7,8 @@ namespace Combodo\iTop\Application\Helper; use AttributeBlob; +use Combodo\iTop\Application\UI\Base\Component\Alert\Alert; +use Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory; use DBObject; use Dict; use MetaModel; @@ -56,6 +58,39 @@ class FormHelper } } + /** + * Returns true if the object has a mandatory attribute blob + * + * @see N°6861 - Display warning when creating/editing a mandatory blob in modal + * + * @param \DBObject $oObject + * + * @return bool + * @throws \CoreException + */ + public static function HasMandatoryAttributeBlobInputs(DBObject $oObject): bool + { + foreach (MetaModel::ListAttributeDefs(get_class($oObject)) as $sAttCode => $oAttDef) { + if ($oAttDef instanceof AttributeBlob && (!$oAttDef->IsNullAllowed() || ($oObject->GetFormAttributeFlags($sAttCode) & OPT_ATT_MANDATORY))) { + return true; + } + } + return false; + } + + /** + * Returns an Alert explaining what will happen when a mandatory attribute blob is displayed in a form + * + * @see N°6861 - Display warning when creating/editing a mandatory blob in modal + * + * @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert + */ + public static function GetAlertForMandatoryAttributeBlobInputsInModal(): Alert + { + $oAlert = AlertUIBlockFactory::MakeForWarning('',Dict::S('UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text')); + return $oAlert; + } + /** * Update flags to be sent to form with url parameters * For now only supports "readonly" param diff --git a/sources/Controller/Base/Layout/ObjectController.php b/sources/Controller/Base/Layout/ObjectController.php index 1725be8dc..7ead393ce 100644 --- a/sources/Controller/Base/Layout/ObjectController.php +++ b/sources/Controller/Base/Layout/ObjectController.php @@ -170,6 +170,10 @@ JS; // Remove blob edition from creation form @see N°5863 to allow blob edition in modal context FormHelper::DisableAttributeBlobInputs($sRealClass, $aFormExtraParams); + if(FormHelper::HasMandatoryAttributeBlobInputs($oObjToClone)){ + $oPage->AddUiBlock(FormHelper::GetAlertForMandatoryAttributeBlobInputsInModal()); + } + $aFormExtraParams['js_handlers']['cancel_button_on_click'] = <<AddUiBlock(FormHelper::GetAlertForMandatoryAttributeBlobInputsInModal()); + } } else { $oPage = new iTopWebPage('', $bPrintable); $oPage->DisableBreadCrumb(); diff --git a/sources/Controller/Links/LinkSetController.php b/sources/Controller/Links/LinkSetController.php index 57cbc740e..3b8836bfd 100644 --- a/sources/Controller/Links/LinkSetController.php +++ b/sources/Controller/Links/LinkSetController.php @@ -228,6 +228,10 @@ JS // Remove blob edition from creation form @see N°5863 to allow blob edition in modal context FormHelper::DisableAttributeBlobInputs($sRealClass, $aExtraParams); + + if(FormHelper::HasMandatoryAttributeBlobInputs($oObj)){ + $oPage->AddUiBlock(FormHelper::GetAlertForMandatoryAttributeBlobInputsInModal()); + } cmdbAbstractObject::DisplayCreationForm($oPage, $sRealClass, $oObj, array(), $aExtraParams); }