🎨 📝 format & add comment

This commit is contained in:
Pierre Goiffon
2020-08-12 10:01:38 +02:00
parent 44e188fa2c
commit 7d7270296e
7 changed files with 474 additions and 488 deletions

View File

@@ -2332,7 +2332,7 @@ EOF
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/form_field.js');
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/subform_field.js');
$oPage->add_ready_script(
<<<EOF
<<<JS
$('#{$iId}_field_set').field_set($sFieldSetOptions);
$('#{$iId}_console_form').console_form_handler($sFormHandlerOptions);
@@ -2348,7 +2348,7 @@ EOF
$(this).val(JSON.stringify($('#{$iId}_field_set').triggerHandler('get_current_values')));
return ValidateCustomFields('$iId', sFormId); // Custom validation function
});
EOF
JS
);
break;
@@ -2479,8 +2479,7 @@ EOF
$oPage->add_ready_script("$('#$sFieldToValidateId').bind('".implode(' ',
$aEventsList)."', function(evt, sFormId) { return ValidateField('$sFieldToValidateId', '$sPattern', $bMandatory, sFormId, $sNullValue, $sOriginalValue) } );\n"); // Bind to a custom event: validate
}
$aDependencies = MetaModel::GetDependentAttributes($sClass,
$sAttCode); // List of attributes that depend on the current one
$aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one
if (count($aDependencies) > 0)
{
// Unbind first to avoid duplicate event handlers in case of reload of the whole (or part of the) form

View File

@@ -359,16 +359,17 @@ EOF
$bDoSearch = !utils::IsHighCardinality($this->m_sRemoteClass);
$sJSDoSearch = $bDoSearch ? 'true' : 'false';
$sWizHelper = 'oWizardHelper'.$sFormPrefix;
$oPage->add_ready_script(<<<EOF
$oPage->add_ready_script(<<<JS
oWidget{$this->m_iInputId} = new LinksWidget('{$this->m_sAttCode}{$this->m_sNameSuffix}', '{$this->m_sClass}', '{$this->m_sAttCode}', '{$this->m_iInputId}', '{$this->m_sNameSuffix}', $sDuplicates, $sWizHelper, '{$this->m_sExtKeyToRemote}', $sJSDoSearch);
oWidget{$this->m_iInputId}.Init();
EOF
JS
);
while ($oCurrentLink = $oValue->Fetch())
{
// We try to retrieve the remote object as usual
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote), false /* Must not be found */);
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote),
false /* Must not be found */);
// If successful, it means that we can edit its link
if ($oLinkedObj !== null)
{

View File

@@ -15,8 +15,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper, sAttCode, bSearchMode, bDoSearch)
{
function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper, sAttCode, bSearchMode, bDoSearch) {
this.id = id;
this.sOriginalTargetClass = sTargetClass;
this.sTargetClass = sTargetClass;
@@ -32,8 +31,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
this.bDoSearch = bDoSearch; // false if the search is not launched
var me = this;
this.Init = function()
{
this.Init = function () {
// make sure that the form is clean
$('#'+this.id+'_btnRemove').prop('disabled', true);
$('#'+this.id+'_linksToRemove').val('');
@@ -168,8 +166,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
});
};
this.StopPendingRequest = function()
{
this.StopPendingRequest = function () {
if (me.ajax_request)
{
me.ajax_request.abort();
@@ -177,9 +174,11 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
}
};
this.Search = function()
this.Search = function () {
if ($('#'+me.id).prop('disabled'))
{
if($('#'+me.id).prop('disabled')) return; // Disabled, do nothing
return;
} // Disabled, do nothing
var value = $('#'+me.id).val(); // Current value
// Query the server to get the form to search for target objects
@@ -191,7 +190,8 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
{
$('#label_'+me.id).addClass('ac_dlg_loading');
}
var theMap = { sAttCode: me.sAttCode,
var theMap = {
sAttCode: me.sAttCode,
iInputId: me.id,
sTitle: me.sTitle,
sAttCode: me.sAttCode,
@@ -217,8 +217,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
// Run the query and get the result back directly in HTML
me.ajax_request = $.post(AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
function(data)
{
function (data) {
$('#ac_dlg_'+me.id).html(data);
$('#ac_dlg_'+me.id).dialog('open');
me.UpdateSizes();
@@ -236,8 +235,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
);
};
this.UpdateSizes = function()
{
this.UpdateSizes = function () {
var dlg = $('#ac_dlg_'+me.id);
// Adjust the dialog's size to fit into the screen
if (dlg.width() > ($(window).width()-40))
@@ -266,8 +264,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
results.height(height-form_height-40); // Leave some space for the buttons
};
this.UpdateButtons = function()
{
this.UpdateButtons = function () {
var okBtn = $('#btn_ok_'+me.id);
if ($('#count_'+me.id).val() > 0)
{
@@ -279,9 +276,9 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
}
};
this.DoSearchObjects = function(id)
{
var theMap = { sTargetClass: me.sTargetClass,
this.DoSearchObjects = function (id) {
var theMap = {
sTargetClass: me.sTargetClass,
iInputId: me.id,
sFilter: me.sFilter,
bSearchMode: me.bSearchMode
@@ -325,11 +322,12 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
// Run the query and display the results
me.ajax_request = $.post(AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
function(data)
{
function (data) {
$(sSearchAreaId).html(data);
$(sSearchAreaId+' .listResults').tableHover();
$('#fr_'+me.id+' input:radio').click(function() { me.UpdateButtons(); });
$('#fr_'+me.id+' input:radio').click(function () {
me.UpdateButtons();
});
me.UpdateButtons();
me.ajax_request = null;
me.UpdateSizes();
@@ -340,8 +338,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
return false; // Don't submit the form, stay in the current page !
};
this.DoOk = function()
{
this.DoOk = function () {
var s = $('#'+me.id+'_results').find(':input[name^=storedSelection]');
var iObjectId = 0;
if (s.length > 0)
@@ -356,7 +353,8 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
$('#label_'+this.id).addClass('ac_dlg_loading');
// Query the server again to get the display name of the selected object
var theMap = { sTargetClass: me.sTargetClass,
var theMap = {
sTargetClass: me.sTargetClass,
iInputId: me.id,
iObjectId: iObjectId,
sAttCode: me.sAttCode,
@@ -370,8 +368,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
// Run the query and get the result back directly in JSON
me.ajax_request = $.post(AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
function(data)
{
function (data) {
var oTemp = $('<div>'+data.name+'</div>');
var txt = oTemp.text(); // this causes HTML entities to be interpreted
$('#label_'+me.id).val(txt);
@@ -396,8 +393,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
// Workaround for a ui.jquery limitation: if the content of
// the dialog contains many INPUTs, closing and opening the
// dialog is very slow. So empty it each time.
this.OnClose = function()
{
this.OnClose = function () {
me.StopPendingRequest();
// called by the dialog, so in the context 'this' points to the jQueryObject
if (me.emptyOnClose)
@@ -409,8 +405,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
me.ajax_request = null;
};
this.SelectObjectClass = function(oWizHelper)
{
this.SelectObjectClass = function (oWizHelper) {
// Resetting target class to its original value
// (If not done, closing the dialog and trying to create a object again
// will force it be of the same class as the previous call)
@@ -419,11 +414,13 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
me.CreateObject(oWizHelper);
};
this.DoSelectObjectClass = function()
{
this.DoSelectObjectClass = function () {
// Retrieving selected value
var oSelectedClass = $('#ac_create_'+me.id+' select');
if(oSelectedClass.length !== 1) return;
if (oSelectedClass.length !== 1)
{
return;
}
// Setting new target class
me.sTargetClass = oSelectedClass.val();
@@ -433,9 +430,11 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
me.CreateObject();
};
this.CreateObject = function(oWizHelper)
this.CreateObject = function (oWizHelper) {
if ($('#'+me.id).prop('disabled'))
{
if($('#'+me.id).prop('disabled')) return; // Disabled, do nothing
return;
} // Disabled, do nothing
// Query the server to get the form to create a target object
if (me.bSelectMode)
{
@@ -446,7 +445,8 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
$('#label_'+me.id).addClass('ac_dlg_loading');
}
me.oWizardHelper.UpdateWizard();
var theMap = { sTargetClass: me.sTargetClass,
var theMap = {
sTargetClass: me.sTargetClass,
iInputId: me.id,
sAttCode: me.sAttCode,
'json': me.oWizardHelper.ToJSON(),
@@ -459,8 +459,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
// Run the query and get the result back directly in HTML
me.ajax_request = $.post(AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
function(data)
{
function (data) {
$('#ajax_'+me.id).html(data);
$('#ac_create_'+me.id).dialog('open');
$('#ac_create_'+me.id).dialog("option", "close", me.OnCloseCreateObject);
@@ -481,13 +480,11 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
);
};
this.CloseCreateObject = function()
{
this.CloseCreateObject = function () {
$('#ac_create_'+me.id).dialog("close");
};
this.OnCloseCreateObject = function()
{
this.OnCloseCreateObject = function () {
if (me.bSelectMode)
{
$('#fstatus_'+me.id).html('');
@@ -502,13 +499,13 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
$('#ajax_'+me.id).html('');
};
this.DoCreateObject = function()
{
this.DoCreateObject = function () {
var sFormId = $('#dcr_'+me.id+' form').attr('id');
if (CheckFields(sFormId, true))
{
$('#'+sFormId).block();
var theMap = { sTargetClass: me.sTargetClass,
var theMap = {
sTargetClass: me.sTargetClass,
iInputId: me.id,
sAttCode: me.sAttCode,
'json': me.oWizardHelper.ToJSON()
@@ -517,8 +514,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
// Gather the values from the form
// Gather the parameters from the search form
$('#'+sFormId+' :input').each(
function(i)
{
function (i) {
if (this.name != '')
{
if ($(this).hasClass('htmlEditor'))
@@ -547,8 +543,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
// Run the query and get the result back directly in JSON
me.ajax_request = $.post(AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
function(data)
{
function (data) {
$('#fstatus_'+me.id).html('');
if (data.id == 0)
{
@@ -586,8 +581,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
return false; // do NOT submit the form
};
this.Update = function()
{
this.Update = function () {
if ($('#'+me.id).prop('disabled'))
{
$('#v_'+me.id).html('');
@@ -607,9 +601,9 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
}
};
this.HKDisplay = function()
{
var theMap = { sTargetClass: me.sTargetClass,
this.HKDisplay = function () {
var theMap = {
sTargetClass: me.sTargetClass,
sInputId: me.id,
sFilter: me.sFilter,
bSearchMode: me.bSearchMode,
@@ -645,8 +639,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
// Run the query and display the results
me.ajax_request = $.post(AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
function(data)
{
function (data) {
$('#ac_tree_'+me.id).html(data);
var maxHeight = $(window).height()-110;
$('#tree_'+me.id).css({maxHeight: maxHeight});
@@ -655,8 +648,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
);
};
this.OnHKResize = function(event, ui)
{
this.OnHKResize = function (event, ui) {
var dh = ui.size.height-ui.originalSize.height;
if (dh != 0)
{
@@ -669,8 +661,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
}
};
this.OnHKClose = function()
{
this.OnHKClose = function () {
if (me.bSelectMode)
{
$('#fstatus_'+me.id).html('');
@@ -684,14 +675,14 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
$('#dlg_tree_'+me.id).remove();
};
this.DoHKOk = function()
{
this.DoHKOk = function () {
iObjectId = $('#tree_'+me.id+' input[name=selectObject]:checked').val();
$('#dlg_tree_'+me.id).dialog('close');
// Query the server again to get the display name of the selected object
var theMap = { sTargetClass: me.sTargetClass,
var theMap = {
sTargetClass: me.sTargetClass,
iInputId: me.id,
iObjectId: iObjectId,
sAttCode: me.sAttCode,

View File

@@ -371,26 +371,6 @@ function ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue,
}
}
/*
function UpdateDependentFields(aFieldNames)
{
//console.log('UpdateDependentFields:');
//console.log(aFieldNames);
index = 0;
oWizardHelper.ResetQuery();
oWizardHelper.UpdateWizard();
while(index < aFieldNames.length )
{
sAttCode = aFieldNames[index];
sFieldId = oWizardHelper.GetFieldId(sAttCode);
$('#v_'+sFieldId).html('<img src="../images/indicator.gif" />');
oWizardHelper.RequestAllowedValues(sAttCode);
index++;
}
oWizardHelper.AjaxQueryServer();
}
*/
function ResetPwd(id)
{
// Reset the values of the password fields

View File

@@ -1,23 +1,23 @@
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/*
* Copyright (C) 2010-2020 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
// JavaScript Document
function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper, sExtKeyToRemote, bDoSearch)
{
function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper, sExtKeyToRemote, bDoSearch) {
this.id = id;
this.iInputId = iInputId;
this.sClass = sClass;
@@ -33,10 +33,11 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
this.bDoSearch = bDoSearch; // false if the search is not launched
var me = this;
this.Init = function()
{
this.Init = function () {
// make sure that the form is clean
$('#linkedset_'+this.id+' .selection').each( function() { this.checked = false; });
$('#linkedset_'+this.id+' .selection').each(function () {
this.checked = false;
});
$('#'+this.id+'_btnRemove').prop('disabled', true);
$('#linkedset_'+me.id).on('remove', function () {
@@ -47,12 +48,15 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
me.RegisterChange();
var oInput = $('#'+this.iInputId);
oInput.bind('update_value', function() { $(this).val(me.GetUpdatedValue()); });
oInput.closest('form').submit(function() { return me.OnFormSubmit(); });
oInput.bind('update_value', function () {
$(this).val(me.GetUpdatedValue());
});
oInput.closest('form').submit(function () {
return me.OnFormSubmit();
});
};
this.RemoveSelected = function()
{
this.RemoveSelected = function () {
var my_id = '#'+me.id;
$('#linkedset_'+me.id+' .selection:checked').each(function () {
$(my_id+'_row_'+this.value).remove();
@@ -87,8 +91,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
}
};
this.OnSelectChange = function()
{
this.OnSelectChange = function () {
var nbChecked = $('#linkedset_'+me.id+' .selection:checked').length;
if (nbChecked > 0)
{
@@ -100,12 +103,12 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
}
};
this.AddObjects = function()
{
this.AddObjects = function () {
var me = this;
$('#'+me.id+'_indicatorAdd').html('&nbsp;<img src="../images/indicator.gif"/>');
me.oWizardHelper.UpdateWizard();
var theMap = { sAttCode: me.sAttCode,
var theMap = {
sAttCode: me.sAttCode,
iInputId: me.iInputId,
sSuffix: me.sSuffix,
bDuplicates: me.bDuplicates,
@@ -127,8 +130,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
"data": theMap,
"dataType": "html"
})
.done(function (data)
{
.done(function (data) {
$('#dlg_'+me.id).html(data);
$('#dlg_'+me.id).dialog('open');
me.UpdateSizes(null, null);
@@ -148,8 +150,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
;
};
this.SearchObjectsToAdd = function()
{
this.SearchObjectsToAdd = function () {
$('#count_'+me.id).change(function () {
var c = this.value;
me.UpdateButtons(c);
@@ -161,8 +162,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
return false; // Don't submit the form, stay in the current page !
};
this.UpdateButtons = function(iCount)
{
this.UpdateButtons = function (iCount) {
var okBtn = $('#btn_ok_'+me.id);
if (iCount > 0)
{
@@ -174,9 +174,9 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
}
};
this.DoAddObjects = function()
{
var theMap = { sAttCode: me.sAttCode,
this.DoAddObjects = function () {
var theMap = {
sAttCode: me.sAttCode,
iInputId: me.iInputId,
sSuffix: me.sSuffix,
bDuplicates: me.bDuplicates,
@@ -192,8 +192,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
var sMode = selectionMode.val();
theMap['selectionMode'] = sMode;
$('#fs_SearchFormToAdd_'+me.id+' :input').each(
function(i)
{
function (i) {
theMap[this.name] = this.value;
}
);
@@ -216,8 +215,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
// {
// Normal table, retrieve all the checked check-boxes
$(':checked[name^=selectObject]', context).each(
function(i)
{
function (i) {
if ((this.name != '') && ((this.type != 'checkbox') || (this.checked)))
{
arrayExpr = /\[\]$/;
@@ -255,8 +253,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
$('#busy_'+me.iInputId).html('&nbsp;<img src="../images/indicator.gif"/>');
// Run the query and display the results
$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', theMap,
function(data)
{
function (data) {
if (data != '')
{
$('#'+me.id+'_empty_row').hide();
@@ -264,7 +261,9 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
$('#linkedset_'+me.id+' .listResults').trigger('update');
$('#linkedset_'+me.id+' .listResults').tableHover();
$('#linkedset_'+me.id+' .listResults').trigger('update').trigger("applyWidgets"); // table is already sortable, just refresh it
$('#linkedset_'+me.id+' :input').each( function() { $(this).trigger('validate', ''); }); // Validate newly added form fields...
$('#linkedset_'+me.id+' :input').each(function () {
$(this).trigger('validate', '');
}); // Validate newly added form fields...
$('#busy_'+me.iInputId).html('');
}
},
@@ -274,8 +273,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
return false;
};
this.AddLink = function (iAddedId, iRemote)
{
this.AddLink = function (iAddedId, iRemote) {
// Assumption: this identifier will be higher than the previous one
me.iMaxAddedId = iAddedId;
var sFormPrefix = me.iInputId;
@@ -285,14 +283,12 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
me.aAdded[iAddedId] = oAdded;
};
this.OnLinkAdded = function(iAddedId, iRemote)
{
this.OnLinkAdded = function (iAddedId, iRemote) {
this.AddLink(iAddedId, iRemote);
me.RegisterChange();
};
this.UpdateSizes = function(event, ui)
{
this.UpdateSizes = function (event, ui) {
var dlg = $('#dlg_'+me.id);
var searchForm = $('#SearchFormToAdd_'+me.id);
var results = $('#SearchResultsToAdd_'+me.id);
@@ -325,8 +321,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
results.height(height-form_height-40); // Leave some space for the buttons
};
this.GetUpdatedValue = function()
{
this.GetUpdatedValue = function () {
var sSelector = '#linkedset_'+me.id+' :input[name^=attr_'+me.id+']';
var aIndexes = [];
var aValues = [];
@@ -365,29 +360,37 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
return JSON.stringify(aValues);
};
this.RegisterChange = function()
{
this.RegisterChange = function () {
// Listen only used inputs
$('#linkedset_'+me.id+' :input[name^="attr_'+me.sAttCode+'["]').off('change').on('change', function () {
if (!($(this).hasClass('selection'))) {
if (!($(this).hasClass('selection')))
{
var oCheckbox = $(this).closest('tr').find('.selection');
var iLink = oCheckbox.attr('data-link-id');
var iUniqueId = oCheckbox.attr('data-unique-id');
var sAttCode = $(this).closest('.attribute-edit').attr('data-attcode');
var value = $(this).val();
return me.OnValueChange(iLink, iUniqueId, sAttCode, value);
return me.OnValueChange(iLink, iUniqueId, sAttCode, value, this);
}
return true;
});
};
this.OnValueChange = function(iLink, iUniqueId, sAttCode, value)
{
/**
* @param int iLink id contained in the data-link-id attribute of the .selection widget
* @param int iUniqueId id contained in the data-unique-id attribute of the .selection widget
* @param string sAttCode
* @param string value new value of the autocomplete
* @param jQuery $oSourceObject object which fires the event
*/
this.OnValueChange = function (iLink, iUniqueId, sAttCode, value, $oSourceObject) {
var sFormPrefix = me.iInputId;
if (iLink > 0) {
if (iLink > 0)
{
// Modifying an existing link
var oModified = me.aModified[iLink];
if (oModified == undefined) {
if (oModified == undefined)
{
// Still not marked as modified
oModified = {};
oModified['formPrefix'] = sFormPrefix;
@@ -396,7 +399,8 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
oModified['attr_'+sFormPrefix+sAttCode] = value;
me.aModified[iLink] = oModified;
}
else {
else
{
// Modifying a newly added link - the structure should already be up to date
if (iUniqueId < 0)
{
@@ -406,8 +410,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
}
};
this.OnFormSubmit = function()
{
this.OnFormSubmit = function () {
var oDiv = $('#linkedset_'+me.id);
var sToBeDeleted = JSON.stringify(me.aRemoved);

View File

@@ -1,42 +1,64 @@
// Copyright (C) 2010-2016 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/*
* Copyright (C) 2010-2020 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
// Wizard Helper JavaScript class to communicate with the WizardHelper PHP class
if (!Array.prototype.indexOf) // Emulation of the indexOf function for IE and old browsers
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0) from += len;
for (; from < len; from++)
{
if (from in this && this[from] === elt) return from;
}
return -1;
};
}
function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus)
{
this.m_oData = { 'm_sClass' : '',
/**
* Helper to handle dependant fields to be refreshed when parent field is updated.
* The JS WizardHelper class has a WizardHelper PHP counterpart.
*
* How to use it :
*
* 1) Initialize by calling :
* <pre><code>
* var oWizardHelper = new WizardHelper('Team', '', '');
* oWizardHelper.SetFieldsMap({"name":"2_name","status":"2_status","org_id":"2_org_id","email":"2_email","phone":"2_phone","notify":"2_notify","function":"2_function","id":"_id","persons_list":"2_persons_list","tickets_list":"2_tickets_list","cis_list":"2_cis_list"});
oWizardHelper.SetFieldsCount(11);
* </code></pre>
*
* 2) On field update launch the UpdateField method, passing the fields to update. This list is retrieved using
* \MetaModel::GetDependentAttributes.
* For now this is launched by an handler on the 'change.dependencies' event, and this event is fired by each field (see
* \cmdbAbstractObject::GetFormElementForField and $aEventsList var)
* <pre><code>
* $('#2_name')
* .unbind('change.dependencies')
* .bind('change.dependencies', function(evt, sFormId) {
* return oWizardHelper.UpdateDependentFields(['friendlyname']);
* }
* );
* </code></pre>
*
* 3) The WizardHelper JS object will send an XHR query to ajax.render.php with operation=wizard_helper
* A new WizardHelper PHP object will be initialized with \WizardHelper::FromJSON
* This will send back to the browser fields updates, by returning JS code that will :
*
* * update JS WizardHelper m_oData attribute
* * launch JS WizardHelper UpdateFields() method
*
* @param sClass
* @param sFormPrefix
* @param sState
* @param sInitialState
* @param sStimulus
* @constructor
*/
function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus) {
this.m_oData = {
'm_sClass': '',
'm_oFieldsMap': {},
'm_oCurrentValues': {},
'm_aDefaultValueRequested': [],
@@ -60,24 +82,20 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus)
}
// Methods
this.SetFieldsMap = function (oFieldsMap)
{
this.SetFieldsMap = function (oFieldsMap) {
this.m_oData.m_oFieldsMap = oFieldsMap;
};
this.SetFieldsCount = function (count)
{
this.SetFieldsCount = function (count) {
this.m_oData.m_iFieldsCount = count;
};
this.GetFieldId = function(sFieldName)
{
this.GetFieldId = function (sFieldName) {
id = this.m_oData.m_oFieldsMap[sFieldName];
return id;
};
this.RequestDefaultValue = function (sFieldName)
{
this.RequestDefaultValue = function (sFieldName) {
currentValue = this.UpdateCurrentValue(sFieldName);
if (currentValue == null)
{
@@ -85,37 +103,31 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus)
}
};
this.RequestAllowedValues = function (sFieldName)
{
this.RequestAllowedValues = function (sFieldName) {
this.m_oData.m_aAllowedValuesRequested.push(sFieldName);
};
this.SetCurrentValue = function (sFieldName, currentValue)
{
this.SetCurrentValue = function (sFieldName, currentValue) {
this.m_oData.m_oCurrentValues[sFieldName] = currentValue;
};
this.ToJSON = function ()
{
this.ToJSON = function () {
return JSON.stringify(this.m_oData);
};
this.FromJSON = function (sJSON)
{
this.FromJSON = function (sJSON) {
//console.log('Parsing JSON:'+sJSON);
this.m_oData = JSON.parse(sJSON);
};
this.ResetQuery = function ()
{
this.ResetQuery = function () {
this.m_oData.m_aDefaultValueRequested = [];
this.m_oData.m_oDefaultValue = {};
this.m_oData.m_aAllowedValuesRequested = [];
this.m_oData.m_oAllowedValues = {};
};
this.UpdateFields = function ()
{
this.UpdateFields = function () {
var aRefreshed = [];
//console.log('** UpdateFields **');
// Set the full HTML for the input field
@@ -153,8 +165,7 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus)
}
};
this.UpdateWizard = function ()
{
this.UpdateWizard = function () {
//console.log('** UpdateWizard **')
for(sFieldCode in this.m_oData.m_oFieldsMap)
{
@@ -164,14 +175,12 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus)
}
};
this.UpdateWizardToJSON = function ()
{
this.UpdateWizardToJSON = function () {
this.UpdateWizard();
return this.ToJSON();
};
this.AjaxQueryServer = function ()
{
this.AjaxQueryServer = function () {
//console.log('data sent:', this.ToJSON());
//console.log('oWizard:', this);
$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php',
@@ -179,16 +188,11 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus)
function (html) {
$('#ajax_content').html(html);
$('.blockUI').parent().unblock();
//console.log('data received:', oWizardHelper);
//oWizardHelper.FromJSON(json_data);
//oWizardHelper.UpdateFields(); // Is done directly in the html provided by ajax.render.php
//console.log(oWizardHelper);
//$('#wizStep'+ G_iCurrentStep).unblock( {fadeOut: 0} );
});
}
);
};
this.Preview = function (divId)
{
this.Preview = function (divId) {
//console.log('data sent:', this.ToJSON());
//console.log('oWizard:', this);
$('#'+divId).load(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?operation=wizard_helper_preview',
@@ -210,16 +214,21 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus)
return value;
};
this.UpdateDependentFields = function(aFieldNames)
{
index = 0;
this.UpdateDependentFields = function (aFieldNames) {
var index = 0,
nbOfFieldsToUpdate = 0,
sAttCode,
sFieldId;
this.ResetQuery();
this.UpdateWizard();
while (index < aFieldNames.length)
{
sAttCode = aFieldNames[index];
sFieldId = this.GetFieldId(sAttCode);
if (sFieldId !== undefined) {
if (sFieldId !== undefined)
{
nbOfFieldsToUpdate++;
$('#fstatus_'+sFieldId).html('<img src="../images/indicator.gif" />');
$('#field_'+sFieldId).find('div').block({
message: '',
@@ -229,19 +238,21 @@ function WizardHelper(sClass, sFormPrefix, sState, sInitialState, sStimulus)
}
index++;
}
if (nbOfFieldsToUpdate > 0)
{
this.AjaxQueryServer();
}
};
this.ReloadObjectCreationForm = function(sFormId, sTargetState)
{
this.ReloadObjectCreationForm = function (sFormId, sTargetState) {
$('#'+sFormId).block();
this.UpdateWizard();
this.ResetQuery();
var sTransactionId = $('input[name=transaction_id]').val();
$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php',
{json_obj: this.ToJSON(), operation: 'obj_creation_form', target_state: sTargetState, transaction_id: sTransactionId},
function(data)
{
function (data) {
// Delete any previous instances of CKEditor
$('#'+sFormId).find('.htmlEditor').each(function () {
var sId = $(this).attr('id');

View File

@@ -701,6 +701,7 @@ try
break;
////////////////////////////////////////////////////////////
/// WizardHelper : see the corresponding PHP class, and JS class
case 'wizard_helper_preview':
$oPage->SetContentType('text/html');