From b3d625b9fc10142c853eea561595d7e34092a965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Espi=C3=A9?= Date: Tue, 13 Mar 2018 08:11:01 +0000 Subject: [PATCH] Advanced Search SVN:b1162[5408] --- application/datatable.class.inc.php | 27 ---------------- application/ui.extkeywidget.class.inc.php | 2 +- application/ui.linkswidget.class.inc.php | 16 ++++++++-- pages/ajax.render.php | 2 +- pages/ajax.searchform.php | 32 +++++++++++++++++-- .../search/searchform.class.inc.php | 21 +++++++++++- 6 files changed, 66 insertions(+), 34 deletions(-) diff --git a/application/datatable.class.inc.php b/application/datatable.class.inc.php index 672cc40b2..86f13aada 100644 --- a/application/datatable.class.inc.php +++ b/application/datatable.class.inc.php @@ -571,33 +571,6 @@ EOF { $oPage->add_ready_script("oTable.trigger(\"fakesorton\", [$sFakeSortList]);"); } - //if ($iNbPages == 1) - if (false) - { - if (isset($aExtraParams['cssCount'])) - { - $sCssCount = $aExtraParams['cssCount']; - if ($sSelectMode == 'single') - { - $sSelectSelector = ":radio[name^=selectObj]"; - } - else if ($sSelectMode == 'multiple') - { - $sSelectSelector = ":checkbox[name^=selectObj]"; - } - $oPage->add_ready_script( -<<iListId} table.listResults $sSelectSelector').change(function() { - var c = $('{$sCssCount}'); - var v = $('#{$this->iListId} table.listResults $sSelectSelector:checked').length; - c.val(v); - $('#{$this->iListId} .selectedCount').text(v); - c.trigger('change'); - }); -EOF - ); - } - } return $sHtml; } diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php index 6a430e599..f260b7cd4 100644 --- a/application/ui.extkeywidget.class.inc.php +++ b/application/ui.extkeywidget.class.inc.php @@ -342,7 +342,7 @@ 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}", 'selection_mode' => true, 'selection_type' => 'single')); + 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)); $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"; diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php index 9295c919b..acdf2c4b2 100644 --- a/application/ui.linkswidget.class.inc.php +++ b/application/ui.linkswidget.class.inc.php @@ -386,8 +386,13 @@ EOF /** * @param WebPage $oPage * @param DBObject $oCurrentObj + * @param $sJson + * + * @throws \CoreException + * @throws \DictExceptionMissingString + * @throws \Exception */ - public function GetObjectPickerDialog($oPage, $oCurrentObj) + public function GetObjectPickerDialog($oPage, $oCurrentObj, $sJson) { $bOpen = MetaModel::GetConfig()->Get('legacy_search_drawer_open'); $sHtml = "
\n"; @@ -395,7 +400,14 @@ EOF $this->SetSearchDefaultFromContext($oCurrentObj, $oFilter); $oBlock = new DisplayBlock($oFilter, 'search', false); $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", - array('open' => $bOpen, 'table_id' => "SearchResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", 'selection_mode' => true)); + array( + 'open' => $bOpen, + 'table_id' => "SearchResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", + 'table_inner_id' => "ResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", + 'selection_mode' => true, + 'json' => $sJson, + 'cssCount' => '#count_'.$this->m_sAttCode.$this->m_sNameSuffix + )); $sHtml .= "m_sAttCode}{$this->m_sNameSuffix}\" OnSubmit=\"return oWidget{$this->m_iInputId}.DoAddObjects(this.id);\">\n"; $sHtml .= "
m_sAttCode}{$this->m_sNameSuffix}\" 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/pages/ajax.render.php b/pages/ajax.render.php index 663f7bd39..d27d54949 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -269,7 +269,7 @@ try $oObj = null; } $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates); - $oWidget->GetObjectPickerDialog($oPage, $oObj); + $oWidget->GetObjectPickerDialog($oPage, $oObj, $sJson); break; // ui.linkswidget diff --git a/pages/ajax.searchform.php b/pages/ajax.searchform.php index 96253c3a1..d7624e40c 100644 --- a/pages/ajax.searchform.php +++ b/pages/ajax.searchform.php @@ -31,6 +31,7 @@ require_once(APPROOT.'/application/user.preferences.class.inc.php'); require_once(APPROOT.'/application/loginwebpage.class.inc.php'); require_once(APPROOT.'/sources/application/search/ajaxsearchexception.class.inc.php'); require_once(APPROOT.'/sources/application/search/criterionparser.class.inc.php'); +require_once(APPROOT.'/application/wizardhelper.class.inc.php'); try { @@ -56,6 +57,10 @@ 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']; @@ -63,12 +68,35 @@ try 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) + } + if (array_key_exists('json', $aListParams)) + { + $aJson = $aListParams['json']; + $sJson = json_encode($aJson); + $oWizardHelper = WizardHelper::FromJSON($sJson); + $oObj = $oWizardHelper->GetTargetObject(); + $aExtraParams['query_params'] = array('this' => $oObj); + } + 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; - $aExtraParams['currentId'] = uniqid('ajax-search-form'); - $oDisplayBlock->RenderContent($oPage, $aExtraParams); + if (isset($sListId)) + { + $oDisplayBlock->Display($oPage, $sListId, $aExtraParams); + } + else + { + $oDisplayBlock->RenderContent($oPage, $aExtraParams); + } $oPage->output(); diff --git a/sources/application/search/searchform.class.inc.php b/sources/application/search/searchform.class.inc.php index 689e2d449..0c9ed9776 100644 --- a/sources/application/search/searchform.class.inc.php +++ b/sources/application/search/searchform.class.inc.php @@ -53,17 +53,20 @@ class SearchForm $sHtml = ''; $oAppContext = new ApplicationContext(); $sClassName = $oSet->GetFilter()->GetClass(); + $aListParams = array(); // Simple search form if (isset($aExtraParams['currentId'])) { $sSearchFormId = $aExtraParams['currentId']; + $aListParams['currentId'] = $aExtraParams['currentId']; } else { $iSearchFormId = $oPage->GetUniqueId(); $sSearchFormId = 'SimpleSearchForm'.$iSearchFormId; $sHtml .= "
\n"; + $aListParams['currentId'] = "$iSearchFormId"; } // Check if the current class has some sub-classes if (isset($aExtraParams['baseClass'])) @@ -74,7 +77,6 @@ class SearchForm { $sRootClass = $sClassName; } - $aListParams = array(); if (array_key_exists('selection_mode', $aExtraParams)) { $aListParams['selection_mode'] = $aExtraParams['selection_mode']; @@ -84,6 +86,18 @@ class SearchForm $aListParams['selection_type'] = $aExtraParams['selection_type']; } + $sJson = stripslashes(utils::ReadParam('json', '', false, 'raw_data')); + if (!empty($sJson)) + { + $aListParams['json'] = json_decode($sJson, true); + } + + + if (array_key_exists('cssCount', $aExtraParams)) + { + $aListParams['cssCount'] = $aExtraParams['cssCount']; + } + $aSubClasses = MetaModel::GetSubclasses($sRootClass); if (count($aSubClasses) > 0) { @@ -126,6 +140,11 @@ class SearchForm $aExtraParams['table_id'] = "search_form_result_{$sSearchFormId}"; $sHtml .= "
\n"; } + $aListParams['table_id'] = $aExtraParams['table_id']; + if (array_key_exists('table_inner_id', $aExtraParams)) + { + $aListParams['table_inner_id'] = $aExtraParams['table_inner_id']; + } $aSearchParams = array( 'criterion_outer_selector' => "#fs_{$sSearchFormId}_criterion_outer", 'result_list_outer_selector' => "#{$aExtraParams['table_id']}",