add batch operation to add/remove category

This commit is contained in:
Uwe Steinmann 2022-09-14 18:08:34 +02:00
parent 100b0bfa26
commit 3283d35db8
2 changed files with 87 additions and 6 deletions

View File

@ -58,6 +58,15 @@ if (isset($_GET["newowner"]) && is_numeric($_GET["newowner"]) && $_GET['newowner
$newowner = $dms->getUser((int) $_GET['newowner']);
}
$changecategory = null;
if (isset($_GET["changecategory"]) && is_numeric($_GET["changecategory"]) && $_GET['changecategory'] > 0) {
$changecategory = $dms->getDocumentCategory((int) $_GET['changecategory']);
}
$removecategory = 0;
if (isset($_GET["removecategory"]) && is_numeric($_GET["removecategory"]) && $_GET['removecategory'] > 0) {
$removecategory = (int) $_GET['removecategory'];
}
$fullsearch = ((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext') || !empty($_GET["fullsearch"])) && $settings->_enableFullSearch;
if($fullsearch) {
// Search in Fulltext {{{
@ -561,6 +570,8 @@ if($settings->_showSingleSearchHit && count($entries) == 1) {
$view->setParam('includecontent', $includecontent);
$view->setParam('marks', isset($_GET['marks']) ? $_GET['marks'] : array());
$view->setParam('newowner', $newowner);
$view->setParam('changecategory', $changecategory);
$view->setParam('removecategory', $removecategory);
$view->setParam('searchhits', $entries);
$view->setParam('totalpages', $totalPages);
$view->setParam('pagenumber', $pageNumber);

View File

@ -67,7 +67,6 @@ $(document).ready( function() {
var inputs = $('input[name^=\"marks\"]');
var values = {};
inputs.each(function() {
console.log(this.name+'='+this.checked);
if(this.checked)
values[this.name] = 1;
});
@ -75,22 +74,20 @@ $(document).ready( function() {
window.location.href = url;
});
/*
$('#changeowner').on('click', function(e) {
$('#changecategory').on('click', function(e) {
e.preventDefault();
var url = "";
url = $(this).attr('href')+'&newowner='+($('#newowner').val());
url = $(this).attr('href')+'&changecategory='+$('#batchcategory').val()+'&removecategory='+($('#removecategory').prop('checked') ? '1' : '0');
var inputs = $('input[name^=\"marks\"]');
var values = {};
inputs.each(function() {
console.log(this.name+'='+this.checked);
if(this.checked)
values[this.name] = 1;
});
url += '&'+$.param(values);
window.location.href = url;
});
*/
<?php if($this->getParam('theme') !== 'bootstrap4'): ?>
$('body').on('click', 'a.change-owner-btn', function(ev){
ev.preventDefault();
@ -292,6 +289,44 @@ $(document).ready(function() {
return self::show();
} /* }}} */
function changecategory() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$entries = $this->params['searchhits'];
$changecategory = $this->params['changecategory'];
$removecategory = $this->params['removecategory'];
$marks = $this->params['marks'];
if($changecategory && $user->isAdmin()) {
$j = $i = 0;
foreach($entries as $entry) {
if($entry->isType('document')) {
if(empty($marks) || !empty($marks['D'.$entry->getId()])) {
if(!$removecategory) {
if(!$entry->hasCategory($changecategory)) {
$entry->addCategories([$changecategory]);
$j++;
}
} else {
if($entry->hasCategory($changecategory)) {
$entry->removeCategories([$changecategory]);
$j++;
}
}
}
}
}
if($removecategory) {
$this->setParam('batchmsg', getMLText('batch_remove_category_msg', ['count'=>$j, 'catname'=>$changecategory->getName()]));
} else {
$this->setParam('batchmsg', getMLText('batch_add_category_msg', ['count'=>$j, 'catname'=>$changecategory->getName()]));
}
} else {
}
return self::show();
} /* }}} */
function opensearchsuggestion() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
@ -911,6 +946,41 @@ function typeahead() { /* {{{ */
$content = ob_get_clean();
$this->printAccordion(getMLText('batch_change_owner'), $content);
ob_start();
$cats = $dms->getDocumentCategories();
$options = array();
$options[] = array("-1", getMLText("choose_category"));
foreach ($cats as $currcat) {
$options[] = array($currcat->getID(), htmlspecialchars($currcat->getName()), false);
}
$this->formField(
null,
array(
'element'=>'select',
'id'=>'batchcategory',
'class'=>'chzn-select',
'options'=>$options,
'multiple'=>false,
'placeholder'=>getMLText('select_category'),
'attributes'=>array(array('style', 'width: 100%;'))
)
);
$this->formField(
getMLText("batch_remove_category"),
array(
'element'=>'input',
'type'=>'checkbox',
'id'=>'removecategory',
'value'=>'1',
)
);
// print $this->html_link('Search', array_merge($_GET, array('action'=>'changeowner')), array('class'=>'btn btn-primary', 'id'=>'changeowner'), "<i class=\"fa fa-user\"></i> ".getMLText("batch_change_owner"), false, true)."\n";
print $this->html_link('Search', array_merge($_GET, array('action'=>'changecategory')), array('class'=>'btn btn-primary change-category-btn mt-4', 'id'=>'changecategory'), "<i class=\"fa fa-user\"></i> ".getMLText("batch_change_category"), false, true)."\n";
$content = ob_get_clean();
$this->printAccordion(getMLText('batch_change_category'), $content);
}
// }}}