From 2d9140e56c6759bf27e9b9e83b8b35ddced4aad7 Mon Sep 17 00:00:00 2001 From: Bruno Da Silva Date: Tue, 13 Mar 2018 13:03:14 +0000 Subject: [PATCH] Search form Result list now expose their extra params using jQuery().data() function SVN:b1162[5415] --- application/displayblock.class.inc.php | 2 +- application/ui.extkeywidget.class.inc.php | 65 +++++++++++-------- .../ui.linksdirectwidget.class.inc.php | 5 +- application/ui.linkswidget.class.inc.php | 1 + pages/ajax.searchform.php | 45 +++++++------ 5 files changed, 67 insertions(+), 51 deletions(-) diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 3907e8112..a740f7cf6 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -290,7 +290,7 @@ class DisplayBlock if (($bAutoReload) && ($this->m_sStyle != 'search')) // Search form do NOT auto-reload { - $oPage->add_script('aAutoReloadBlock["'.$sId.'"] = setInterval("ReloadBlock(\''.$sId.'\', \''.$this->m_sStyle.'\', \''.$sFilter.'\', \"'.$sExtraParams.'\")", '.$iReloadInterval.');'); + $oPage->add_script('aAutoReloadBlock = setInterval("ReloadBlock(\''.$sId.'\', \''.$this->m_sStyle.'\', \''.$sFilter.'\', \"'.$sExtraParams.'\")", '.$iReloadInterval.');'); } return $sHtml; } diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php index f260b7cd4..d16fb0242 100644 --- a/application/ui.extkeywidget.class.inc.php +++ b/application/ui.extkeywidget.class.inc.php @@ -19,15 +19,15 @@ * Class UIExtKeyWidget * UI wdiget for displaying and editing external keys when * A simple drop-down list is not enough... - * + * * The layout is the following - * + * * +-- #label_ (input)-------+ +-----------+ * | | | Browse... | * +-----------------------------+ +-----------+ - * + * * And the popup dialog has the following layout: - * + * * +------------------- ac_dlg_ (div)-----------+ * + +--- ds_ (div)---------------------------+ | * | | +------------- fs_ (form)------------+ | | @@ -61,13 +61,13 @@ require_once(APPROOT.'/application/webpage.class.inc.php'); require_once(APPROOT.'/application/displayblock.class.inc.php'); -class UIExtKeyWidget +class UIExtKeyWidget { protected $iId; protected $sTargetClass; protected $sAttCode; protected $bSearchMode; - + //public function __construct($sAttCode, $sClass, $sTitle, $oAllowedValues, $value, $iInputId, $bMandatory, $sNameSuffix = '', $sFieldPrefix = '', $sFormPrefix = '') static public function DisplayFromAttCode($oPage, $sAttCode, $sClass, $sTitle, $oAllowedValues, $value, $iInputId, $bMandatory, $sFieldName = '', $sFormPrefix = '', $aArgs, $bSearchMode = false) { @@ -94,7 +94,7 @@ class UIExtKeyWidget $this->sAttCode = $sAttCode; $this->bSearchMode = $bSearchMode; } - + /** * Get the HTML fragment corresponding to the ext key editing widget * @param WebPage $oP The web page used for all the output @@ -107,10 +107,10 @@ class UIExtKeyWidget { $this->bSearchMode = $bSearchMode; } - $sTitle = addslashes($sTitle); + $sTitle = addslashes($sTitle); $oPage->add_linked_script('../js/extkeywidget.js'); $oPage->add_linked_script('../js/forms-json-utils.js'); - + $bCreate = (!$this->bSearchMode) && (UserRights::IsActionAllowed($this->sTargetClass, UR_ACTION_BULK_MODIFY) && $bAllowTargetCreation); $bExtensions = true; $sMessage = Dict::S('UI:Message:EmptyList:UseSearchForm'); @@ -123,7 +123,7 @@ class UIExtKeyWidget $sWizHelper = 'null'; $sWizHelperJSON = "''"; $sJSSearchMode = 'true'; - } + } else { if (isset($aArgs['wizHelper'])) @@ -159,7 +159,7 @@ class UIExtKeyWidget while($oObj = $oAllowedValues->Fetch()) { $aAllowedValues[$oObj->GetKey()] = $oObj->GetName(); - } + } $sHTMLValue .= $oPage->GetRadioButtons($aAllowedValues, $value, $this->iId, "{$sAttrFieldPrefix}{$sFieldName}", false /* $bMandatory will be placed manually */, $bVertical, $sValidationField); $aEventsList[] ='change'; break; @@ -168,7 +168,7 @@ class UIExtKeyWidget case 'list': default: $sSelectMode = 'true'; - + $sHelpText = ''; //$this->oAttDef->GetHelpOnEdition(); $sHTMLValue .= "
\n"; @@ -196,7 +196,7 @@ class UIExtKeyWidget { $key = $oObj->GetKey(); $display_value = $oObj->GetName(); - + if (($oAllowedValues->Count() == 1) && ($bMandatory == 'true') ) { // When there is only once choice, select it by default @@ -239,7 +239,7 @@ EOF { // Too many choices, use an autocomplete $sSelectMode = 'false'; - + // Check that the given value is allowed $oSearch = $oAllowedValues->GetFilter(); $oSearch->AddCondition('id', $value); @@ -259,15 +259,15 @@ EOF } $iMinChars = isset($aArgs['iMinChars']) ? $aArgs['iMinChars'] : 3; //@@@ $this->oAttDef->GetMinAutoCompleteChars(); $iFieldSize = isset($aArgs['iFieldSize']) ? $aArgs['iFieldSize'] : 20; //@@@ $this->oAttDef->GetMaxSize(); - + // the input for the auto-complete $sHTMLValue .= "Count()."\" type=\"text\" id=\"label_$this->iId\" value=\"$sDisplayValue\"/>"; $sHTMLValue .= "iId}\" style=\"border:0;vertical-align:middle;cursor:pointer;\" src=\"../images/mini_search.gif?itopversion=".ITOP_VERSION."\" onClick=\"oACWidget_{$this->iId}.Search();\"/>"; - + // another hidden input to store & pass the object's Id $sHTMLValue .= "iId\" name=\"{$sAttrFieldPrefix}{$sFieldName}\" value=\"".htmlentities($value, ENT_QUOTES, 'UTF-8')."\" />\n"; - $JSSearchMode = $this->bSearchMode ? 'true' : 'false'; + $JSSearchMode = $this->bSearchMode ? 'true' : 'false'; // Scripts to start the autocomplete and bind some events to it $oPage->add_ready_script( <<iId.'">'; @@ -342,7 +342,16 @@ EOF $oFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', $this->bSearchMode); $oBlock = new DisplayBlock($oFilter, 'search', false, $aParams); $sHTML .= $oBlock->GetDisplay($oPage, $this->iId, - array('open' => $bOpen, 'currentId' => $this->iId, 'table_id' => "dr_{$this->iId}", 'table_inner_id' => "{$this->iId}_results", 'selection_mode' => true, 'selection_type' => 'single', 'cssCount' => '#count_'.$this->iId)); + array( + 'menu' => false, + 'open' => $bOpen, + 'currentId' => $this->iId, + 'table_id' => "dr_{$this->iId}", + 'table_inner_id' => "{$this->iId}_results", + 'selection_mode' => true, + 'selection_type' => 'single', + 'cssCount' => '#count_'.$this->iId) + ); $sHTML .= "
iId}\" OnSubmit=\"return oACWidget_{$this->iId}.DoOk();\">\n"; $sHTML .= "
iId}\" style=\"vertical-align:top;background: #fff;height:100%;overflow:auto;padding:0;border:0;\">\n"; $sHTML .= "

".Dict::S('UI:Message:EmptyList:UseSearchForm')."

\n"; @@ -376,7 +385,7 @@ EOF { throw new Exception('Implementation: null value for allowed values definition'); } - + $oFilter = DBObjectSearch::FromOQL($sFilter); if (strlen($sRemoteClass) > 0) { @@ -390,7 +399,7 @@ EOF $oBlock = new DisplayBlock($oFilter, 'list', false, array('query_params' => array('this' => $oObj, 'current_extkey_id' => $iCurrentExtKeyId))); $oBlock->Display($oP, $this->iId.'_results', array('this' => $oObj, 'cssCount'=> '#count_'.$this->iId, 'menu' => false, 'selection_mode' => true, 'selection_type' => 'single', 'table_id' => 'select_'.$this->sAttCode)); // Don't display the 'Actions' menu on the results } - + /** * Search for objects to be selected * @param WebPage $oP The page used for the output (usually an AjaxWebPage) @@ -416,7 +425,7 @@ EOF $oP->add(trim($sFriendlyName)."\t".$sKey."\n"); } } - + /** * Get the display name of the selected object, to fill back the autocomplete */ @@ -506,7 +515,7 @@ EOF } } } - + // 3rd - set values from the page argument 'default' $oNewObj->UpdateObjectFromArg('default'); @@ -523,7 +532,7 @@ EOF $aFieldsComments[$sAttCode] = ' '; } } - cmdbAbstractObject::DisplayCreationForm($oPage, $this->sTargetClass, $oNewObj, array(), array('formPrefix' => $this->iId, 'noRelations' => true, 'fieldsFlags' => $aFieldsFlags, 'fieldsComments' => $aFieldsComments)); + cmdbAbstractObject::DisplayCreationForm($oPage, $this->sTargetClass, $oNewObj, array(), array('formPrefix' => $this->iId, 'noRelations' => true, 'fieldsFlags' => $aFieldsFlags, 'fieldsComments' => $aFieldsComments)); $oPage->add('
'); // $oPage->add_ready_script("\$('#ac_create_$this->iId').dialog({ width: $(window).width()*0.8, height: 'auto', autoOpen: false, modal: true, title: '$sDialogTitle'});\n"); $oPage->add_ready_script("\$('#ac_create_$this->iId').dialog({ width: 'auto', height: 'auto', maxHeight: $(window).height() - 50, autoOpen: false, modal: true, title: '$sDialogTitle'});\n"); @@ -567,7 +576,7 @@ EOF $oPage->add(''); $oPage->add("iId}\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"$('#dlg_tree_{$this->iId}').dialog('close');\">  "); $oPage->add("iId}\" value=\"".Dict::S('UI:Button:Ok')."\" onClick=\"oACWidget_{$this->iId}.DoHKOk();\">"); - + $oPage->add(''); $oPage->add_ready_script("\$('#tree_$this->iId ul').treeview();\n"); $oPage->add_ready_script("\$('#dlg_tree_$this->iId').dialog({ width: 'auto', height: 'auto', autoOpen: true, modal: true, title: '$sDialogTitle', resizeStop: oACWidget_{$this->iId}.OnHKResize, close: oACWidget_{$this->iId}.OnHKClose });\n"); @@ -589,7 +598,7 @@ EOF } else { - return array('error' => implode(' ', $aErrors), 'id' => 0); + return array('error' => implode(' ', $aErrors), 'id' => 0); } } catch(Exception $e) @@ -612,7 +621,7 @@ EOF $aTree[$iParentId][$oObj->GetKey()] = $oObj->GetName(); $aNodes[$oObj->GetKey()] = $oObj; } - + $aParents = array_keys($aTree); $aRoots = array(); foreach($aParents as $id) @@ -627,7 +636,7 @@ EOF $this->DumpNodes($oP, $iRootId, $aTree, $aNodes, $currValue); } } - + function DumpNodes($oP, $iRootId, $aTree, $aNodes, $currValue) { $bSelect = true; diff --git a/application/ui.linksdirectwidget.class.inc.php b/application/ui.linksdirectwidget.class.inc.php index ff2abafc5..499f6695f 100644 --- a/application/ui.linksdirectwidget.class.inc.php +++ b/application/ui.linksdirectwidget.class.inc.php @@ -305,7 +305,10 @@ class UILinksWidgetDirect $bOpen = MetaModel::GetConfig()->Get('legacy_search_drawer_open'); $oBlock = new DisplayBlock($oFilter, 'search', false); $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->sInputid}", - array('open' => $bOpen, 'table_id' => "SearchResultsToAdd_{$this->sInputid}")); + array( + 'open' => $bOpen, + 'table_id' => "SearchResultsToAdd_{$this->sInputid}") + ); $sHtml .= "sInputid}\">\n"; $sHtml .= "
sInputid}\" style=\"vertical-align:top;background: #fff;height:100%;overflow:auto;padding:0;border:0;\">\n"; $sHtml .= "

".Dict::S('UI:Message:EmptyList:UseSearchForm')."

\n"; diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php index acdf2c4b2..41dec06c0 100644 --- a/application/ui.linkswidget.class.inc.php +++ b/application/ui.linkswidget.class.inc.php @@ -401,6 +401,7 @@ EOF $oBlock = new DisplayBlock($oFilter, 'search', false); $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", array( + 'menu' => false, 'open' => $bOpen, 'table_id' => "SearchResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", 'table_inner_id' => "ResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", diff --git a/pages/ajax.searchform.php b/pages/ajax.searchform.php index 57d362573..ad2543132 100644 --- a/pages/ajax.searchform.php +++ b/pages/ajax.searchform.php @@ -57,19 +57,23 @@ try $sListParams = stripslashes(utils::ReadParam('list_params', '{}', false, 'raw_data')); $aListParams = json_decode($sListParams, true); - if (array_key_exists('currentId', $aListParams)) - { - $aExtraParams['currentId'] = $aListParams['currentId']; - } - if (array_key_exists('selection_mode', $aListParams)) - { - $aExtraParams['selection_mode'] = $aListParams['selection_mode']; - } - if (array_key_exists('selection_type', $aListParams)) - { - $aExtraParams['selection_type'] = $aListParams['selection_type']; - // In case of single selection, the root of the HTML identifiers used is suffixed with "_results" (at least in the external keys) - } + + $aPassFromExtraParamsToListParams = array( + 'currentId', + 'selection_mode', + 'selection_type',// In case of single selection, the root of the HTML identifiers used is suffixed with "_results" (at least in the external keys) + 'cssCount', + 'table_inner_id', + ); + foreach ($aPassFromExtraParamsToListParams as $passThroughKey) + { + if (array_key_exists($passThroughKey, $aListParams)) + { + $aExtraParams[$passThroughKey] = $aListParams[$passThroughKey]; + } + } + + if (array_key_exists('json', $aListParams)) { $aJson = $aListParams['json']; @@ -77,15 +81,14 @@ try $oWizardHelper = WizardHelper::FromJSON($sJson); $oObj = $oWizardHelper->GetTargetObject(); $aExtraParams['query_params'] = array('this' => $oObj); + + +// // Current extkey value, so we can display event if it is not available anymore (eg. archived). +// $iCurrentExtKeyId = (is_null($oObj)) ? 0 : $oObj->Get($this->sAttCode); +// $aExtraParams['current_extkey_id'] = $iCurrentExtKeyId; + } - if (array_key_exists('cssCount', $aListParams)) - { - $aExtraParams['cssCount'] = $aListParams['cssCount']; - } - if (array_key_exists('table_inner_id', $aListParams)) - { - $sListId = $aListParams['table_inner_id']; - } + $aExtraParams['display_limit'] = true; $aExtraParams['truncated'] = true;