do not add items ot sequence chooser, if number of documents/folders is greater than 50

This commit is contained in:
Uwe Steinmann 2024-03-25 10:58:16 +01:00
parent a00655932b
commit 19c70d5588
6 changed files with 72 additions and 20 deletions

View File

@ -241,7 +241,7 @@ console.log(params);
}
}
if(!$nodocumentformfields || !in_array('sequence', $nodocumentformfields)) {
$this->formField(getMLText("sequence"), $this->getSequenceChooser($folder->getDocuments('s')).($orderby != 's' ? "<br />".getMLText('order_by_sequence_off') : ''));
$this->formField(getMLText("sequence"), $this->getSequenceChooser($folder, 'd').($orderby != 's' ? "<br />".getMLText('order_by_sequence_off') : ''));
} else {
$minmax = $folder->getDocumentsMinMax();
if($this->params['defaultposition'] == 'start') {

View File

@ -98,7 +98,7 @@ $(document).ready( function() {
)
);
if(!$nofolderformfields || !in_array('sequence', $nofolderformfields)) {
$this->formField(getMLText("sequence"), $this->getSequenceChooser($folder->getSubFolders('s')).($orderby != 's' ? "<br />".getMLText('order_by_sequence_off') : ''));
$this->formField(getMLText("sequence"), $this->getSequenceChooser($folder, 'f').($orderby != 's' ? "<br />".getMLText('order_by_sequence_off') : ''));
} else {
$minmax = $folder->getFoldersMinMax();
if($this->params['defaultposition'] == 'start') {

View File

@ -1598,17 +1598,43 @@ $(document).ready(function() {
print "</select>";
} /* }}} */
function printSequenceChooser($objArr, $keepID = -1) { /* {{{ */
echo $this->getSequenceChooser($objArr, $keepID);
function printSequenceChooser($parent, $type, $keepID = -1) { /* {{{ */
echo $this->getSequenceChooser($parent, $type, $keepID);
} /* }}} */
function getSequenceChooser($objArr, $keepID = -1) { /* {{{ */
if (count($objArr) > 0) {
$max = $objArr[count($objArr)-1]->getSequence() + 1;
$min = $objArr[0]->getSequence() - 1;
/**
* Return html code for sequence chooser
*
* This method will return the html code of the ѕelect menu for setting
* the ѕequence number of a document or folder. The select menu will contain
* a list of all siblings to select to positon relative to a sibling.
* For performance reasons the select menu will not contain any siblings
* if the number of siblings is greater than 50.
*
* @param $parent object parent folder of new or updated document/folder
* @param $type string type of new object 'f'=folder, 'd'=document
* @param $keepID integer id of current object
*/
function getSequenceChooser($parent, $type, $keepID = -1) { /* {{{ */
$objArr = [];
if($type == 'd') {
if(($c = $parent->hasDocuments()) < 50)
$objArr = $parent->getDocuments('s');
$minmax = $parent->getDocumentsMinMax();
} elseif($type = 'f') {
if(($c = $parent->hasSubFolders()) < 50)
$objArr = $parent->getSubFolders('s');
$minmax = $parent->getFoldersMinMax();
} else
return '';
if ($objArr) {
$min = $minmax['min']-1.0;
$max = $minmax['max']+1.0;
}
else {
$max = 1.0;
$min = (float) $minmax['min'];
$max = $minmax['max']+1.0;
}
$content = "<select name=\"sequence\">\n";
if ($keepID != -1) {
@ -1616,7 +1642,7 @@ $(document).ready(function() {
}
if($this->params['defaultposition'] != 'start')
$content .= " <option value=\"".$max."\">" . getMLText("seq_end");
if (count($objArr) > 0) {
if ($c > 0) {
$content .= " <option value=\"".$min."\">" . getMLText("seq_start");
}
if($this->params['defaultposition'] == 'start')

View File

@ -201,7 +201,7 @@ $(document).ready( function() {
}
if(!$nodocumentformfields || !in_array('sequence', $nodocumentformfields)) {
if ($folder->getAccessMode($user) > M_READ) {
$this->formField(getMLText("sequence"), $this->getSequenceChooser($folder->getDocuments('s'), $document->getID()).($orderby != 's' ? "<br />".getMLText('order_by_sequence_off') : ''));
$this->formField(getMLText("sequence"), $this->getSequenceChooser($folder, 'd', $document->getID()).($orderby != 's' ? "<br />".getMLText('order_by_sequence_off') : ''));
}
}
if($attrdefs) {

View File

@ -108,7 +108,7 @@ $(document).ready(function() {
$parent = ($folder->getID() == $rootfolderid) ? false : $folder->getParent();
if(!$nofolderformfields || !in_array('sequence', $nofolderformfields)) {
if ($parent && $parent->getAccessMode($user) > M_READ) {
$this->formField(getMLText("sequence"), $this->getSequenceChooser($parent->getSubFolders('s'), $folder->getID()).($orderby != 's' ? "<br />".getMLText('order_by_sequence_off') : ''));
$this->formField(getMLText("sequence"), $this->getSequenceChooser($parent, 'f', $folder->getID()).($orderby != 's' ? "<br />".getMLText('order_by_sequence_off') : ''));
}
}
if($attrdefs) {

View File

@ -1627,17 +1627,43 @@ $(document).ready(function() {
print "</select>";
} /* }}} */
function printSequenceChooser($objArr, $keepID = -1) { /* {{{ */
echo $this->getSequenceChooser($objArr, $keepID);
function printSequenceChooser($parent, $type, $keepID = -1) { /* {{{ */
echo $this->getSequenceChooser($parent, $type, $keepID);
} /* }}} */
function getSequenceChooser($objArr, $keepID = -1) { /* {{{ */
if (count($objArr) > 0) {
$max = $objArr[count($objArr)-1]->getSequence() + 1;
$min = $objArr[0]->getSequence() - 1;
/**
* Return html code for sequence chooser
*
* This method will return the html code of the ѕelect menu for setting
* the ѕequence number of a document or folder. The select menu will contain
* a list of all siblings to select to positon relative to a sibling.
* For performance reasons the select menu will not contain any siblings
* if the number of siblings is greater than 50.
*
* @param $parent object parent folder of new or updated document/folder
* @param $type string type of new object 'f'=folder, 'd'=document
* @param $keepID integer id of current object
*/
function getSequenceChooser($parent, $type, $keepID = -1) { /* {{{ */
$objArr = [];
if($type == 'd') {
if(($c = $parent->hasDocuments()) < 50)
$objArr = $parent->getDocuments('s');
$minmax = $parent->getDocumentsMinMax();
} elseif($type = 'f') {
if(($c = $parent->hasSubFolders()) < 50)
$objArr = $parent->getSubFolders('s');
$minmax = $parent->getFoldersMinMax();
} else
return '';
if ($objArr) {
$min = $minmax['min']-1.0;
$max = $minmax['max']+1.0;
}
else {
$max = 1.0;
$min = (float) $minmax['min'];
$max = $minmax['max']+1.0;
}
$content = "<select class=\"form-control\" name=\"sequence\">\n";
if ($keepID != -1) {
@ -1645,7 +1671,7 @@ $(document).ready(function() {
}
if($this->params['defaultposition'] != 'start')
$content .= " <option value=\"".$max."\">" . getMLText("seq_end");
if (count($objArr) > 0) {
if ($c > 0) {
$content .= " <option value=\"".$min."\">" . getMLText("seq_start");
}
if($this->params['defaultposition'] == 'start')