Prepare dropdown bookmark menu
This commit is contained in:
parent
2b57d486dc
commit
cc1d490135
@ -150,3 +150,174 @@ 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="">';
|
||||
$searchForm.= '<input name="bookmark" id="topboxbookmark" class="dropdown-search-input" alt="Bookmarks" placeholder="'.$langs->trans('Bookmarks').'">';
|
||||
$searchForm.= '</form>';
|
||||
|
||||
// Url to list bookmark
|
||||
$listbtn = '<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans('Bookmarks').'</option>';
|
||||
|
||||
$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&urlsource='.urlencode($url).'&url='.urlencode($url);
|
||||
$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&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>';
|
||||
}
|
||||
|
||||
|
||||
$html = '
|
||||
|
||||
<!-- User image -->
|
||||
<div class="bookmark-header">
|
||||
'.$searchForm.'
|
||||
</div>
|
||||
|
||||
<!-- Menu Body -->
|
||||
<div class="bookmark-body"></div>
|
||||
|
||||
<!-- Menu Footer-->
|
||||
<div class="bookmark-footer">
|
||||
'.$newbtn.'<br/>'.$listbtn.'
|
||||
<div style="clear:both;"></div>
|
||||
</div>';
|
||||
|
||||
|
||||
|
||||
return $html;
|
||||
|
||||
|
||||
|
||||
if (! empty($conf->use_javascript_ajax)) { // Bookmark autosubmit can't work when javascript is off.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Menu bookmark
|
||||
$ret = '<div class="menu_top"></div>'."\n";
|
||||
|
||||
$ret.= '<!-- form with POST method by default, will be replaced with GET for external link by js -->'."\n";
|
||||
$ret.= '<form id="actionbookmark" name="actionbookmark" method="POST" action="">';
|
||||
$ret.= '<select name="bookmark" id="boxbookmark" class="flat boxcombo vmenusearchselectcombo" alt="Bookmarks">';
|
||||
$ret.= '<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans('Bookmarks').'</option>';
|
||||
$ret.= '<option value="listbookmark" class="optionblue" rel="'.dol_escape_htmltag(DOL_URL_ROOT.'/bookmarks/list.php').'" ';
|
||||
$ret.= ' data-html="'.dol_escape_htmltag('<span class="fa fa-star-o"></span> '.dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...').'">';
|
||||
$ret.= dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...</option>';
|
||||
|
||||
// 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))
|
||||
{
|
||||
$ret.='<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1?' target="_blank"':'').' rel="'.dol_escape_htmltag($obj->url).'"';
|
||||
//$ret.=' data-html="'.dol_escape_htmltag('<span class="fa fa-print"></span> '.$obj->title).'"';
|
||||
$ret.='>';
|
||||
$ret.=dol_escape_htmltag($obj->title);
|
||||
$ret.='</option>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
$ret.= '</select>';
|
||||
$ret.= '</form>';
|
||||
|
||||
$ret.=ajax_combobox('boxbookmark');
|
||||
|
||||
$ret.='<script>
|
||||
$(document).ready(function () {';
|
||||
$ret.=' jQuery("#boxbookmark").change(function() {
|
||||
var urlselected = jQuery("#boxbookmark option:selected").attr("rel");
|
||||
if (! urlselected) console.log("Error, failed to get the URL to jump to from the rel attribute");
|
||||
var urltarget = jQuery("#boxbookmark option:selected").attr("target");
|
||||
if (! urltarget) { urltarget=""; }
|
||||
jQuery("form#actionbookmark").attr("target",urltarget);
|
||||
jQuery("form#actionbookmark").attr("action",urlselected);
|
||||
|
||||
console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget);
|
||||
|
||||
// Method is POST for internal link, GET for external
|
||||
if (urlselected.startsWith(\'http\'))
|
||||
{
|
||||
var newmethod=\'GET\';
|
||||
jQuery("form#actionbookmark").attr("method", newmethod);
|
||||
console.log("We change method to newmethod="+newmethod);
|
||||
jQuery("#actionbookmark").submit();
|
||||
console.log("We restore method to POST");
|
||||
jQuery("form#actionbookmark").attr("method", \'POST\');
|
||||
}
|
||||
else
|
||||
{
|
||||
jQuery("#actionbookmark").submit();
|
||||
}
|
||||
});';
|
||||
$ret.='})</script>';
|
||||
}
|
||||
|
||||
$ret.= '<div class="menu_end"></div>'."\n";
|
||||
|
||||
return $ret;
|
||||
}
|
||||
@ -1606,6 +1606,12 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead
|
||||
|
||||
print '<div class="login_block usedropdown">'."\n";
|
||||
|
||||
|
||||
// Add bookmark dropdown
|
||||
$toprightmenu.=top_menu_bookmark($user, $langs);
|
||||
|
||||
|
||||
|
||||
// Add login user link
|
||||
$toprightmenu.='<div class="login_block_user">';
|
||||
|
||||
@ -1897,6 +1903,77 @@ function top_menu_user(User $user, Translate $langs)
|
||||
return $btnUser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the tooltip on top menu bookmark
|
||||
*
|
||||
* @param user $user User object
|
||||
* @param Translate $langs Language object
|
||||
* @return string HTML content
|
||||
*/
|
||||
function top_menu_bookmark(User $user, Translate $langs)
|
||||
{
|
||||
global $langs, $conf, $db, $hookmanager, $user;
|
||||
global $menumanager;
|
||||
$html = '';
|
||||
|
||||
|
||||
|
||||
// Define $bookmarks
|
||||
if (! empty($conf->bookmark->enabled) && $user->rights->bookmark->lire)
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/bookmarks/bookmarks.lib.php';
|
||||
$langs->load("bookmarks");
|
||||
|
||||
// Add login user link
|
||||
$html.='<div class="login_block_user">';
|
||||
|
||||
// Login name with photo and tooltip
|
||||
$html.='<div class="inline-block nowrap"><div class="inline-block login_block_elem login_block_elem_name" style="padding: 0px;">';
|
||||
|
||||
$html.= '<!-- div for bookmark link -->
|
||||
<div id="topmenu-bookmark-dropdown" class="atoplogin dropdown">
|
||||
<span class="dropdown-toggle login-dropdown-a" data-toggle="dropdown">
|
||||
<i class="fa fa-star" ></i>
|
||||
</span>
|
||||
<div class="dropdown-menu">
|
||||
'.printDropdownBookmarksList($db, $langs).'
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
$html.='</div></div>';
|
||||
|
||||
$html.='</div>'."\n";
|
||||
|
||||
|
||||
if (! defined('JS_JQUERY_DISABLE_DROPDOWN')) // This may be set by some pages that use different jquery version to avoid errors
|
||||
{
|
||||
$html .= '
|
||||
<!-- Code to show/hide the user drop-down -->
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
$(document).on("click", function(event) {
|
||||
if (!$(event.target).closest("#topmenu-bookmark-dropdown").length) {
|
||||
// Hide the menus.
|
||||
$("#topmenu-bookmark-dropdown").removeClass("open");
|
||||
}
|
||||
});
|
||||
|
||||
$("#topmenu-bookmark-dropdown .dropdown-toggle").on("click", function(event) {
|
||||
event.preventDefault();
|
||||
$("#topmenu-bookmark-dropdown").toggleClass("open");
|
||||
$("#topboxbookmark").focus();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
';
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show left menu bar
|
||||
*
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
|
||||
|
||||
/* <style type="text/css" > dont remove this line it's an ide hack */
|
||||
/*
|
||||
* Dropdown
|
||||
*/
|
||||
@ -98,6 +98,10 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
|
||||
background: rgb(<?php echo $colorbackhmenu1 ?>);
|
||||
}
|
||||
|
||||
.dropdown-menu > .bookmark-header{
|
||||
padding: 5px 10px 10px 10px;
|
||||
}
|
||||
|
||||
.dropdown-menu > .user-footer {
|
||||
background-color: #f9f9f9;
|
||||
padding: 10px;
|
||||
@ -107,7 +111,13 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.dropdown-menu > .user-body {
|
||||
|
||||
.dropdown-menu > .bookmark-footer{
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
|
||||
.dropdown-menu > .user-body, .dropdown-menu > .bookmark-body{
|
||||
padding: 15px;
|
||||
border-bottom: 1px solid #f4f4f4;
|
||||
border-top: 1px solid #dddddd;
|
||||
@ -166,3 +176,47 @@ if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
|
||||
background-color: #f4f4f4;
|
||||
border-color: #ddd;
|
||||
}
|
||||
|
||||
.top-menu-dropdown-link {
|
||||
color: rgb(<?php print $colortextlink; ?>) !important;
|
||||
-webkit-box-shadow: none;
|
||||
-moz-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* SEARCH
|
||||
*/
|
||||
|
||||
.dropdown-search-input {
|
||||
width: 100%;
|
||||
padding: 10px 35px 10px 20px;
|
||||
|
||||
background-color: transparent;
|
||||
font-size: 14px;
|
||||
line-height: 16px;
|
||||
box-sizing: border-box;
|
||||
|
||||
|
||||
color: #575756;
|
||||
background-color: transparent;
|
||||
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3Cpath d='M0 0h24v24H0z' fill='none'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 16px 16px;
|
||||
background-position: 95% center;
|
||||
border-radius: 50px;
|
||||
border: 1px solid #c4c4c2 !important;
|
||||
transition: all 250ms ease-in-out;
|
||||
backface-visibility: hidden;
|
||||
transform-style: preserve-3d;
|
||||
|
||||
}
|
||||
|
||||
.dropdown-search-input::placeholder {
|
||||
color: color(#575756 a(0.8));
|
||||
letter-spacing: 1.5px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user