Add shortcut , searchable items and list

This commit is contained in:
ATM john 2019-09-29 12:51:27 +02:00
parent cc1d490135
commit 37f476bd8f
3 changed files with 102 additions and 11 deletions

View File

@ -197,7 +197,7 @@ function printDropdownBookmarksList($aDb, $aLangs)
$searchForm = '<!-- form with POST method by default, will be replaced with GET for external link by js -->'."\n";
$searchForm.= '<form id="top-menu-action-bookmark" name="actionbookmark" method="POST" action="">';
$searchForm.= '<input name="bookmark" id="topboxbookmark" class="dropdown-search-input" alt="Bookmarks" placeholder="'.$langs->trans('Bookmarks').'">';
$searchForm.= '<input name="bookmark" id="top-bookmark-search-input" class="dropdown-search-input" alt="Bookmarks" placeholder="'.$langs->trans('Bookmarks').'" autocomplete="off" >';
$searchForm.= '</form>';
// Url to list bookmark
@ -217,23 +217,75 @@ function printDropdownBookmarksList($aDb, $aLangs)
}
$html = '
$bookmarkList='<div id="dropdown-bookmarks-list" >';
// Menu with all bookmarks
if (! empty($conf->global->BOOKMARKS_SHOW_IN_MENU))
{
$sql = "SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX."bookmark";
$sql.= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)";
$sql.= " AND entity IN (".getEntity('bookmarks').")";
$sql.= " ORDER BY position";
if ($resql = $db->query($sql) )
{
$i=0;
while ($i < $conf->global->BOOKMARKS_SHOW_IN_MENU && $obj = $db->fetch_object($resql))
{
$bookmarkList.='<a class="dropdown-item bookmark-item" id="bookmark-item-'.$obj->rowid.'" data-id="'.$obj->rowid.'" '.($obj->target == 1?' target="_blank"':'').' href="'.dol_escape_htmltag($obj->url).'" >';
$bookmarkList.=dol_escape_htmltag($obj->title);
$bookmarkList.='</a>';
$i++;
}
}
else
{
dol_print_error($db);
}
}
$bookmarkList.='</div>';
$html= '';
if (! empty($conf->global->BOOKMARKS_SHOW_IN_MENU)) {
$html.= '
<!-- User image -->
<div class="bookmark-header">
'.$searchForm.'
' . $searchForm . '
</div>
';
}
$html.= '
<!-- Menu Body -->
<div class="bookmark-body"></div>
<div class="bookmark-body">
'.$bookmarkList.'
</div>
';
$html.= '
<!-- Menu Footer-->
<div class="bookmark-footer">
'.$newbtn.'<br/>'.$listbtn.'
<div style="clear:both;"></div>
</div>';
</div>
';
if (! empty($conf->global->BOOKMARKS_SHOW_IN_MENU)) {
$html .= '<script>
$( document ).on("keyup", "#top-bookmark-search-input", function () {
var filter = $(this).val(), count = 0;
$("#dropdown-bookmarks-list .bookmark-item").each(function () {
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).addClass("hidden-search-result");
} else {
$(this).removeClass("hidden-search-result");
count++;
}
});
$("#top-bookmark-search-filter-count").text(count);
});
</script>';
}
return $html;

View File

@ -1933,9 +1933,9 @@ function top_menu_bookmark(User $user, Translate $langs)
$html.= '<!-- div for bookmark link -->
<div id="topmenu-bookmark-dropdown" class="atoplogin dropdown">
<span class="dropdown-toggle login-dropdown-a" data-toggle="dropdown">
<a class="dropdown-toggle login-dropdown-a" data-toggle="dropdown" href="#">
<i class="fa fa-star" ></i>
</span>
</a>
<div class="dropdown-menu">
'.printDropdownBookmarksList($db, $langs).'
</div>
@ -1960,11 +1960,23 @@ function top_menu_bookmark(User $user, Translate $langs)
});
$("#topmenu-bookmark-dropdown .dropdown-toggle").on("click", function(event) {
event.preventDefault();
$("#topmenu-bookmark-dropdown").toggleClass("open");
$("#topboxbookmark").focus();
openBookMarkDropDown();
});
// Key map shortcut
$(document).keydown(function(e){
if( e.which === 77 && e.ctrlKey && e.shiftKey ){
console.log(\'control + shift + m : trigger open bookmark dropdown\');
openBookMarkDropDown();
}
});
var openBookMarkDropDown = function() {
event.preventDefault();
$("#topmenu-bookmark-dropdown").toggleClass("open");
$("#top-bookmark-search-input").focus();
}
});
</script>

View File

@ -124,6 +124,10 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
white-space: normal;
}
.dropdown-menu > .bookmark-body{
padding: 10px 0;
}
#topmenu-login-dropdown{
padding: 0 5px 0 5px;
}
@ -184,7 +188,28 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
box-shadow: none;
}
.dropdown-item {
display: block;
width: 100%;
padding: .25rem 1.5rem;
clear: both;
font-weight: 400;
color: #212529 !important;
text-align: inherit;
white-space: nowrap;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.dropdown-item.active, .dropdown-item:hover {
color: #<?php echo $colortextbackhmenu; ?> !important;
text-decoration: none;
background: rgb(<?php echo $colorbackhmenu1 ?>);
}
/*
* SEARCH
@ -219,4 +244,6 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
letter-spacing: 1.5px;
}
.hidden-search-result{
display: none !important;
}