Add favorites menu

issue5715
review29391002
This commit is contained in:
Xavier Codinas
2016-10-28 09:09:52 +02:00
parent deedbb8cb4
commit 42ccffbae0
5 changed files with 142 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add favorites menu
* Show records names in wizard title
* Add support for datetime_field to Many2One, Reference
* Add calendar view
+1
View File
@@ -57,6 +57,7 @@ this repository contains the full copyright notices and license terms. -->
<div class="collapse navbar-collapse" id="user_menu_collapse">
<ul class="nav navbar-nav">
<li id="user-preferences"></li>
<li id="user-favorites"></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li id="user-logout"></li>
+134
View File
@@ -270,6 +270,7 @@ var Sao = {};
Sao.Tab.tabs.close(true).done(function() {
jQuery('#user-preferences').children().remove();
jQuery('#user-logout').children().remove();
jQuery('#user-favorites').children().remove();
jQuery('#menu').children().remove();
document.title = 'Tryton';
session.do_logout().always(Sao.login);
@@ -279,6 +280,7 @@ var Sao = {};
Sao.preferences = function() {
Sao.Tab.tabs.close(true).done(function() {
jQuery('#user-preferences').children().remove();
jQuery('#user-favorites').children().remove();
jQuery('#user-logout').children().remove();
jQuery('#menu').children().remove();
new Sao.Window.Preferences(function() {
@@ -289,9 +291,80 @@ var Sao = {};
});
});
};
Sao.favorites_menu = function() {
var clear_menu = function() {
if (menu) {
menu.remove();
}
};
jQuery(window).click(function() {
clear_menu();
});
if (jQuery('#user-favorites').children('.dropdown-menu')
.length !== 0 ) {
clear_menu();
} else {
var name = Sao.main_menu_screen.model_name + '.favorite';
var session = Sao.Session.current_session;
var args = {
'method': 'model.' + name + '.get',
};
var menu = jQuery('<ul/>', {
'class': 'dropdown-menu',
'aria-expanded': 'false'
});
jQuery('#user-favorites').append(menu);
Sao.rpc(args, session).then(function(fav) {
fav.forEach(function(menu_item) {
var a = jQuery('<a/>', {
'href': '#'
});
var id = menu_item[0];
var li = jQuery('<li/>', {
'role': 'presentation'
});
var icon = jQuery('<img/>', {
'class': 'favorite-icon'
});
a.append(icon);
li.append(a);
icon.attr('src',
Sao.common.ICONFACTORY.get_icon_url(menu_item[2]));
a.append(menu_item[1]);
a.click(function() {
clear_menu();
Sao.Action.exec_keyword('tree_open', {
'model': Sao.main_menu_screen.model_name,
'id': id,
'ids': [id],
});
});
menu.append(li);
});
menu.append(jQuery('<li/>', {
'class': 'divider'
}));
jQuery('<li/>', {
'role': 'presentation'
}).append(jQuery('<a/>', {
'href': '#'
}).click(function() {
clear_menu();
Sao.Tab.create({
'model': Sao.main_menu_screen.model_name +
'.favorite',
'mode': ['tree', 'form'],
'name': Sao.i18n.gettext('Manage favorites')
});
}).text(Sao.i18n.gettext('Manage favorites'))).appendTo(
menu);
});
}
};
Sao.user_menu = function(preferences) {
jQuery('#user-preferences').children().remove();
jQuery('#user-favorites').children().remove();
jQuery('#user-logout').children().remove();
jQuery('#user-preferences').append(jQuery('<a/>', {
'href': '#'
@@ -299,6 +372,10 @@ var Sao = {};
jQuery('#user-logout').append(jQuery('<a/>', {
'href': '#'
}).click(Sao.logout).append(Sao.i18n.gettext('Logout')));
jQuery('#user-favorites').append(jQuery('<a/>', {
'href': '#',
'data-toggle': 'dropdown'
}).click(Sao.favorites_menu).append(Sao.i18n.gettext('Favorites')));
};
Sao.menu = function(preferences) {
@@ -333,10 +410,67 @@ var Sao = {};
jQuery('#menu').append(gs.el);
jQuery('#menu').append(
form.screen.screen_container.content_box.detach());
form.screen.views[0].columns.push(
new FavoriteColumn(form.screen.model.fields.favorite));
});
};
Sao.main_menu_screen = null;
var FavoriteColumn = Sao.class_(Object, {
init: function(favorite) {
this.field = favorite;
this.header = jQuery('<th/>');
this.attributes = jQuery.extend({}, this.field.description);
this.attributes.name = this.field.name;
},
get_cell: function() {
var cell = jQuery('<span/>', {
'tabindex': 0
});
return cell;
},
render: function(record, cell) {
if (!cell) {
cell = this.get_cell();
}
record.load(this.field.name).done(function() {
if (record._values.favorite !== null) {
var star = 'glyphicon glyphicon-star';
if (!record._values.favorite) {
star += '-empty';
}
cell.addClass(star);
cell.click({'record': record, 'button': cell},
this.favorite_click);
}
}.bind(this));
return cell;
},
favorite_click: function(e) {
// Prevent activate the action of the row
e.stopImmediatePropagation();
var button = e.data.button;
var method;
if (button.hasClass('glyphicon-star-empty')) {
button.removeClass('glyphicon-star-empty');
button.addClass('glyphicon-star');
method = 'set';
} else {
button.removeClass('glyphicon-star');
button.addClass('glyphicon-star-empty');
method = 'unset';
}
var name = Sao.main_menu_screen.model_name + '.favorite';
var session = Sao.Session.current_session;
var args = {
'method': 'model.' + name + '.' + method,
'params': [e.data.record.id, session.context]
};
Sao.rpc(args, session);
}
});
Sao.Dialog = Sao.class_(Object, {
init: function(title, class_, size) {
size = size || 'sm';
+5
View File
@@ -315,3 +315,8 @@ img.global-search-icon {
width: 2em;
height: 2em;
}
img.favorite-icon {
width: 1em;
height: 1em;
}
+1 -1
View File
@@ -51,7 +51,7 @@
},
create_toolbar: function() {
var toolbar = jQuery(
'<nav class="navbar navbar-default toolbar" role="navigation">' +
'<nav class="navbar-default toolbar" role="navigation">' +
'<div class="container-fluid">' +
'<div class="navbar-header">' +
'<a class="navbar-brand" href="#"></a>' +