mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-19 00:28:47 +02:00
Advanced Search: Auto-complete search on foreign keys
SVN:b1162[5592]
This commit is contained in:
@@ -54,7 +54,7 @@ class UISearchFormForeignKeys
|
||||
'open' => $bOpen,
|
||||
'menu' => false,
|
||||
'table_id' => "SearchResultsToAdd_{$this->m_iInputId}",
|
||||
'table_id2' => 'add_'.$this->m_sAttCode,
|
||||
'table_id2' => "add_{$this->m_iInputId}",
|
||||
'table_inner_id' => "ResultsToAdd_{$this->m_iInputId}",
|
||||
'selection_mode' => true,
|
||||
'cssCount' => '#count_'.$this->m_sAttCode.$this->m_sNameSuffix,
|
||||
@@ -65,14 +65,14 @@ class UISearchFormForeignKeys
|
||||
$sHtml .= "<div style=\"background: #fff; border:0; text-align:center; vertical-align:middle;\"><p>".Dict::S('UI:Message:EmptyList:UseSearchForm')."</p></div>\n";
|
||||
$sHtml .= "</div>\n";
|
||||
$sHtml .= "<input type=\"hidden\" id=\"count_{$this->m_iInputId}\" value=\"0\"/>";
|
||||
$sHtml .= "<input type=\"button\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"$('#dlg_{$this->m_iInputId}').dialog('close');\"> <input id=\"btn_ok_{$this->m_iInputId}\" disabled=\"disabled\" type=\"button\" onclick=\"return oWForeignKeysWidget{$this->m_iInputId}.DoAddObjects(this.id);\" value=\"".Dict::S('UI:Button:Add')."\">";
|
||||
$sHtml .= "<input type=\"button\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"$('#dlg_{$this->m_iInputId}').dialog('close');\"> <input id=\"btn_ok_{$this->m_iInputId}\" disabled=\"disabled\" type=\"button\" onclick=\"return oForeignKeysWidget{$this->m_iInputId}.DoAddObjects(this.id);\" value=\"".Dict::S('UI:Button:Add')."\">";
|
||||
$sHtml .= "</div>\n";
|
||||
$sHtml .= "</form>\n";
|
||||
$oPage->add($sHtml);
|
||||
$oPage->add_ready_script("$('#dlg_{$this->m_iInputId}').dialog({ width: $(window).width()*0.8, height: $(window).height()*0.8, autoOpen: false, modal: true, resizeStop: oWForeignKeysWidget{$this->m_iInputId}.UpdateSizes });");
|
||||
$oPage->add_ready_script("$('#dlg_{$this->m_iInputId}').dialog({ width: $(window).width()*0.8, height: $(window).height()*0.8, autoOpen: false, modal: true, resizeStop: oForeignKeysWidget{$this->m_iInputId}.UpdateSizes });");
|
||||
$oPage->add_ready_script("$('#dlg_{$this->m_iInputId}').dialog('option', {title:'$sTitle'});");
|
||||
$oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_iInputId} form').bind('submit.uilinksWizard', oWForeignKeysWidget{$this->m_iInputId}.SearchObjectsToAdd);");
|
||||
$oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_iInputId}').resize(oWForeignKeysWidget{$this->m_iInputId}.UpdateSizes);");
|
||||
$oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_iInputId} form').bind('submit.uilinksWizard', oForeignKeysWidget{$this->m_iInputId}.SearchObjectsToAdd);");
|
||||
$oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_iInputId}').resize(oForeignKeysWidget{$this->m_iInputId}.UpdateSizes);");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,8 +97,8 @@ class UISearchFormForeignKeys
|
||||
}
|
||||
|
||||
$oBlock = new DisplayBlock($oFilter, 'list', false);
|
||||
$oBlock->Display($oP, "ResultsToAdd_{$this->m_sAttCode}",
|
||||
array('menu' => false, 'cssCount' => '#count_'.$this->m_sAttCode.$this->m_sNameSuffix, 'selection_mode' => true, 'table_id' => 'add_'.$this->m_sAttCode));
|
||||
$oBlock->Display($oP, "ResultsToAdd_{$this->m_iInputId}",
|
||||
array('menu' => false, 'cssCount' => "#count_{$this->m_iInputId}", 'selection_mode' => true, 'table_id' => "add_{$this->m_iInputId}"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -273,15 +273,15 @@ $(function()
|
||||
// External classes
|
||||
var oFilterIconElem = oFilterElem.find('.sff_search_dialog').uniqueId();
|
||||
oFilterIconElem.attr('id', oFilterIconElem.attr('id').replace(/-/g, '_'));
|
||||
var oWForeignKeysWidgetCurrent = new SearchFormForeignKeys(
|
||||
var oForeignKeysWidgetCurrent = new SearchFormForeignKeys(
|
||||
oFilterIconElem.attr('id'), // id
|
||||
me.options.field.target_class, // sTargetClass
|
||||
me.options.field.code, // sAttCode
|
||||
'', // sFilter //TODO
|
||||
me.options.field.label // sTitle
|
||||
);
|
||||
window['oWForeignKeysWidget' + oFilterIconElem.attr('id')] = oWForeignKeysWidgetCurrent;
|
||||
oWForeignKeysWidgetCurrent.Init();
|
||||
window['oForeignKeysWidget'+oFilterIconElem.attr('id')] = oForeignKeysWidgetCurrent;
|
||||
oForeignKeysWidgetCurrent.Init();
|
||||
|
||||
// model of similar code found in UIExtKeyWidget (you can find another on in UILinksWidget for example)
|
||||
// oACWidget_{$this->iId} = new ExtKeyWidget('{$this->iId}', '{$this->sTargetClass}', '$sFilter', '$sTitle', true, $sWizHelper, '{$this->sAttCode}', $sJSSearchMode);
|
||||
@@ -342,7 +342,7 @@ $(function()
|
||||
//
|
||||
// // - Open search dialog
|
||||
oFilterElem.find('.sff_search_dialog').on('click', function(){
|
||||
oWForeignKeysWidgetCurrent.ShowModalSearchForeignKeys();
|
||||
oForeignKeysWidgetCurrent.ShowModalSearchForeignKeys();
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ function SearchFormForeignKeys(id, sTargetClass, sAttCode, sFilter, sTitle)
|
||||
dlg.height($(window).height()-70);
|
||||
}
|
||||
var searchForm = dlg.find('div.display_block:first'); // Top search form, enclosing display_block
|
||||
var results = $('#dr_'+me.id);
|
||||
var results = $('#SearchResultsToAdd_'+me.id);
|
||||
var oPadding = {};
|
||||
var aKeys = ['top', 'right', 'bottom', 'left'];
|
||||
for(k in aKeys)
|
||||
@@ -199,7 +199,7 @@ function SearchFormForeignKeys(id, sTargetClass, sAttCode, sFilter, sTitle)
|
||||
theMap['sRemoteClass'] = theMap['class']; // swap 'class' (defined in the form) and 'remoteClass'
|
||||
theMap.operation = 'ListResultsSearchForeignKeys'; // Override what is defined in the form itself
|
||||
theMap.sAttCode = me.sAttCode;
|
||||
sSearchAreaId = '#dr_'+me.id;
|
||||
sSearchAreaId = '#SearchResultsToAdd_'+me.id;
|
||||
//$(sSearchAreaId).html('<div style="text-align:center;width:100%;height:24px;vertical-align:middle;"><img src="../images/indicator.gif" /></div>');
|
||||
$(sSearchAreaId).block();
|
||||
me.UpdateButtons();
|
||||
@@ -228,59 +228,56 @@ function SearchFormForeignKeys(id, sTargetClass, sAttCode, sFilter, sTitle)
|
||||
return false; // Don't submit the form, stay in the current page !
|
||||
};
|
||||
|
||||
this.DoOk = function()
|
||||
{
|
||||
var s = $('#'+me.id+'_results').find(':input[name^=storedSelection]');
|
||||
var iObjectId = 0;
|
||||
if (s.length > 0)
|
||||
{
|
||||
iObjectId = s.val();
|
||||
}
|
||||
else
|
||||
{
|
||||
iObjectId = $('#fr_'+me.id+' input[name=selectObject]:checked').val();
|
||||
}
|
||||
$('#dlg_'+this.id).dialog('close');
|
||||
$('#label_'+this.id).addClass('dlg_loading');
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
this.DoAddObjects = function () {
|
||||
// Gather the parameters from the search form
|
||||
var theMap = {};
|
||||
var context = $('#SearchResultsToAdd_'+me.id);
|
||||
var selectionMode = $(':input[name=selectionMode]', context);
|
||||
if (selectionMode.length > 0) {
|
||||
// Paginated table retrieve the mode and the exceptions
|
||||
theMap['selectionMode'] = selectionMode.val();
|
||||
$('#fs_SearchFormToAdd_'+me.id+' :input').each(function () {
|
||||
theMap[this.name] = this.value;
|
||||
});
|
||||
|
||||
// Query the server again to get the display name of the selected object
|
||||
var theMap = { sTargetClass: me.sTargetClass,
|
||||
iInputId: me.id,
|
||||
iObjectId: iObjectId,
|
||||
sAttCode: me.sAttCode,
|
||||
// bSearchMode: me.bSearchMode,
|
||||
operation: 'getObjectName'
|
||||
};
|
||||
|
||||
// Make sure that we cancel any pending request before issuing another
|
||||
// since responses may arrive in arbitrary order
|
||||
me.StopPendingRequest();
|
||||
|
||||
// Run the query and get the result back directly in JSON
|
||||
me.ajax_request = $.post( AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
|
||||
function(data)
|
||||
{
|
||||
var oTemp = $('<div>'+data.name+'</div>');
|
||||
var txt = oTemp.text(); // this causes HTML entities to be interpreted
|
||||
$('#label_'+me.id).val(txt);
|
||||
$('#label_'+me.id).removeClass('dlg_loading');
|
||||
var prevValue = $('#'+me.id).val();
|
||||
$('#'+me.id).val(iObjectId);
|
||||
if (prevValue != iObjectId)
|
||||
{
|
||||
$('#'+me.id).trigger('validate');
|
||||
$('#'+me.id).trigger('extkeychange');
|
||||
$('#'+me.id).trigger('change');
|
||||
$(':input[name^=storedSelection]', context).each(function () {
|
||||
if (typeof theMap[this.name] === "undefined") {
|
||||
theMap[this.name] = [];
|
||||
}
|
||||
$('#label_'+me.id).focus();
|
||||
me.ajax_request = null;
|
||||
},
|
||||
'json'
|
||||
theMap[this.name].push(this.value);
|
||||
$(this).remove(); // Remove the selection for the next time the dialog re-opens
|
||||
});
|
||||
}
|
||||
|
||||
// Normal table, retrieve all the checked check-boxes
|
||||
$(':checked[name^=selectObject]', context).each(
|
||||
function (i) {
|
||||
if ((this.name != '') && ((this.type != 'checkbox') || (this.checked))) {
|
||||
arrayExpr = /\[\]$/;
|
||||
if (arrayExpr.test(this.name)) {
|
||||
// Array
|
||||
if (typeof theMap[this.name] === "undefined") {
|
||||
theMap[this.name] = [];
|
||||
}
|
||||
theMap[this.name].push(this.value);
|
||||
}
|
||||
else {
|
||||
theMap[this.name] = this.value;
|
||||
}
|
||||
}
|
||||
$(this).parents('tr:first').remove(); // Remove the whole line, so that, next time the dialog gets displayed it's no longer there
|
||||
}
|
||||
);
|
||||
|
||||
return false; // Do NOT submit the form in case we are called by OnSubmit...
|
||||
$('#dlg_'+me.id).dialog('close');
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
// 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.
|
||||
@@ -290,15 +287,13 @@ function SearchFormForeignKeys(id, sTargetClass, sAttCode, sFilter, sTitle)
|
||||
// called by the dialog, so in the context 'this' points to the jQueryObject
|
||||
if (me.emptyOnClose)
|
||||
{
|
||||
$('#dr_'+me.id).html(me.emptyHtml);
|
||||
$('#SearchResultsToAdd_'+me.id).html(me.emptyHtml);
|
||||
}
|
||||
$('#label_'+me.id).removeClass('dlg_loading');
|
||||
$('#label_'+me.id).focus();
|
||||
me.ajax_request = null;
|
||||
};
|
||||
|
||||
|
||||
|
||||
this.DoSelectObjectClass = function()
|
||||
{
|
||||
// Retrieving selected value
|
||||
@@ -313,9 +308,6 @@ function SearchFormForeignKeys(id, sTargetClass, sAttCode, sFilter, sTitle)
|
||||
me.CreateObject();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
this.Update = function()
|
||||
{
|
||||
if ($('#'+me.id).prop('disabled'))
|
||||
@@ -336,139 +328,4 @@ function SearchFormForeignKeys(id, sTargetClass, sAttCode, sFilter, sTitle)
|
||||
$('#mini_search_'+me.id).show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
this.OnFormSubmit = function()
|
||||
{
|
||||
var oDiv = $('#linkedset_'+me.id);
|
||||
|
||||
var aToBeCreated = [];
|
||||
me.aAdded.forEach(function(oAdded){
|
||||
if (oAdded != null)
|
||||
{
|
||||
aToBeCreated.push(oAdded);
|
||||
}
|
||||
});
|
||||
var sToBeCreated = JSON.stringify(aToBeCreated);
|
||||
$('<input type="hidden" name="attr_'+me.sAttCode+'_tbc">').val(sToBeCreated).appendTo(oDiv);
|
||||
};
|
||||
// this.HKDisplay = function()
|
||||
// {
|
||||
// var theMap = { sTargetClass: me.sTargetClass,
|
||||
// sInputId: me.id,
|
||||
// sFilter: me.sFilter,
|
||||
//// bSearchMode: me.bSearchMode,
|
||||
// sAttCode: me.sAttCode,
|
||||
// value: $('#'+me.id).val()
|
||||
// };
|
||||
//
|
||||
//// if (me.bSelectMode)
|
||||
//// {
|
||||
//// $('#fstatus_'+me.id).html('<img src="../images/indicator.gif" />');
|
||||
//// }
|
||||
//// else
|
||||
//// {
|
||||
//// $('#label_'+me.id).addClass('dlg_loading');
|
||||
//// }
|
||||
// $('#label_'+me.id).addClass('dlg_loading');
|
||||
//
|
||||
// theMap['sRemoteClass'] = me.sTargetClass;
|
||||
// theMap.operation = 'displayHierarchy';
|
||||
//
|
||||
// // Make sure that we cancel any pending request before issuing another
|
||||
// // since responses may arrive in arbitrary order
|
||||
// me.StopPendingRequest();
|
||||
//
|
||||
// // Run the query and display the results
|
||||
// me.ajax_request = $.post( AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
|
||||
// function(data)
|
||||
// {
|
||||
// $('#ac_tree_'+me.id).html(data);
|
||||
// var maxHeight = $(window).height()-110;
|
||||
// $('#tree_'+me.id).css({maxHeight: maxHeight});
|
||||
// },
|
||||
// 'html'
|
||||
// );
|
||||
// };
|
||||
//
|
||||
// this.OnHKResize = function(event, ui)
|
||||
// {
|
||||
// var dh = ui.size.height - ui.originalSize.height;
|
||||
// if (dh != 0)
|
||||
// {
|
||||
// var dlg_content = $('#dlg_tree_'+me.id+' .wizContainer');
|
||||
// var h = dlg_content.height();
|
||||
// dlg_content.height(h + dh);
|
||||
// var tree = $('#tree_'+me.id);
|
||||
// var h = tree.height();
|
||||
// tree.height(h + dh - 1);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// this.OnHKClose = function()
|
||||
// {
|
||||
// if (me.bSelectMode)
|
||||
// {
|
||||
// $('#fstatus_'+me.id).html('');
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $('#label_'+me.id).removeClass('dlg_loading');
|
||||
// }
|
||||
// $('#label_'+me.id).focus();
|
||||
// $('#dlg_tree_'+me.id).dialog("destroy");
|
||||
// $('#dlg_tree_'+me.id).remove();
|
||||
// };
|
||||
//
|
||||
// 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,
|
||||
// iInputId: me.id,
|
||||
// iObjectId: iObjectId,
|
||||
// sAttCode: me.sAttCode,
|
||||
//// bSearchMode: me.bSearchMode,
|
||||
// operation: 'getObjectName'
|
||||
// };
|
||||
//
|
||||
// // Make sure that we cancel any pending request before issuing another
|
||||
// // since responses may arrive in arbitrary order
|
||||
// me.StopPendingRequest();
|
||||
//
|
||||
// // Run the query and get the result back directly in JSON
|
||||
// me.ajax_request = $.post( AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
|
||||
// function(data)
|
||||
// {
|
||||
// var oTemp = $('<div>'+data.name+'</div>');
|
||||
// var txt = oTemp.text(); // this causes HTML entities to be interpreted
|
||||
// $('#label_'+me.id).val(txt);
|
||||
// $('#label_'+me.id).removeClass('dlg_loading');
|
||||
// var prevValue = $('#'+me.id).val();
|
||||
// $('#'+me.id).val(iObjectId);
|
||||
// if (prevValue != iObjectId)
|
||||
// {
|
||||
// $('#'+me.id).trigger('validate');
|
||||
// $('#'+me.id).trigger('extkeychange');
|
||||
// $('#'+me.id).trigger('change');
|
||||
// }
|
||||
// if ( $('#'+me.id).hasClass('multiselect'))
|
||||
// {
|
||||
// $('#'+me.id+' option').each(function() { this.selected = ($(this).attr('value') == iObjectId); });
|
||||
// $('#'+me.id).multiselect('refresh');
|
||||
// }
|
||||
// $('#label_'+me.id).focus();
|
||||
// me.ajax_request = null;
|
||||
// },
|
||||
// 'json'
|
||||
// );
|
||||
//
|
||||
// return false; // Do NOT submit the form in case we are called by OnSubmit...
|
||||
// };
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user