N°6861 - Display warning message when creating/editing a mandatory blob in modal depending on edition mode and blob value

This commit is contained in:
Stephen Abello
2023-11-02 14:58:46 +01:00
parent b54022e2ad
commit 92cd1e3f19
21 changed files with 100 additions and 31 deletions

View File

@@ -25,6 +25,11 @@ use utils;
*/
class FormHelper
{
public const ENUM_MANDATORY_BLOB_MODE_CREATE = 'Create';
public const ENUM_MANDATORY_BLOB_MODE_MODIFY_EMPTY = 'Modify';
public const ENUM_MANDATORY_BLOB_MODE_MODIFY_FILLED = 'Modify:Filled';
/**
* DisableAttributeBlobInputs.
*
@@ -58,6 +63,26 @@ class FormHelper
}
}
/**
* Returns an attribute code if the object has a mandatory attribute blob, null otherwise
*
* @see N°6861 - Display warning when creating/editing a mandatory blob in modal
*
* @param \DBObject $oObject
*
* @return string|null
* @throws \CoreException
*/
public static function GetMandatoryAttributeBlobInputs(DBObject $oObject)
{
foreach (MetaModel::ListAttributeDefs(get_class($oObject)) as $sAttCode => $oAttDef) {
if ($oAttDef instanceof AttributeBlob && (!$oAttDef->IsNullAllowed() || ($oObject->GetFormAttributeFlags($sAttCode) & OPT_ATT_MANDATORY))) {
return $sAttCode;
}
}
return null;
}
/**
* Returns true if the object has a mandatory attribute blob
*
@@ -70,25 +95,29 @@ class FormHelper
*/
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;
return self::GetMandatoryAttributeBlobInputs($oObject) !== null;
}
/**
* 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
* @see self::ENUM_MANDATORY_BLOB_MODE_XXX
*
* @param string $sMode
*
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
*/
public static function GetAlertForMandatoryAttributeBlobInputsInModal(): Alert
public static function GetAlertForMandatoryAttributeBlobInputsInModal(string $sMode = self::ENUM_MANDATORY_BLOB_MODE_MODIFY_EMPTY): Alert
{
$oAlert = AlertUIBlockFactory::MakeForWarning('',Dict::S('UI:Object:Modal:MandatoryAttributeBlobInputs:Warning:Text'));
return $oAlert;
$sMessage = Dict::S('UI:Object:Modal:'.$sMode.':MandatoryAttributeBlobInputs:Warning:Text');
// If the mandatory attribute is already filled, there's no risk to make an object incomplete so we display an information level alert
if($sMode === self::ENUM_MANDATORY_BLOB_MODE_MODIFY_FILLED){
return AlertUIBlockFactory::MakeForInformation('', $sMessage);
}
return AlertUIBlockFactory::MakeForWarning('', $sMessage);
}
/**