Merge branch 'seeddms-5.1.x' into seeddms-6.0.x

This commit is contained in:
Uwe Steinmann 2024-11-01 17:49:44 +01:00
commit 36acb63ebe
8 changed files with 178 additions and 62 deletions

View File

@ -74,6 +74,13 @@ module.exports = function (grunt) {
],
dest: bootstrapDir + '/select2/js',
flatten: true
},{
expand: true,
src: [
nodeDir + '/select2/dist/js/i18n/*'
],
dest: bootstrapDir + '/select2/js/i18n',
flatten: true
},{
expand: true,
src: [

View File

@ -133,29 +133,45 @@ switch($command) {
}
break; /* }}} */
/* Used for folder chooser */
/* This is used for searching folders in the folder selectors
* 1. the selector also having a tree
* 2. the selector based on select2 for <select class="chzn-select-folder" ...>
* $format is set to 'select2' in the second case.
*/
case 'searchfolder': /* {{{ */
if($user) {
$query = $_GET['query'];
$format = $_GET['format'] ?? '';
$query = $_GET['query'] ?? '';
if(!$query) {
header('Content-Type: application/json');
if($format == 'select2')
echo json_encode(['results'=>[]]);
else
echo json_encode([]);
return;
}
if(false !== ($pos = strpos($query, '/'))) {
$subquery = substr($query, 0, $pos);
$hits = $dms->search($subquery, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(), $startFolder=$dms->getRootFolder(), $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
$hits = $dms->search($subquery, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(2), $startFolder=$dms->getRootFolder(), $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
if($hits) {
if(count($hits['folders']) == 1) {
$hit = $hits['folders'][0];
$basefolder = $dms->getFolder($hit->getID());
if($basefolder->getAccessMode($user, 'search') >= M_READ) {
if($subquery = substr($query, $pos+1)) {
$hits = $dms->search($subquery, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(), $startFolder=$basefolder, $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
$hits = $dms->search($subquery, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(2), $startFolder=$basefolder, $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
if($hits) {
$result = array();
foreach($hits['folders'] as $hit) {
if($hit->getAccessMode($user, 'search') >= M_READ)
// $result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getName()), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
if($format == 'select2')
echo json_encode(['results'=>$result]);
else
echo json_encode($result);
return;
}
@ -166,9 +182,12 @@ switch($command) {
foreach($subfolders as $subfolder) {
//$result[] = $subfolder->getID().'#'.$basefolder->getName().'/'.$subfolder->getName();
// $result[] = $subfolder->getID().'#'.$subfolder->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$subfolder->getId(), 'name'=>htmlspecialchars($subfolder->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($subfolder->getParent()->getFolderPathPlain(true, '/')));
$result[] = array('type'=>'F', 'id'=>$subfolder->getId(), 'name'=>htmlspecialchars($subfolder->getName()), 'path'=>htmlspecialchars($subfolder->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
if($format == 'select2')
echo json_encode(['results'=>$result]);
else
echo json_encode($result);
return;
}
@ -182,9 +201,12 @@ switch($command) {
foreach($hits['folders'] as $hit) {
if($hit->getAccessMode($user, 'search') >= M_READ)
// $result[] = $hit->getID().'#'.$hit->getFolderPathPlain(true, '/');
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getFolderPathPlain(true, '/')), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
$result[] = array('type'=>'F', 'id'=>$hit->getId(), 'name'=>htmlspecialchars($hit->getName()), 'path'=>htmlspecialchars($hit->getParent()->getFolderPathPlain(true, '/')));
}
header('Content-Type: application/json');
if($format == 'select2')
echo json_encode(['results'=>$result]);
else
echo json_encode($result);
}
}

View File

@ -101,9 +101,11 @@ class SeedDMS_Theme_Style extends SeedDMS_View_Common {
echo "<!DOCTYPE html>\n";
echo "<html lang=\"";
if(!empty($this->params['session']) && ($slang = $this->params['session']->getLanguage())) {
echo str_replace('_', '-', $slang);
echo substr($slang, 0, 2);
// echo str_replace('_', '-', $slang);
} else {
echo str_replace('_', '-', $this->params['settings']->_language);
echo substr($this->params['settings']->_language, 0, 2);
// echo str_replace('_', '-', $this->params['settings']->_language);
}
echo "\">\n<head>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
@ -213,7 +215,7 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
$this->addFooterJS('SeedDMSTask.run();');
}
if($this->params['enabledropfolderlist'] && isset($this->params['user']) && $this->params['user']) {
$this->addFooterJS("SeedDMSTask.add({name: 'dropfolder', interval: 30, func: function(){\$('#menu-dropfolder > div.ajax').trigger('update', {folderid: seeddms_folder});}});");
$this->addFooterJS("SeedDMSTask.add({name: 'dropfolder', interval: 30, func: function(){\$('#menu-dropfolder > div.ajax').trigger('update', {folderid: seeddms_folder, noinit: true});}});");
}
if($this->footerjs) {
$jscode = "$(document).ready(function () {\n";

View File

@ -803,6 +803,19 @@ if(($kkk = $this->callHook('getFullSearchEngine')) && is_array($kkk))
case "folders":
$this->formField(null, $this->getFolderChooserHtml("form".$extname.$confkey, M_READ, -1, $selections ? $dms->getFolder($selections[0]) : 0, 'extensions['.$extname."][".$confkey."]"));
break;
case "folderlist":
echo "<select class=\"chzn-select-folder\"".($allowempty ? " data-allow-clear=\"true\"" : "")." name=\"extensions[".$extname."][".$confkey."][]\"".(!empty($conf['multiple']) ? " multiple" : "").(!empty($conf['size']) ? " size=\"".$conf['size']."\"" : "")." data-placeholder=\"".getMLText("select_attribute_value")."\" style=\"width: 100%;\">";
if($selections) {
foreach ($selections as $selid) {
if ($f = $dms->getFolder($selid)) {
echo "<option value=\"".$f->getID()."\"";
echo " selected";
echo ">".htmlspecialchars($f->getName())."</option>";
}
}
}
echo "</select>";
break;
case "documents":
$this->formField(null, $this->getDocumentChooserHtml("form".$extname.$confkey, M_READ, -1, $selections ? $dms->getDocument($selections[0]) : 0, 'extensions['.$extname."][".$confkey."]"));
break;

View File

@ -4,8 +4,10 @@
* will receive an unescaped string
* (see https://forums.select2.org/t/propperly-escape-option-value-to-prevent-xss/788)
*/
chzn_template_func = function (state) {
chzn_template_func = function (state) { /* {{{ */
var subtitle = '';
if(state.subtitle)
subtitle = state.subtitle;
if($(state.element).data('subtitle'))
subtitle = $(state.element).data('subtitle')+''; /* make sure it is a string */
var warning = '';
@ -24,9 +26,9 @@ chzn_template_func = function (state) {
html += '</span>';
var $newstate = $(html);
return $newstate;
};
}; /* }}} */
function escapeHtml(text) {
function escapeHtml(text) { /* {{{ */
var map = {
'&': '&amp;',
'<': '&lt;',
@ -36,7 +38,7 @@ function escapeHtml(text) {
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
} /* }}} */
/**
* Format bytes as human-readable text.
@ -48,7 +50,7 @@ function escapeHtml(text) {
*
* @return Formatted string.
*/
function formatFileSize(bytes, si=false, dp=1) {
function formatFileSize(bytes, si=false, dp=1) { /* {{{ */
const thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
@ -68,7 +70,7 @@ function formatFileSize(bytes, si=false, dp=1) {
return bytes.toFixed(dp) + ' ' + units[u];
}
} /* }}} */
function treeFolderSelected(formid, nodeid, nodename) {
$('#'+formid).val(nodeid);
@ -82,7 +84,7 @@ function treeDocumentSelected(formid, nodeid, nodename) {
$('#docChooser'+formid).modal('hide');
}
function initMost() {
function initMost() { /* {{{ */
$('.datepicker, #expirationdate, #createstartdate, #createenddate, #expirationstartdate, #expirationenddate')
.datepicker({todayHighlight: true, toggleActive: true})
.on('changeDate', function(ev){
@ -92,11 +94,37 @@ function initMost() {
$(ev.currentTarget).datepicker('hide');
});
$(".chzn-select").select2({
$(".chzn-select").select2({ /* {{{ */
width: '100%',
templateResult: chzn_template_func//,
//templateSelection: chzn_template_func
});
templateResult: chzn_template_func
}); /* }}} */
$(".chzn-select-folder").select2({ /* {{{ */
theme: "bootstrap4",
width: 'resolve',
debug: false,
ajax: {
url: seeddms_webroot+"op/op.Ajax.php",
delay: 500,
data: function (params) {
var query = {
query: params.term,
command: 'searchfolder',
format: 'select2'
}
// Query parameters will be ?search=[term]&command=folderlist
return query;
},
processResults: function(data) {
$.map(data.results, function (obj) {obj.text = obj.name || obj.text; obj.subtitle = obj.path || obj.subtitle; return obj; });
return {
results: data.results
};
},
dataType: 'json'
},
templateResult: chzn_template_func
}); /* }}} */
/* change the color and length of the bar graph showing the password
* strength on each change to the passwod field.
@ -307,26 +335,27 @@ function initMost() {
return this
}
}); /* }}} */
}
} /* }}} */
$(document).ready( function() {
/* close popovers when clicking somewhere except in the popover or the
* remove icon
*/
$('html').on('click', function(e) {
$('html').on('click', function(e) { /* {{{ */
if (typeof $(e.target).data('original-title') == 'undefined' && !$(e.target).parents().is('.popover.in') && !$(e.target).is('.fa fa-remove')) {
$('[data-original-title]').popover('hide');
}
});
}); /* }}} */
$('body').on('hidden', '.modal', function () {
$('body').on('hidden', '.modal', function () { /* {{{ */
$(this).removeData('modal');
});
$('body').on('click', '[data-toggle="modal"]', function(ev){
}); /* }}} */
$('body').on('click', '[data-toggle="modal"]', function(ev){ /* {{{ */
/* Also set the title */
if($(this).data("modal-title"))
$($(this).data("target")+' .modal-header h3').html($(this).data("modal-title"));
});
}); /* }}} */
$('body').on('touchstart.dropdown', '.dropdown-menu', function (e) { e.stopPropagation(); });
@ -584,6 +613,7 @@ $(document).ready( function() {
var query = element.data('query');
var afterload = $(this).data('afterload');
var updatemsg = element.data('update-msg');
var runinit = true;
if(view && action) {
url = seeddms_webroot+base+"out/out."+view+".php?action="+action;
if(query) {
@ -595,6 +625,8 @@ $(document).ready( function() {
for(var key in param1) {
if(key == 'callback')
callback = param1[key];
else if(key == 'noinit')
runinit = !param1[key];
else {
if($.isArray(param1[key])) {
if(param1[key].length > 0)
@ -621,7 +653,9 @@ $(document).ready( function() {
func();
}
}
if(runinit) {
initMost();
}
SeedDMSAjax.run(view, action);
});
}); /* }}} */

View File

@ -103,9 +103,11 @@ class SeedDMS_Theme_Style extends SeedDMS_View_Common {
echo "<!DOCTYPE html>\n";
echo "<html lang=\"";
if(!empty($this->params['session']) && ($slang = $this->params['session']->getLanguage())) {
echo str_replace('_', '-', $slang);
echo substr($slang, 0, 2);
// echo str_replace('_', '-', $slang);
} else {
echo str_replace('_', '-', $this->params['settings']->_language);
echo substr($this->params['settings']->_language, 0, 2);
// echo str_replace('_', '-', $this->params['settings']->_language);
}
echo "\">\n<head>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
@ -218,7 +220,7 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
$this->addFooterJS('SeedDMSTask.run();');
}
if($this->params['enabledropfolderlist'] && isset($this->params['user']) && $this->params['user']) {
$this->addFooterJS("SeedDMSTask.add({name: 'dropfolder', interval: 30, func: function(){\$('#menu-dropfolder > div.ajax').trigger('update', {folderid: seeddms_folder});}});");
$this->addFooterJS("SeedDMSTask.add({name: 'dropfolder', interval: 30, func: function(){\$('#menu-dropfolder > div.ajax').trigger('update', {folderid: seeddms_folder, noinit: true});}});");
}
if($this->footerjs) {
$jscode = "$(document).ready(function () {\n";

View File

@ -278,6 +278,9 @@ a.accordion2-toggle:focus, a.accordion2-toggle:hover {
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice {
border-radius: 0px;
}
.select2-results__option span i {
font-size: 80%;
}
.datepicker {
border-radius: 0px;
}

View File

@ -4,8 +4,10 @@
* will receive an unescaped string
* (see https://forums.select2.org/t/propperly-escape-option-value-to-prevent-xss/788)
*/
chzn_template_func = function (state) {
chzn_template_func = function (state) { /* {{{ */
var subtitle = '';
if(state.subtitle)
subtitle = state.subtitle;
if($(state.element).data('subtitle'))
subtitle = $(state.element).data('subtitle')+''; /* make sure it is a string */
var warning = '';
@ -24,9 +26,9 @@ chzn_template_func = function (state) {
html += '</span>';
var $newstate = $(html);
return $newstate;
};
}; /* }}} */
function escapeHtml(text) {
function escapeHtml(text) { /* {{{ */
var map = {
'&': '&amp;',
'<': '&lt;',
@ -36,7 +38,7 @@ function escapeHtml(text) {
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
} /* }}} */
/**
* Format bytes as human-readable text.
@ -48,7 +50,7 @@ function escapeHtml(text) {
*
* @return Formatted string.
*/
function formatFileSize(bytes, si=false, dp=1) {
function formatFileSize(bytes, si=false, dp=1) { /* {{{ */
const thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
@ -68,7 +70,7 @@ function formatFileSize(bytes, si=false, dp=1) {
return bytes.toFixed(dp) + ' ' + units[u];
}
} /* }}} */
function treeFolderSelected(formid, nodeid, nodename) {
$('#'+formid).val(nodeid);
@ -82,7 +84,7 @@ function treeDocumentSelected(formid, nodeid, nodename) {
$('#docChooser'+formid).modal('hide');
}
function initMost() {
function initMost() { /* {{{ */
$('.datepicker, #expirationdate, #createstartdate, #createenddate, #expirationstartdate, #expirationenddate')
.datepicker({todayHighlight: true, toggleActive: true, autoclose: "true", zIndexOffset: "1040"})
/*
@ -94,12 +96,38 @@ function initMost() {
});
*/
$(".chzn-select").select2({
$(".chzn-select").select2({ /* {{{ */
theme: "bootstrap4",
width: 'resolve',
templateResult: chzn_template_func//,
//templateSelection: chzn_template_func
});
debug: false,
templateResult: chzn_template_func
}); /* }}} */
$(".chzn-select-folder").select2({ /* {{{ */
theme: "bootstrap4",
width: 'resolve',
ajax: {
url: seeddms_webroot+"op/op.Ajax.php",
delay: 500,
data: function (params) {
var query = {
query: params.term,
command: 'searchfolder',
format: 'select2'
}
// Query parameters will be ?search=[term]&command=folderlist
return query;
},
processResults: function(data) {
$.map(data.results, function (obj) {obj.text = obj.name || obj.text; obj.subtitle = obj.path || obj.subtitle; return obj; });
return {
results: data.results
};
},
dataType: 'json'
},
templateResult: chzn_template_func
}); /* }}} */
/* change the color and length of the bar graph showing the password
* strength on each change to the passwod field.
@ -319,10 +347,10 @@ function initMost() {
return this
}
}); /* }}} */
}
} /* }}} */
$(document).ready( function() {
$('body').on('click', '.dropdown-menu a.dropdown-toggle', function (e) {
$('body').on('click', '.dropdown-menu a.dropdown-toggle', function (e) { /* {{{ */
if (!$(this).next().hasClass('show')) {
$(this).parents('.dropdown-menu').first().find('.show').removeClass("show");
}
@ -336,33 +364,33 @@ $(document).ready( function() {
return false;
});
}); /* }}} */
/* close popovers when clicking somewhere except in the popover or the
* remove icon
*/
$('html').on('click', function(e) {
$('html').on('click', function(e) { /* {{{ */
if (typeof $(e.target).data('original-title') == 'undefined' && !$(e.target).parents().is('.popover.in') && !$(e.target).is('.fa fa-remove')) {
$('[data-original-title]').popover('hide');
}
});
}); /* }}} */
$('body').on('hidden', '.modal', function () {
$('body').on('hidden', '.modal', function () { /* {{{ */
$(this).removeData('modal');
});
}); /* }}} */
/* Bootstrap 4 does not support to the remote loading of the modal content
* anymore. This adds it by using jquery.
*/
$('body').on('click', '[data-toggle="modal"]', function(ev){
$('body').on('click', '[data-toggle="modal"]', function(ev){ /* {{{ */
ev.preventDefault();
$($(this).data("target")+' .modal-body').load($(this).data("remote"));
/* Also set the title */
if($(this).data("modal-title"))
$($(this).data("target")+' .modal-header h3').html($(this).data("modal-title"));
});
}); /* }}} */
$('body').on('click', '.show-hide-password a', function(ev){
$('body').on('click', '.show-hide-password a', function(ev) { /* {{{ */
ev.preventDefault();
// console.log($(this).closest('input'));
// console.log($(ev.target).parent().parent().children('input'));
@ -375,7 +403,7 @@ $(document).ready( function() {
$('.show-hide-password i').removeClass( "fa-eye-slash" );
$('.show-hide-password i').addClass( "fa-eye" );
}
});
}); /* }}} */
// $('body').on('touchstart.dropdown', '.dropdown-menu', function (e) { e.stopPropagation(); });
@ -633,6 +661,7 @@ $(document).ready( function() {
var query = element.data('query');
var afterload = $(this).data('afterload');
var updatemsg = element.data('update-msg');
var runinit = true;
if(view && action) {
url = seeddms_webroot+base+"out/out."+view+".php?action="+action;
if(query) {
@ -644,6 +673,8 @@ $(document).ready( function() {
for(var key in param1) {
if(key == 'callback')
callback = param1[key];
else if(key == 'noinit')
runinit = !param1[key];
else {
if($.isArray(param1[key])) {
if(param1[key].length > 0)
@ -670,7 +701,9 @@ $(document).ready( function() {
func();
}
}
if(runinit) {
initMost();
}
SeedDMSAjax.run(view, action);
});
}); /* }}} */