Files
iTop/js/linkswidget.js
Romain Quetiez 2f26ebe54c Finalization of the user management by profile (UI to manage the accounts), and some unrelated changes:
- Using class labels in the UI
- Data model: you may specify a set of allowed values from a query (see caller_id in bizIncident class), still not 100% used in the UI but does not generate any error
- Data model: you may specify a password field (AttributePassword replacing AttributeString)
- Setup: calling UserRight::Setup() right after calling UserRight::CreateAdministrator()
- Setup: administrator account created with "my organization" and a dedicated contact
- Menus: optimized the load of std menus (queries written in OQL to get the benefit of the query cache)
- Menus: admin tools, seen only by people having the "admin" profile
- Object edition: fixed bug with the display of N-N links in the form

SVN:trunk[110]
2009-09-04 15:22:40 +00:00

113 lines
3.1 KiB
JavaScript

// 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+'&sextkeytoremote='+this.sExtKeyToRemote+'&myid='+this.id,
{'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
}
}