mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
#704: preserve the content of a "linkedset" when changing the initial state of the object being created !
SVN:trunk[2737]
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// JavaScript Document
|
||||
function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper)
|
||||
function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper, sExtKeyToRemote)
|
||||
{
|
||||
this.id = id;
|
||||
this.iInputId = iInputId;
|
||||
@@ -8,6 +8,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
|
||||
this.sSuffix = sSuffix;
|
||||
this.bDuplicates = bDuplicates;
|
||||
this.oWizardHelper = oWizHelper;
|
||||
this.sExtKeyToRemote = sExtKeyToRemote;
|
||||
var me = this;
|
||||
this.Init = function()
|
||||
{
|
||||
@@ -59,7 +60,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
|
||||
{
|
||||
$('#'+me.id+'_btnRemove').attr('disabled','disabled');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.AddObjects = function()
|
||||
{
|
||||
@@ -288,4 +289,44 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
|
||||
form_height = searchForm.outerHeight();
|
||||
results.height(height - form_height - 40); // Leave some space for the buttons
|
||||
};
|
||||
|
||||
this.GetUpdatedValue = function()
|
||||
{
|
||||
var sSelector = '#linkedset_'+me.id+' input[name^=attr_'+me.id+']';
|
||||
var aIndexes = [];
|
||||
var aValues = [];
|
||||
$(sSelector).each(function() {
|
||||
var re = /\[([^\[]+)\]\[(.+)\]/;
|
||||
var aMatches = [];
|
||||
if (aMatches = this.name.match(re))
|
||||
{
|
||||
var idx = aMatches[1];
|
||||
var index = aIndexes.indexOf(idx);
|
||||
if (index == -1)
|
||||
{
|
||||
aIndexes.push(idx);
|
||||
index = aIndexes.indexOf(idx);
|
||||
aValues[index] = {};
|
||||
}
|
||||
var value = $(this).val();
|
||||
if (aMatches[2] == "id")
|
||||
{
|
||||
var iId = parseInt(aMatches[1], 10);
|
||||
if (iId < 0)
|
||||
{
|
||||
aValues[index][me.sExtKeyToRemote] = -iId;
|
||||
}
|
||||
else
|
||||
{
|
||||
aValues[index]['id'] = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aValues[index][aMatches[2]] = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
return JSON.stringify(aValues);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -36,19 +36,18 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
this.SetFieldsMap = function (oFieldsMap)
|
||||
{
|
||||
this.m_oData.m_oFieldsMap = oFieldsMap;
|
||||
}
|
||||
};
|
||||
|
||||
this.SetFieldsCount = function (count)
|
||||
{
|
||||
this.m_oData.m_iFieldsCount = count;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
this.GetFieldId = function(sFieldName)
|
||||
{
|
||||
id = this.m_oData.m_oFieldsMap[sFieldName];
|
||||
return id;
|
||||
}
|
||||
};
|
||||
|
||||
this.RequestDefaultValue = function (sFieldName)
|
||||
{
|
||||
@@ -57,26 +56,28 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
{
|
||||
this.m_oData.m_aDefaultValueRequested.push(sFieldName);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.RequestAllowedValues = function (sFieldName)
|
||||
{
|
||||
this.m_oData.m_aAllowedValuesRequested.push(sFieldName);
|
||||
}
|
||||
};
|
||||
|
||||
this.SetCurrentValue = function (sFieldName, currentValue)
|
||||
{
|
||||
this.m_oData.m_oCurrentValues[sFieldName] = currentValue;
|
||||
}
|
||||
};
|
||||
|
||||
this.ToJSON = function ()
|
||||
{
|
||||
return JSON.stringify(this.m_oData);
|
||||
}
|
||||
};
|
||||
|
||||
this.FromJSON = function (sJSON)
|
||||
{
|
||||
//console.log('Parsing JSON:'+sJSON);
|
||||
this.m_oData = JSON.parse(sJSON);
|
||||
}
|
||||
};
|
||||
|
||||
this.ResetQuery = function ()
|
||||
{
|
||||
@@ -84,7 +85,7 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
this.m_oData.m_oDefaultValue = {};
|
||||
this.m_oData.m_aAllowedValuesRequested = [];
|
||||
this.m_oData.m_oAllowedValues = {};
|
||||
}
|
||||
};
|
||||
|
||||
this.UpdateFields = function ()
|
||||
{
|
||||
@@ -120,10 +121,10 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
// For each "refreshed" field, asynchronously trigger a change in case there are dependent fields to update
|
||||
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
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.UpdateWizard = function ()
|
||||
{
|
||||
@@ -134,16 +135,13 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
//console.log(sFieldCode);
|
||||
this.UpdateCurrentValue(sCleanFieldCode);
|
||||
}
|
||||
// Remove unnecessary stuff
|
||||
this.m_oData.m_oDefaultValue = {};
|
||||
this.m_oData.m_oAllowedValues = {};
|
||||
}
|
||||
};
|
||||
|
||||
this.UpdateWizardToJSON = function ()
|
||||
{
|
||||
this.UpdateWizard();
|
||||
return this.ToJSON()
|
||||
}
|
||||
return this.ToJSON();
|
||||
};
|
||||
|
||||
this.AjaxQueryServer = function ()
|
||||
{
|
||||
@@ -159,7 +157,7 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
//console.log(oWizardHelper);
|
||||
//$('#wizStep'+ G_iCurrentStep).unblock( {fadeOut: 0} );
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.Preview = function (divId)
|
||||
{
|
||||
@@ -170,10 +168,11 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
function(responseText, textStatus, XMLHttpRequest){
|
||||
$('#wizStep'+ G_iCurrentStep).unblock( {fadeOut: 0} );
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.UpdateCurrentValue = function (sFieldCode)
|
||||
{
|
||||
$('#'+this.m_oData.m_oFieldsMap[sFieldCode]).trigger('update_value'); // Give the widget a chance to update its value (if it is aware of this event)
|
||||
value = $('#'+this.m_oData.m_oFieldsMap[sFieldCode]).val();
|
||||
if (value == '')
|
||||
{
|
||||
@@ -181,7 +180,7 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
}
|
||||
this.m_oData.m_oCurrentValues[sFieldCode] = value;
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
this.UpdateDependentFields = function(aFieldNames)
|
||||
{
|
||||
@@ -197,7 +196,7 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
index++;
|
||||
}
|
||||
this.AjaxQueryServer();
|
||||
}
|
||||
};
|
||||
|
||||
this.ReloadObjectCreationForm = function(sFormId, sTargetState)
|
||||
{
|
||||
@@ -224,5 +223,5 @@ function WizardHelper(sClass, sFormPrefix, sState)
|
||||
$('#'+sFormId).unblock();
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user