From 849b185a4cb2ef4e44fc4921814011dfa7e5c97f Mon Sep 17 00:00:00 2001 From: zhaoke Date: Wed, 9 Aug 2023 16:55:10 +0800 Subject: [PATCH] * Fix errrors of search widget. --- lib/zin/wg/searchtoggle/v1.php | 4 +++- module/host/ui/browse.html.php | 2 +- module/search/control.php | 23 +++++++++++++++++++---- module/search/model.php | 13 +++++++------ module/search/ui/savezinquery.html.php | 4 ++-- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/zin/wg/searchtoggle/v1.php b/lib/zin/wg/searchtoggle/v1.php index 8bd65d2192..86c066062c 100644 --- a/lib/zin/wg/searchtoggle/v1.php +++ b/lib/zin/wg/searchtoggle/v1.php @@ -25,6 +25,8 @@ class searchToggle extends wg global $lang; $module = $this->prop('module'); $formName = $this->prop('formName'); + $open = $this->prop('open'); + if(is_null($open) && !empty($_GET['browseType'])) $open = $_GET['browseType'] === 'bySearch'; return btn ( set::class('ghost search-form-toggle'), @@ -33,7 +35,7 @@ class searchToggle extends wg set('data-module', $this->prop('module')), set('data-on', 'click'), set('data-do', "window.toggleSearchForm('$module', '$formName');"), - $this->prop('open') ? h::jsCall('~window.toggleSearchForm', $module, $formName, true) : null + $open ? h::jsCall('~window.toggleSearchForm', $module, $formName, true) : null ); } } diff --git a/module/host/ui/browse.html.php b/module/host/ui/browse.html.php index 469637d38b..0e14d2a0fb 100644 --- a/module/host/ui/browse.html.php +++ b/module/host/ui/browse.html.php @@ -21,7 +21,7 @@ $config->host->featureBar[0]['badge'] = $pager->recTotal != '' ? array('text' = featureBar ( set::items($config->host->featureBar), - li(searchToggle()) + li(searchToggle(set::open($browseType==='bySearch'))) ); /* zin: Define the toolbar on main menu. */ diff --git a/module/search/control.php b/module/search/control.php index bdbb9a7f9e..1924ffc331 100644 --- a/module/search/control.php +++ b/module/search/control.php @@ -151,7 +151,7 @@ class search extends control */ public function buildZinQuery() { - if(!commonModel::hasPriv('search', 'buildForm')) $this->loadModel('common')->deny('search', 'buildForm', false); + if(!commonModel::hasPriv('search', 'buildQuery')) $this->loadModel('common')->deny('search', 'buildQuery', false); $this->search->buildZinQuery(); @@ -210,12 +210,12 @@ class search extends control */ public function saveZinQuery($module, $onMenuBar = 'no') { - if(!commonModel::hasPriv('search', 'saveQuery')) $this->loadModel('common')->deny('search', 'buildForm', false); + if(!commonModel::hasPriv('search', 'saveQuery')) $this->loadModel('common')->deny('search', 'saveQuery', false); if($_POST) { $queryID = $this->search->saveZinQuery(); - if(!$queryID) return print(js::error(dao::getError())); + if(!$queryID) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $data = fixer::input('post')->get(); $shortcut = empty($data->onMenuBar) ? 0 : 1; @@ -225,7 +225,7 @@ class search extends control echo 'success'; return; } - return print(js::closeModal('parent.parent', '', "function(){parent.parent.loadQueries($queryID, $shortcut, '{$data->title}')}")); + return $this->send(array('closeModal' => true, 'callback' => '$(\'#searchFormPanel form button[type="submit"]\').trigger("click")')); } $this->view->module = $module; @@ -247,6 +247,21 @@ class search extends control echo 'success'; } + /** + * Delete current search query. + * + * @param int $queryID + * @access public + * @return void + */ + public function deleteZinQuery($queryID) + { + if(!commonModel::hasPriv('search', 'deleteQuery')) $this->loadModel('common')->deny('search', 'deleteQuery', false); + $this->search->deleteQuery($queryID); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + echo $this->send(array('result' => 'success', 'load' => true)); + } + /** * Ajax get search query. * diff --git a/module/search/model.php b/module/search/model.php index b38de753c1..33ef50deb8 100644 --- a/module/search/model.php +++ b/module/search/model.php @@ -289,6 +289,7 @@ class searchModel extends model /* Fix bug #2704. */ $field = $this->post->$fieldName; + if(empty($field)) continue; if(isset($fieldParams->$field) and $fieldParams->$field->control == 'input' and $this->post->$valueName === '0') $this->post->$valueName = 'ZERO'; if($field == 'id' and $this->post->$valueName === '0') $this->post->$valueName = 'ZERO'; $queryForm[$formIndex]['field'] = $field; @@ -1852,7 +1853,7 @@ class searchModel extends model 'data-toggle' => 'modal', 'data-type' => 'ajax', 'data-data-type' => 'html', - 'data-url' => helper::createLink('search', 'saveQuery', array('module' => $module)), + 'data-url' => helper::createLink('search', 'saveZinQuery', array('module' => $module)), ); return $result; @@ -1866,21 +1867,21 @@ class searchModel extends model * @access public * @return array */ - public static function buildFormSavedQuery($queries, $account) + public static function buildFormSavedQuery($queries, $actionURL) { $result = array(); if(empty($queries)) return $result; + global $lang; $hasPriv = common::hasPriv('search', 'deleteQuery'); foreach($queries as $query) { if(!is_object($query)) continue; $item = new stdClass(); - $item->id = $query->id; - $item->title = $query->title; - $item->account = $query->account; - $item->hasPriv = ($hasPriv && $account == $query->account); + $item->text = $query->title; + $item->applyURL = str_replace('myQueryID', $query->id, $actionURL); + if($hasPriv) $item->deleteProps = array('className' => 'ajax-submit', 'data-confirm' => $lang->search->confirmDelete, 'href' => helper::createLink('search', 'deleteZinQuery', "queryID={$query->id}")); $result[] = $item; } diff --git a/module/search/ui/savezinquery.html.php b/module/search/ui/savezinquery.html.php index d6714e4742..de0f9f173e 100644 --- a/module/search/ui/savezinquery.html.php +++ b/module/search/ui/savezinquery.html.php @@ -3,7 +3,7 @@ namespace zin; form ( - set::actions(null), + set::actions(array()), set::action($_SERVER['REQUEST_URI']), set::method('post'), div @@ -34,7 +34,7 @@ form ), btn( setClass('w-1/12 primary'), - set::type('submit'), + set::btnType('submit'), set('data-type', 'submit'), $lang->save ),