mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-21 16:22:20 +02:00
Merge remote-tracking branch 'origin/support/2.7' into develop
# Conflicts: # application/cmdbabstract.class.inc.php # application/utils.inc.php # dictionaries/en.dictionary.itop.core.php # dictionaries/fr.dictionary.itop.core.php # setup/setuputils.class.inc.php
This commit is contained in:
@@ -33,6 +33,7 @@ $(function()
|
||||
category: 'redirect',
|
||||
url: null,
|
||||
modal: false,
|
||||
timeout_duration: 400,
|
||||
},
|
||||
cancel_rule: {
|
||||
category: 'close',
|
||||
@@ -56,7 +57,7 @@ $(function()
|
||||
this.options.submit_rule.url = this.options.submit_url;
|
||||
if((this.options.cancel_url !== null) && (this.options.cancel_url !== ''))
|
||||
this.options.cancel_rule.url = this.options.cancel_url;
|
||||
|
||||
|
||||
this._super();
|
||||
},
|
||||
|
||||
@@ -143,12 +144,14 @@ $(function()
|
||||
// Determine where we go in case validation is successful
|
||||
var sRuleType = me.options.submit_rule.category;
|
||||
var bRedirectInModal = me.options.submit_rule.modal;
|
||||
var iRedirectTimeout = me.options.submit_rule.timeout_duration;
|
||||
var sRedirectUrl = me.options.submit_rule.url;
|
||||
// - The validation might want us to be redirect elsewhere
|
||||
if(oValidation.valid)
|
||||
{
|
||||
// Checking if we have to redirect to another page
|
||||
// Typically this happens when applying a stimulus, we redirect to the transition form
|
||||
// This code let the ajax response override the initial parameters
|
||||
if(oValidation.redirection !== undefined)
|
||||
{
|
||||
var oRedirection = oValidation.redirection;
|
||||
@@ -160,6 +163,10 @@ $(function()
|
||||
{
|
||||
sRedirectUrl = oRedirection.url;
|
||||
}
|
||||
if(oRedirection.timeout_duration !== undefined)
|
||||
{
|
||||
iRedirectTimeout = oRedirection.timeout_duration;
|
||||
}
|
||||
sRuleType = 'redirect';
|
||||
}
|
||||
}
|
||||
@@ -241,7 +248,7 @@ $(function()
|
||||
// Checking if we have to redirect to another page
|
||||
if(sRuleType === 'redirect')
|
||||
{
|
||||
me._applyRedirectRule(sRedirectUrl, bRedirectInModal);
|
||||
me._applyRedirectRule(sRedirectUrl, bRedirectInModal, iRedirectTimeout);
|
||||
}
|
||||
// Close rule only needs to be applied to non modal forms (modal is always closed on submit)
|
||||
else if(sRuleType === 'close')
|
||||
@@ -360,10 +367,13 @@ $(function()
|
||||
{
|
||||
$('#page_overlay').fadeOut(200);
|
||||
},
|
||||
_applyRedirectRule: function(sRedirectUrl, bRedirectInModal)
|
||||
_applyRedirectRule: function(sRedirectUrl, bRedirectInModal, iRedirectTimeout)
|
||||
{
|
||||
var me = this;
|
||||
|
||||
//optional argument
|
||||
iRedirectTimeout = (typeof iRedirectTimeout !== 'undefined' && iRedirectTimeout != null ) ? iRedirectTimeout : 400;
|
||||
|
||||
// Always close current modal
|
||||
if(this.options.is_modal)
|
||||
{
|
||||
@@ -391,8 +401,8 @@ $(function()
|
||||
// Showing loader while redirecting, otherwise user tend to click somewhere in the page.
|
||||
// Note: We use a timeout because .always() is called right after here and will hide the loader
|
||||
setTimeout(function(){ me._disableFormBeforeLoading(); }, 50);
|
||||
// Redirecting after a few ms so the user can see what happend
|
||||
setTimeout(function() { location.href = sRedirectUrl; }, 400);
|
||||
// Redirecting after a few ms so the user can see what happened
|
||||
setTimeout(function() { location.href = sRedirectUrl; }, iRedirectTimeout);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -211,6 +211,7 @@ class UserProfileBrickController extends BrickController
|
||||
{
|
||||
$aFormData['validation']['redirection'] = array(
|
||||
'url' => $oUrlGenerator->generate('p_user_profile_brick'),
|
||||
'timeout_duration' => 1000, //since there are several ajax request, we use a longer timeout in hope that they will all be finished in time. A promise would have been more reliable, but since this change is made in a minor version, this approach is less error prone.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1061,6 +1061,28 @@ class ObjectFormManager extends FormManager
|
||||
$this->CancelAttachments();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function CheckTransaction($aData)
|
||||
{
|
||||
$isTransactionValid = \utils::IsTransactionValid($this->oForm->GetTransactionId(), false); //The transaction token is kept in order to preserve BC with ajax forms (the second call would fail if the token is deleted). (The GC will take care of cleaning the token for us later on)
|
||||
if (!$isTransactionValid) {
|
||||
if ($this->oObject->IsNew()) {
|
||||
$sError = Dict::S('UI:Error:ObjectAlreadyCreated');
|
||||
} else {
|
||||
$sError = Dict::S('UI:Error:ObjectAlreadyUpdated');
|
||||
}
|
||||
|
||||
$aData['messages']['error'] += [
|
||||
'_main' => [$sError]
|
||||
];
|
||||
$aData['valid'] = false;
|
||||
}
|
||||
|
||||
return $aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the form and returns an array with the validation status and the messages.
|
||||
* If the form is valid, creates/updates the object.
|
||||
@@ -1083,124 +1105,116 @@ class ObjectFormManager extends FormManager
|
||||
*/
|
||||
public function OnSubmit($aArgs = null)
|
||||
{
|
||||
$aData = array(
|
||||
'valid' => true,
|
||||
'messages' => array(
|
||||
'success' => array(),
|
||||
'warnings' => array(), // Not used as of today, just to show that the structure is ready for change like this.
|
||||
'error' => array(),
|
||||
),
|
||||
);
|
||||
$aData = parent::OnSubmit($aArgs);
|
||||
|
||||
if (! $aData['valid']) {
|
||||
return $aData;
|
||||
}
|
||||
|
||||
// Update object and form
|
||||
$this->OnUpdate($aArgs);
|
||||
|
||||
// Check if form valid
|
||||
if ($this->oForm->Validate())
|
||||
{
|
||||
// The try catch is essentially to start a MySQL transaction in order to ensure that all or none objects are persisted when creating an object with links
|
||||
try
|
||||
{
|
||||
$sObjectClass = get_class($this->oObject);
|
||||
|
||||
// Starting transaction
|
||||
CMDBSource::Query('START TRANSACTION');
|
||||
// Forcing allowed writing on the object if necessary. This is used in some particular cases.
|
||||
$bAllowWrite = ($sObjectClass === 'Person' && $this->oObject->GetKey() == UserRights::GetContactId());
|
||||
if ($bAllowWrite)
|
||||
{
|
||||
$this->oObject->AllowWrite(true);
|
||||
}
|
||||
|
||||
// Writing object to DB
|
||||
$bActivateTriggers = (!$this->oObject->IsNew() && $this->oObject->IsModified());
|
||||
$bWasModified = $this->oObject->IsModified();
|
||||
try
|
||||
{
|
||||
$this->oObject->DBWrite();
|
||||
}
|
||||
catch (CoreCannotSaveObjectException $e)
|
||||
{
|
||||
throw new Exception($e->getHtmlMessage());
|
||||
}
|
||||
// Finalizing images link to object, otherwise it will be cleaned by the GC
|
||||
InlineImage::FinalizeInlineImages($this->oObject);
|
||||
// Finalizing attachments link to object
|
||||
// TODO : This has to be refactored when the function from itop-attachments has been migrated into the core
|
||||
if (isset($aArgs['attachmentIds']))
|
||||
{
|
||||
$this->FinalizeAttachments($aArgs['attachmentIds']);
|
||||
}
|
||||
|
||||
// Ending transaction with a commit as everything was fine
|
||||
CMDBSource::Query('COMMIT');
|
||||
|
||||
// Checking if we have to apply a stimulus
|
||||
if (isset($aArgs['applyStimulus']))
|
||||
{
|
||||
$this->oObject->ApplyStimulus($aArgs['applyStimulus']['code']);
|
||||
}
|
||||
// Activating triggers only on update
|
||||
if ($bActivateTriggers)
|
||||
{
|
||||
$sTriggersQuery = $this->oContainer->getParameter('combodo.portal.instance.conf')['properties']['triggers_query'];
|
||||
if ($sTriggersQuery !== null)
|
||||
{
|
||||
$aParentClasses = MetaModel::EnumParentClasses($sObjectClass, ENUM_PARENT_CLASSES_ALL);
|
||||
$oTriggerSet = new DBObjectSet(DBObjectSearch::FromOQL($sTriggersQuery), array(),
|
||||
array('parent_classes' => $aParentClasses));
|
||||
/** @var \Trigger $oTrigger */
|
||||
while ($oTrigger = $oTriggerSet->Fetch())
|
||||
{
|
||||
try
|
||||
{
|
||||
$oTrigger->DoActivate($this->oObject->ToArgs('this'));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
utils::EnrichRaisedException($oTrigger, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resetting caselog fields value, otherwise the value will stay in it after submit.
|
||||
$this->oForm->ResetCaseLogFields();
|
||||
|
||||
if ($bWasModified)
|
||||
{
|
||||
//=if (isNew) because $bActivateTriggers = (!$this->oObject->IsNew() && $this->oObject->IsModified())
|
||||
if(!$bActivateTriggers)
|
||||
{
|
||||
$aData['messages']['success'] += array( '_main' => array(Dict::Format('UI:Title:Object_Of_Class_Created', $this->oObject->GetName(),MetaModel::GetName(get_class($this->oObject)))));
|
||||
}
|
||||
else
|
||||
{
|
||||
$aData['messages']['success'] += array('_main' => array(Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($this->oObject)), $this->oObject->GetName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// End transaction with a rollback as something failed
|
||||
CMDBSource::Query('ROLLBACK');
|
||||
$aData['valid'] = false;
|
||||
$aData['messages']['error'] += array('_main' => array($e->getMessage()));
|
||||
IssueLog::Error(__METHOD__.' at line '.__LINE__.' : Rollback during submit ('.$e->getMessage().')');
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Removing transaction id
|
||||
utils::RemoveTransaction($this->oForm->GetTransactionId());
|
||||
}
|
||||
}
|
||||
else
|
||||
if (! $this->oForm->Validate())
|
||||
{
|
||||
// Handle errors
|
||||
$aData['valid'] = false;
|
||||
$aData['messages']['error'] += $this->oForm->GetErrorMessages();
|
||||
return $aData;
|
||||
}
|
||||
|
||||
// The try catch is essentially to start a MySQL transaction in order to ensure that all or none objects are persisted when creating an object with links
|
||||
try
|
||||
{
|
||||
$sObjectClass = get_class($this->oObject);
|
||||
|
||||
// Starting transaction
|
||||
CMDBSource::Query('START TRANSACTION');
|
||||
// Forcing allowed writing on the object if necessary. This is used in some particular cases.
|
||||
$bAllowWrite = ($sObjectClass === 'Person' && $this->oObject->GetKey() == UserRights::GetContactId());
|
||||
if ($bAllowWrite)
|
||||
{
|
||||
$this->oObject->AllowWrite(true);
|
||||
}
|
||||
|
||||
// Writing object to DB
|
||||
$bActivateTriggers = (!$this->oObject->IsNew() && $this->oObject->IsModified());
|
||||
$bWasModified = $this->oObject->IsModified();
|
||||
try
|
||||
{
|
||||
$this->oObject->DBWrite();
|
||||
}
|
||||
catch (CoreCannotSaveObjectException $e)
|
||||
{
|
||||
throw new Exception($e->getHtmlMessage());
|
||||
}
|
||||
// Finalizing images link to object, otherwise it will be cleaned by the GC
|
||||
InlineImage::FinalizeInlineImages($this->oObject);
|
||||
// Finalizing attachments link to object
|
||||
// TODO : This has to be refactored when the function from itop-attachments has been migrated into the core
|
||||
if (isset($aArgs['attachmentIds']))
|
||||
{
|
||||
$this->FinalizeAttachments($aArgs['attachmentIds']);
|
||||
}
|
||||
|
||||
// Ending transaction with a commit as everything was fine
|
||||
CMDBSource::Query('COMMIT');
|
||||
|
||||
// Checking if we have to apply a stimulus
|
||||
if (isset($aArgs['applyStimulus']))
|
||||
{
|
||||
$this->oObject->ApplyStimulus($aArgs['applyStimulus']['code']);
|
||||
}
|
||||
// Activating triggers only on update
|
||||
if ($bActivateTriggers)
|
||||
{
|
||||
$sTriggersQuery = $this->oContainer->getParameter('combodo.portal.instance.conf')['properties']['triggers_query'];
|
||||
if ($sTriggersQuery !== null)
|
||||
{
|
||||
$aParentClasses = MetaModel::EnumParentClasses($sObjectClass, ENUM_PARENT_CLASSES_ALL);
|
||||
$oTriggerSet = new DBObjectSet(DBObjectSearch::FromOQL($sTriggersQuery), array(),
|
||||
array('parent_classes' => $aParentClasses));
|
||||
/** @var \Trigger $oTrigger */
|
||||
while ($oTrigger = $oTriggerSet->Fetch())
|
||||
{
|
||||
try
|
||||
{
|
||||
$oTrigger->DoActivate($this->oObject->ToArgs('this'));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
utils::EnrichRaisedException($oTrigger, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resetting caselog fields value, otherwise the value will stay in it after submit.
|
||||
$this->oForm->ResetCaseLogFields();
|
||||
|
||||
if ($bWasModified)
|
||||
{
|
||||
//=if (isNew) because $bActivateTriggers = (!$this->oObject->IsNew() && $this->oObject->IsModified())
|
||||
if(!$bActivateTriggers)
|
||||
{
|
||||
$aData['messages']['success'] += array( '_main' => array(Dict::Format('UI:Title:Object_Of_Class_Created', $this->oObject->GetName(),MetaModel::GetName(get_class($this->oObject)))));
|
||||
}
|
||||
else
|
||||
{
|
||||
$aData['messages']['success'] += array('_main' => array(Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($this->oObject)), $this->oObject->GetName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// End transaction with a rollback as something failed
|
||||
CMDBSource::Query('ROLLBACK');
|
||||
$aData['valid'] = false;
|
||||
$aData['messages']['error'] += array('_main' => array($e->getMessage()));
|
||||
IssueLog::Error(__METHOD__.' at line '.__LINE__.' : Rollback during submit ('.$e->getMessage().')');
|
||||
}
|
||||
|
||||
|
||||
return $aData;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ class PasswordFormManager extends FormManager
|
||||
// Building the form
|
||||
$oForm = new Form('change_password');
|
||||
|
||||
$oForm->SetTransactionId(\utils::GetNewTransactionId());
|
||||
|
||||
// Adding hidden field with form type
|
||||
$oField = new HiddenField('form_type');
|
||||
$oField->SetCurrentValue('change_password');
|
||||
@@ -93,14 +95,11 @@ class PasswordFormManager extends FormManager
|
||||
*/
|
||||
public function OnSubmit($aArgs = null)
|
||||
{
|
||||
$aData = array(
|
||||
'valid' => true,
|
||||
'messages' => array(
|
||||
'success' => array(),
|
||||
'warnings' => array(), // Not used as of today, just to show that the structure is ready for change like this.
|
||||
'error' => array(),
|
||||
),
|
||||
);
|
||||
$aData = parent::OnSubmit($aArgs);
|
||||
|
||||
if (! $aData['valid']) {
|
||||
return $aData;
|
||||
}
|
||||
|
||||
// Update object and form
|
||||
$this->OnUpdate($aArgs);
|
||||
|
||||
@@ -49,6 +49,8 @@ class PreferencesFormManager extends FormManager
|
||||
// Building the form
|
||||
$oForm = new Form('preferences');
|
||||
|
||||
$oForm->SetTransactionId(\utils::GetNewTransactionId());
|
||||
|
||||
// Adding hidden field with form type
|
||||
$oField = new HiddenField('form_type');
|
||||
$oField->SetCurrentValue('preferences');
|
||||
@@ -97,14 +99,11 @@ class PreferencesFormManager extends FormManager
|
||||
*/
|
||||
public function OnSubmit($aArgs = null)
|
||||
{
|
||||
$aData = array(
|
||||
'valid' => true,
|
||||
'messages' => array(
|
||||
'success' => array(),
|
||||
'warnings' => array(), // Not used as of today, just to show that the structure is ready for change like this.
|
||||
'error' => array(),
|
||||
),
|
||||
);
|
||||
$aData = parent::OnSubmit($aArgs);
|
||||
|
||||
if (! $aData['valid']) {
|
||||
return $aData;
|
||||
}
|
||||
|
||||
// Update object and form
|
||||
$this->OnUpdate($aArgs);
|
||||
|
||||
@@ -227,16 +227,10 @@
|
||||
$('#user-profile-wrapper .form_field .help-block > p').remove();
|
||||
|
||||
// Submiting contact form through AJAX
|
||||
//if($('#{{ oContactForm.id }} .field_set').field_set('hasTouchedFields'))
|
||||
//{
|
||||
$('#{{ oContactForm.id }}').portal_form_handler('submit', oEvent);
|
||||
//}
|
||||
$('#{{ oContactForm.id }}').portal_form_handler('submit', oEvent);
|
||||
|
||||
// Submiting preferences form through AJAX
|
||||
//if($('#{{ oPreferencesForm.id }} .field_set').field_set('hasTouchedFields'))
|
||||
//{
|
||||
$('#{{ oPreferencesForm.id }}').portal_form_handler('submit', oEvent);
|
||||
//}
|
||||
$('#{{ oPreferencesForm.id }}').portal_form_handler('submit', oEvent);
|
||||
|
||||
{% if oPasswordForm is not null %}
|
||||
// Submiting password form through AJAX
|
||||
|
||||
Reference in New Issue
Block a user