mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
web_notify: add feature to reload current view
This commit is contained in:
committed by
Yannick Vaucher
parent
b8e1337079
commit
8d3f2749e4
5
web_notify/static/src/css/notification.less
Normal file
5
web_notify/static/src/css/notification.less
Normal file
@@ -0,0 +1,5 @@
|
||||
.o_notification {
|
||||
.o_notification_reload {
|
||||
padding: 10px;
|
||||
}
|
||||
}
|
||||
40
web_notify/static/src/js/notification.js
Normal file
40
web_notify/static/src/js/notification.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/* Copyright 2018 Camptocamp
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||
odoo.define('web_notify.notification', function (require) {
|
||||
"use strict";
|
||||
|
||||
var base_notification = require('web.notification'),
|
||||
WebClient = require('web.WebClient'),
|
||||
Notification = base_notification.Notification,
|
||||
Warning = base_notification.Warning;
|
||||
|
||||
Notification.include({
|
||||
events: _.extend(
|
||||
{},
|
||||
Notification.prototype.events,
|
||||
{'click .o_view_reload': function(e){
|
||||
e.preventDefault();
|
||||
this.reload_active_view();
|
||||
}
|
||||
}
|
||||
),
|
||||
init: function(parent, title, text, sticky, options) {
|
||||
this._super.apply(this, arguments);
|
||||
this.options = options || {};
|
||||
},
|
||||
reload_active_view: function() {
|
||||
this.trigger_up('reload_active_view');
|
||||
},
|
||||
});
|
||||
|
||||
base_notification.NotificationManager.include({
|
||||
notify: function(title, text, sticky, options) {
|
||||
return this.display(new Notification(this, title, text, sticky, options));
|
||||
},
|
||||
warn: function(title, text, sticky, options) {
|
||||
return this.display(new Warning(this, title, text, sticky, options));
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,13 +1,52 @@
|
||||
odoo.define('web_notify.WebClient', function (require) {
|
||||
"use strict";
|
||||
|
||||
var WebClient = require('web.WebClient');
|
||||
var base_bus = require('bus.bus');
|
||||
var core = require('web.core'),
|
||||
WebClient = require('web.WebClient'),
|
||||
base_bus = require('bus.bus'),
|
||||
Widget = require('web.Widget');
|
||||
|
||||
|
||||
Widget.include({
|
||||
do_notify: function(title, message, sticky, options) {
|
||||
this.trigger_up('notification', {title: title, message: message, sticky: sticky, options: options});
|
||||
},
|
||||
do_warn: function(title, message, sticky, options) {
|
||||
this.trigger_up('warning', {title: title, message: message, sticky: sticky, options: options});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
WebClient.include({
|
||||
custom_events: _.extend(
|
||||
{},
|
||||
WebClient.prototype.custom_events,
|
||||
{reload_active_view: 'reload_active_view',
|
||||
notification: function (e) {
|
||||
if(this.notification_manager) {
|
||||
this.notification_manager.notify(e.data.title, e.data.message, e.data.sticky, e.data.options);
|
||||
}
|
||||
},
|
||||
warning: function (e) {
|
||||
if(this.notification_manager) {
|
||||
this.notification_manager.warn(e.data.title, e.data.message, e.data.sticky, e.data.options);
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
init: function(parent, client_options){
|
||||
this._super(parent, client_options);
|
||||
},
|
||||
reload_active_view: function(){
|
||||
var action_manager = this.action_manager;
|
||||
if(!action_manager){
|
||||
return;
|
||||
}
|
||||
var active_view = action_manager.inner_widget.active_view;
|
||||
if(active_view) {
|
||||
active_view.controller.reload();
|
||||
}
|
||||
},
|
||||
show_application: function() {
|
||||
var res = this._super();
|
||||
this.start_polling();
|
||||
@@ -40,12 +79,12 @@ WebClient.include({
|
||||
},
|
||||
on_message_warning: function(message){
|
||||
if(this.notification_manager) {
|
||||
this.notification_manager.do_warn(message.title, message.message, message.sticky);
|
||||
this.notification_manager.do_warn(message.title, message.message, message.sticky, message);
|
||||
}
|
||||
},
|
||||
on_message_info: function(message){
|
||||
if(this.notification_manager) {
|
||||
this.notification_manager.do_notify(message.title, message.message, message.sticky);
|
||||
this.notification_manager.do_notify(message.title, message.message, message.sticky, message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
24
web_notify/static/src/xml/notification.xml
Normal file
24
web_notify/static/src/xml/notification.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
|
||||
<t t-name="Notification.reload">
|
||||
<div class="o_notification_reload" t-if="widget.options.show_reload">
|
||||
<a href="#" class="o_view_reload">
|
||||
<span class="fa fa-refresh"/> Reload current view
|
||||
</a>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-extend="Notification">
|
||||
<t t-jquery=".o_notification_content" t-operation="after">
|
||||
<t t-call="Notification.reload"/>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
<t t-extend="Warning">
|
||||
<t t-jquery=".o_notification_content" t-operation="after">
|
||||
<t t-call="Notification.reload"/>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
Reference in New Issue
Block a user