|
|
@@ -12,10 +12,15 @@ require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
|
|
|
class BxBaseSearch extends BxDolSearch
|
|
|
{
|
|
|
protected $_oTemplate;
|
|
|
+
|
|
|
protected $_sIdForm = 'sys_search_form';
|
|
|
protected $_sIdResults = 'sys_search_results';
|
|
|
+ protected $_sIdLoading;
|
|
|
protected $_sSuffixLiveSearch = '_quick';
|
|
|
|
|
|
+ protected $_iSearchLenth;
|
|
|
+ protected $_sSearchFunctionParams;
|
|
|
+
|
|
|
public function __construct($aChoice, $oTemplate)
|
|
|
{
|
|
|
if (!is_array($aChoice) && $aChoice != '')
|
|
|
@@ -23,6 +28,22 @@ class BxBaseSearch extends BxDolSearch
|
|
|
parent::__construct($aChoice);
|
|
|
|
|
|
$this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
|
|
|
+
|
|
|
+ $this->_sIdLoading = $this->_sIdForm;
|
|
|
+
|
|
|
+ $this->_iSearchLenth = 5;
|
|
|
+ $this->_sSearchFunctionParams = "%d, '%s', '%s', '%s', %d, %d";
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setLiveSearch($bLiveSearch)
|
|
|
+ {
|
|
|
+ parent::setLiveSearch($bLiveSearch);
|
|
|
+
|
|
|
+ if($this->_bLiveSearch) {
|
|
|
+ $this->_sIdForm .= $this->_sSuffixLiveSearch;
|
|
|
+ $this->_sIdResults .= $this->_sSuffixLiveSearch;
|
|
|
+ $this->_sIdLoading = $this->_sIdResults;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function getForm($iDesignBoxTemplate = BX_DB_PADDING_DEF, $sTitle = false, $bOnlyForm = false)
|
|
|
@@ -33,30 +54,51 @@ class BxBaseSearch extends BxDolSearch
|
|
|
if (false === $sTitle)
|
|
|
$sTitle = _t( "_Search");
|
|
|
|
|
|
- $aValues = array_merge(array('' => _t('_search_in_all_section')), $this->getKeyTitlesPairs());
|
|
|
+ $aSection = '';
|
|
|
if (bx_get('type'))
|
|
|
- $aValue = bx_process_input(bx_get('type'));
|
|
|
- elseif (bx_get('section'))
|
|
|
- $aValue = bx_process_input(bx_get('section'));
|
|
|
- else
|
|
|
- $aValue = '';
|
|
|
-
|
|
|
-
|
|
|
- $sIdForm = $this->_sIdForm;
|
|
|
- $sIdResults = $this->_sIdResults;
|
|
|
- $sIdLoadingContainer = $sIdForm;
|
|
|
- $iKeywordMinLenth = 0;
|
|
|
- if($this->_bLiveSearch) {
|
|
|
- $sIdForm .= $this->_sSuffixLiveSearch;
|
|
|
- $sIdResults .= $this->_sSuffixLiveSearch;
|
|
|
- $sIdLoadingContainer = $sIdResults;
|
|
|
- $iKeywordMinLenth = (int)getParam('sys_search_keyword_min_len');
|
|
|
+ $aSection = bx_process_input(bx_get('type'));
|
|
|
+ else if (bx_get('section'))
|
|
|
+ $aSection = bx_process_input(bx_get('section'));
|
|
|
+
|
|
|
+ $aForm = $this->_getForm([
|
|
|
+ 'section' => $aSection,
|
|
|
+ 'keyword' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : ''
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $oForm = new BxTemplFormView($aForm);
|
|
|
+ $sForm = $oForm->getCode();
|
|
|
+
|
|
|
+ if (!$this->_bLiveSearch) {
|
|
|
+ $o = new BxTemplPaginate(array());
|
|
|
+ $o->addCssJs();
|
|
|
}
|
|
|
- $sJsParams = "5, '#{$sIdForm}', '#{$sIdResults}', '#{$sIdLoadingContainer}', '{$this->_bLiveSearch}', {$iKeywordMinLenth}";
|
|
|
+ if ($bOnlyForm)
|
|
|
+ return $sForm;
|
|
|
|
|
|
+ return $this->_oTemplate->parseHtmlByName('designbox_container.html', array(
|
|
|
+ 'class_add' => '',
|
|
|
+ 'bx_if:show_html_id' => array(
|
|
|
+ 'condition' => false,
|
|
|
+ 'content' => array(),
|
|
|
+ ),
|
|
|
+ 'content' => DesignBoxContent($sTitle, $sForm, $iDesignBoxTemplate)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getResultsContainer($sCode = '')
|
|
|
+ {
|
|
|
+ return $this->_oTemplate->parseHtmlByName('search_result.html', [
|
|
|
+ 'html_id' => $this->_sIdResults,
|
|
|
+ 'class' => str_replace('_', '-', $this->_sIdResults),
|
|
|
+ 'content' => $sCode
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function _getForm($aValues = array())
|
|
|
+ {
|
|
|
$aForm = array(
|
|
|
'form_attrs' => array(
|
|
|
- 'id' => $sIdForm,
|
|
|
+ 'id' => $this->_sIdForm,
|
|
|
'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
|
|
|
'method' => 'post',
|
|
|
),
|
|
|
@@ -75,14 +117,14 @@ class BxBaseSearch extends BxDolSearch
|
|
|
'type' => 'select',
|
|
|
'name' => 'section',
|
|
|
'caption' => _t('_Section'),
|
|
|
- 'values' => $aValues,
|
|
|
- 'value' => $aValue,
|
|
|
+ 'values' => array_merge(array('' => _t('_search_in_all_section')), $this->getKeyTitlesPairs()),
|
|
|
+ 'value' => $aValues['section'],
|
|
|
),
|
|
|
'keyword' => array(
|
|
|
'type' => 'text',
|
|
|
'name' => 'keyword',
|
|
|
'caption' => _t('_Keyword'),
|
|
|
- 'value' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : '',
|
|
|
+ 'value' => $aValues['keyword'],
|
|
|
),
|
|
|
'search' => array(
|
|
|
'type' => 'submit',
|
|
|
@@ -93,6 +135,8 @@ class BxBaseSearch extends BxDolSearch
|
|
|
);
|
|
|
|
|
|
if ($this->_bLiveSearch) {
|
|
|
+ $sJsParams = sprintf($this->_sSearchFunctionParams, $this->_iSearchLenth, '#' . $this->_sIdForm, '#' . $this->_sIdResults, '#' . $this->_sIdLoading, $this->_bLiveSearch, (int)getParam('sys_search_keyword_min_len'));
|
|
|
+
|
|
|
unset($aForm['inputs']['section']);
|
|
|
unset($aForm['inputs']['search']);
|
|
|
unset($aForm['inputs']['keyword']['caption']);
|
|
|
@@ -101,32 +145,9 @@ class BxBaseSearch extends BxDolSearch
|
|
|
$aForm['inputs']['keyword']['attrs']['onpaste'] = $aForm['inputs']['keyword']['attrs']['onkeydown'];
|
|
|
}
|
|
|
|
|
|
- $oForm = new BxTemplFormView($aForm);
|
|
|
- $sForm = $oForm->getCode();
|
|
|
-
|
|
|
- if (!$this->_bLiveSearch) {
|
|
|
- $o = new BxTemplPaginate(array());
|
|
|
- $o->addCssJs();
|
|
|
- }
|
|
|
- if ($bOnlyForm)
|
|
|
- return $sForm;
|
|
|
-
|
|
|
- return $this->_oTemplate->parseHtmlByName('designbox_container.html', array(
|
|
|
- 'class_add' => '',
|
|
|
- 'bx_if:show_html_id' => array(
|
|
|
- 'condition' => false,
|
|
|
- 'content' => array(),
|
|
|
- ),
|
|
|
- 'content' => DesignBoxContent($sTitle, $sForm, $iDesignBoxTemplate)
|
|
|
- ));
|
|
|
- }
|
|
|
-
|
|
|
- public function getResultsContainer($sCode = '')
|
|
|
- {
|
|
|
- $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
|
|
|
- return '<div id="' . $sIdResults . '">' . $sCode . '</div>';
|
|
|
+ return $aForm;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected function getKeyTitlesPairs ()
|
|
|
{
|
|
|
$a = array();
|