mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
Compare commits
1 Commits
3.1.0-2
...
support/3.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e793b02f8b |
@@ -347,6 +347,7 @@ class WizardHelper
|
|||||||
/**
|
/**
|
||||||
* @return string JS code to be executed for fields update
|
* @return string JS code to be executed for fields update
|
||||||
* @since 3.0.0 N°3198
|
* @since 3.0.0 N°3198
|
||||||
|
* @deprecated 3.0.3-2 3.0.4 3.1.1 3.2.0 Use {@see \WizardHelper::AddJsForUpdateFields()} instead
|
||||||
*/
|
*/
|
||||||
public function GetJsForUpdateFields()
|
public function GetJsForUpdateFields()
|
||||||
{
|
{
|
||||||
@@ -359,15 +360,39 @@ class WizardHelper
|
|||||||
JS;
|
JS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add necessary JS snippets (to the page) to be executed for fields update
|
||||||
|
*
|
||||||
|
* @param \WebPage $oPage
|
||||||
|
* @return void
|
||||||
|
* @since 3.0.3-2 3.0.4 3.1.1 3.2.0 N°6766
|
||||||
|
*/
|
||||||
|
public function AddJsForUpdateFields(WebPage $oPage)
|
||||||
|
{
|
||||||
|
$sWizardHelperJsVar = (!is_null($this->m_aData['m_sWizHelperJsVarName'])) ? utils::Sanitize($this->m_aData['m_sWizHelperJsVarName'], '', utils::ENUM_SANITIZATION_FILTER_PARAMETER) : 'oWizardHelper'.$this->GetFormPrefix();
|
||||||
|
$sWizardHelperJson = $this->ToJSON();
|
||||||
|
|
||||||
|
$oPage->add_script(<<<JS
|
||||||
|
{$sWizardHelperJsVar}.m_oData = {$sWizardHelperJson};
|
||||||
|
{$sWizardHelperJsVar}.UpdateFields();
|
||||||
|
JS
|
||||||
|
);
|
||||||
|
$oPage->add_ready_script(<<<JS
|
||||||
|
if ({$sWizardHelperJsVar}.m_oDependenciesUpdatedPromiseResolve !== null){
|
||||||
|
{$sWizardHelperJsVar}.m_oDependenciesUpdatedPromiseResolve();
|
||||||
|
}
|
||||||
|
JS
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static function ParseJsonSet($oMe, $sLinkClass, $sExtKeyToMe, $sJsonSet)
|
static function ParseJsonSet($oMe, $sLinkClass, $sExtKeyToMe, $sJsonSet)
|
||||||
{
|
{
|
||||||
$aSet = json_decode($sJsonSet, true); // true means hash array instead of object
|
$aSet = json_decode($sJsonSet, true); // true means hash array instead of object
|
||||||
$oSet = CMDBObjectSet::FromScratch($sLinkClass);
|
$oSet = CMDBObjectSet::FromScratch($sLinkClass);
|
||||||
foreach ($aSet as $aLinkObj)
|
foreach ($aSet as $aLinkObj) {
|
||||||
{
|
|
||||||
$oLink = MetaModel::NewObject($sLinkClass);
|
$oLink = MetaModel::NewObject($sLinkClass);
|
||||||
foreach ($aLinkObj as $sAttCode => $value)
|
foreach ($aLinkObj as $sAttCode => $value) {
|
||||||
{
|
|
||||||
$oAttDef = MetaModel::GetAttributeDef($sLinkClass, $sAttCode);
|
$oAttDef = MetaModel::GetAttributeDef($sLinkClass, $sAttCode);
|
||||||
if (($oAttDef->IsExternalKey()) && ($value != '') && ($value > 0))
|
if (($oAttDef->IsExternalKey()) && ($value != '') && ($value > 0))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,6 +72,11 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus) {
|
|||||||
'm_sWizHelperJsVarName': null // if set will use this name when server returns JS code in \WizardHelper::GetJsForUpdateFields
|
'm_sWizHelperJsVarName': null // if set will use this name when server returns JS code in \WizardHelper::GetJsForUpdateFields
|
||||||
};
|
};
|
||||||
this.m_oData.m_sClass = sClass;
|
this.m_oData.m_sClass = sClass;
|
||||||
|
/**
|
||||||
|
* Promise resolve callback when dependencies have been updated
|
||||||
|
* @since 3.0.3-2 3.0.4 3.1.1 3.2.0 N°6766
|
||||||
|
* */
|
||||||
|
this.m_oDependenciesUpdatedPromiseResolve = null;
|
||||||
|
|
||||||
// Setting optional transition data
|
// Setting optional transition data
|
||||||
if (sInitialState !== undefined)
|
if (sInitialState !== undefined)
|
||||||
@@ -138,6 +143,7 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.UpdateFields = function () {
|
this.UpdateFields = function () {
|
||||||
|
const me = this;
|
||||||
var aRefreshed = [];
|
var aRefreshed = [];
|
||||||
//console.log('** UpdateFields **');
|
//console.log('** UpdateFields **');
|
||||||
// Set the full HTML for the input field
|
// Set the full HTML for the input field
|
||||||
@@ -171,10 +177,17 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For each "refreshed" field, asynchronously trigger a change in case there are dependent fields to update
|
// For each "refreshed" field, asynchronously trigger a change in case there are dependent fields to update
|
||||||
for (i = 0; i < aRefreshed.length; i++)
|
for (i = 0; i < aRefreshed.length; i++) {
|
||||||
{
|
|
||||||
var sString = "$('#"+aRefreshed[i]+"').trigger('change').trigger('update');";
|
var sString = "$('#"+aRefreshed[i]+"').trigger('change').trigger('update');";
|
||||||
window.setTimeout(sString, 1); // Synchronous 'trigger' does nothing, call it asynchronously
|
const oPromise = new Promise(function (resolve) {
|
||||||
|
// Store the resolve callback so we can call it later from outside
|
||||||
|
me.m_oDependenciesUpdatedPromiseResolve = resolve;
|
||||||
|
});
|
||||||
|
oPromise.then(function () {
|
||||||
|
window.setTimeout(sString, 1); // Synchronous 'trigger' does nothing, call it asynchronously
|
||||||
|
// Resolve callback is reinitialized in case the redirection fails for any reason and we might need to retry
|
||||||
|
me.m_oDependenciesUpdatedPromiseResolve = null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if($('[data-field-status="blocked"]').length === 0) {
|
if($('[data-field-status="blocked"]').length === 0) {
|
||||||
$('.disabledDuringFieldLoading').prop("disabled", false).removeClass('disabledDuringFieldLoading');
|
$('.disabledDuringFieldLoading').prop("disabled", false).removeClass('disabledDuringFieldLoading');
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ try
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$oPage->add_script($oWizardHelper->GetJsForUpdateFields());
|
$oWizardHelper->AddJsForUpdateFields($oPage);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'obj_creation_form':
|
case 'obj_creation_form':
|
||||||
|
|||||||
Reference in New Issue
Block a user