mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 06:48:50 +02:00
Fix for Ticket #22 (impossible to create change or incident tickets)
SVN:code[68]
This commit is contained in:
112
trunk/js/linkswidget.js
Normal file
112
trunk/js/linkswidget.js
Normal file
@@ -0,0 +1,112 @@
|
||||
// JavaScript Document
|
||||
|
||||
function LinksWidget(id, sLinkedClass, sExtKeyToMe, sExtKeyToRemote, aAttributes)
|
||||
{
|
||||
this.id = id;
|
||||
this.sLinkedClass = sLinkedClass;
|
||||
this.sExtKeyToMe = sExtKeyToMe;
|
||||
this.sExtKeyToRemote = sExtKeyToRemote;
|
||||
this.aAttributes = aAttributes;
|
||||
this.aLinks = new Array();
|
||||
|
||||
this.Init = function()
|
||||
{
|
||||
sLinks = $('#'+this.id).val();
|
||||
if (sLinks.length > 0)
|
||||
{
|
||||
this.aLinks = JSON.parse(sLinks);
|
||||
}
|
||||
this.Refresh();
|
||||
}
|
||||
|
||||
this.Refresh = function ()
|
||||
{
|
||||
if (this.aLinks.length == 0)
|
||||
{
|
||||
$('#'+this.id+'_values').empty();
|
||||
}
|
||||
else
|
||||
{
|
||||
sLinks = JSON.stringify(this.aLinks);
|
||||
$('#'+this.id).val(sLinks);
|
||||
$('#'+this.id+'_values').load('ajax.render.php?operation=ui.linkswidget.linkedset&sclass='+this.sLinkedClass+'&sextkeytome='+this.sExtKeyToMe,
|
||||
{'sset' : sLinks});
|
||||
}
|
||||
}
|
||||
|
||||
this.OnOk = function()
|
||||
{
|
||||
this.aObjectBeingLinked = new Array();
|
||||
sSelected = 'selected_objects_'+this.id;
|
||||
oSelected = document.getElementById(sSelected);
|
||||
for(i=0; i<oSelected.length; i++)
|
||||
{
|
||||
this.aObjectBeingLinked[i] = oSelected.options[i].value;
|
||||
}
|
||||
this.aPreviousLinks = this.aLinks; // Save the list in case of cancellation
|
||||
this.aLinks = new Array(); // rebuild the list of links from scratch
|
||||
$('#LinkDlg_'+this.id).jqmShow();
|
||||
}
|
||||
|
||||
this.OnCancel = function()
|
||||
{
|
||||
// Restore the links to their previous value (just in case)
|
||||
this.aLinks = this.aPreviousLinks;
|
||||
}
|
||||
|
||||
this.OnLinkOk = function()
|
||||
{
|
||||
$('#LinkDlg_'+this.id).jqmHide();
|
||||
for(i=0; i<this.aObjectBeingLinked.length; i++)
|
||||
{
|
||||
oLink = {};
|
||||
oLink[this.sExtKeyToRemote] = this.aObjectBeingLinked[i];
|
||||
for(j=0; j<this.aAttributes.length; j++)
|
||||
{
|
||||
oLink[aAttributes[j]] = $('#'+this.id+'_'+j).val();
|
||||
}
|
||||
this.aLinks.push(oLink);
|
||||
}
|
||||
this.Refresh();
|
||||
}
|
||||
|
||||
this.OnLinkCancel = function()
|
||||
{
|
||||
// Restore the links to their previous value (just in case)
|
||||
this.aLinks = this.aPreviousLinks;
|
||||
}
|
||||
|
||||
this.RemoveLink = function(index)
|
||||
{
|
||||
this.aLinks.splice(index, 1); // Remove the element at position 'index'
|
||||
this.Refresh();
|
||||
}
|
||||
|
||||
this.AddObject = function()
|
||||
{
|
||||
linkedObjId = $('#id_ac_'+this.id).val();
|
||||
// Clears the selection
|
||||
$('#id_ac_'+this.id).val('');
|
||||
$('#ac_'+this.id).val('');
|
||||
// Add the object to the list
|
||||
this.aObjectBeingLinked = new Array();
|
||||
this.aObjectBeingLinked[0] = linkedObjId;
|
||||
// Add the object to the list of links
|
||||
this.aPreviousLinks = this.aLinks; // Save the list in case of cancellation
|
||||
$('#LinkDlg_'+this.id).jqmShow();
|
||||
}
|
||||
|
||||
this.ModifyLink = function(index)
|
||||
{
|
||||
this.aObjectBeingLinked = new Array();
|
||||
this.aObjectBeingLinked[0] = this.aLinks[index][this.sExtKeyToRemote];
|
||||
this.aPreviousLinks = this.aLinks; // Save the list in case of cancellation
|
||||
// Set the default values of the dialog to the current ones
|
||||
for(j=0; j<this.aAttributes.length; j++)
|
||||
{
|
||||
$('#'+this.id+'_'+j).val(aLinks[index][aAttributes[j]]);
|
||||
}
|
||||
this.aLinks.splice(index, 1); // Remove the element at position 'index'
|
||||
$('#LinkDlg_'+this.id).jqmShow(); // And add it again
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user