Skip to content

Commit

Permalink
Merge pull request #11986 from atm-john/develop_dropdown_bookmark
Browse files Browse the repository at this point in the history
NEW :  dropdown bookmark and search
  • Loading branch information
eldy committed Oct 3, 2019
2 parents c223c56 + 135621c commit ad4aa39
Show file tree
Hide file tree
Showing 5 changed files with 548 additions and 57 deletions.
137 changes: 137 additions & 0 deletions htdocs/bookmarks/bookmarks.lib.php
Expand Up @@ -150,3 +150,140 @@ function printBookmarksList($aDb, $aLangs)

return $ret;
}



/**
* Add area with bookmarks in top menu
*
* @param DoliDb $aDb Database handler
* @param Translate $aLangs Object lang
* @return string
*/
function printDropdownBookmarksList($aDb, $aLangs)
{
global $conf, $user;

$db = $aDb;
$langs = $aLangs;

require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
if (! isset($conf->global->BOOKMARKS_SHOW_IN_MENU)) $conf->global->BOOKMARKS_SHOW_IN_MENU=5;

$langs->load("bookmarks");

$url= $_SERVER["PHP_SELF"];

if (! empty($_SERVER["QUERY_STRING"]))
{
$url.=(dol_escape_htmltag($_SERVER["QUERY_STRING"])?'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]):'');
}
else
{
global $sortfield,$sortorder;
$tmpurl='';
// No urlencode, all param $url will be urlencoded later
if ($sortfield) $tmpurl.=($tmpurl?'&':'').'sortfield='.$sortfield;
if ($sortorder) $tmpurl.=($tmpurl?'&':'').'sortorder='.$sortorder;
if (is_array($_POST))
{
foreach($_POST as $key => $val)
{
if (preg_match('/^search_/', $key) && $val != '') $tmpurl.=($tmpurl?'&':'').$key.'='.$val;
}
}
$url.=($tmpurl?'?'.$tmpurl:'');
}

$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="" onsubmit="return false" >';
$searchForm.= '<input name="bookmark" id="top-bookmark-search-input" class="dropdown-search-input" placeholder="'.$langs->trans('Bookmarks').'" autocomplete="off" >';
$searchForm.= '</form>';

// Url to list bookmark
$listbtn = '<a class="top-menu-dropdown-link" title="'.$langs->trans('AddThisPageToBookmarks').'" href="'.DOL_URL_ROOT.'/bookmarks/list.php" >';
$listbtn.= '<span class="fa fa-list"></span> '.$langs->trans('Bookmarks').'</a>';

// Url to go on create new bookmark page
$newbtn = '';
if (! empty($user->rights->bookmark->creer))
{
//$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;urlsource='.urlencode($url).'&amp;url='.urlencode($url);
$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;url='.urlencode($url);
$newbtn.= '<a class="top-menu-dropdown-link" title="'.$langs->trans('AddThisPageToBookmarks').'" href="'.dol_escape_htmltag($urltoadd).'" >';
$newbtn.= '<span class="fa fa-star-o"></span> '.dol_escape_htmltag($langs->trans('AddThisPageToBookmarks')).'</a>';
}


$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.= '
<!-- search input -->
<div class="dropdown-header bookmark-header">
' . $searchForm . '
</div>
';
}

$html.= '
<!-- Menu Body -->
<div class="bookmark-body dropdown-body">
'.$bookmarkList.'
</div>
';

$html.= '
<!-- Menu Footer-->
<div class="bookmark-footer">
'.$newbtn.$listbtn.'
<div style="clear:both;"></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;
}
1 change: 1 addition & 0 deletions htdocs/langs/en_US/bookmarks.lang
Expand Up @@ -18,3 +18,4 @@ SetHereATitleForLink=Set a name for the bookmark
UseAnExternalHttpLinkOrRelativeDolibarrLink=Use an external/absolute link (https://URL) or an internal/relative link (/DOLIBARR_ROOT/htdocs/...)
ChooseIfANewWindowMustBeOpenedOnClickOnBookmark=Choose if the linked page should open in the current tab or a new tab
BookmarksManagement=Bookmarks management
BookmarksMenuShortCut=Ctrl + shift + m

0 comments on commit ad4aa39

Please sign in to comment.