[FIX] web: make rainbowMan more solid
This commit is contained in:
@@ -21,7 +21,7 @@ var Dialog = require('web.Dialog');
|
||||
var Loading = require('web.Loading');
|
||||
var mixins = require('web.mixins');
|
||||
var NotificationManager = require('web.notification').NotificationManager;
|
||||
var RainbowMan = require('web.rainbow_man');
|
||||
var RainbowMan = require('web.RainbowMan');
|
||||
var session = require('web.session');
|
||||
var Widget = require('web.Widget');
|
||||
|
||||
|
||||
@@ -1,27 +1,40 @@
|
||||
odoo.define('web.rainbow_man', function (require) {
|
||||
odoo.define('web.RainbowMan', function (require) {
|
||||
"use strict";
|
||||
|
||||
var ajax = require("web.ajax");
|
||||
/**
|
||||
* The RainbowMan widget is the widget displayed by default as a 'fun/rewarding'
|
||||
* effect in some cases. For example, when the user marked a large deal as won,
|
||||
* or when he cleared its inbox.
|
||||
*
|
||||
* This widget is mostly a picture and a message with a rainbow animation around
|
||||
* If you want to display a RainbowMan, you probably do not want to do it by
|
||||
* importing this file. The usual way to do that would be to use the effect
|
||||
* service (by triggering the 'show_effect' event)
|
||||
*/
|
||||
|
||||
var Widget = require('web.Widget');
|
||||
var core = require('web.core');
|
||||
var qweb = core.qweb;
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
var RainbowMan = Widget.extend({
|
||||
template: 'rainbow_man.notification',
|
||||
xmlDependencies: ['/web/static/src/xml/rainbow_man.xml'],
|
||||
/**
|
||||
* @override
|
||||
* @constructor
|
||||
* @param {Object} [options] - key-value options to decide rainbowman behavior / appearance
|
||||
* @param {string} [options.message] - Message to be displayed on rainbowman card
|
||||
* @param {string} [options.fadeout]
|
||||
* Delay for rainbowman to disappear - [options.fadeout='fast'] will make rainbowman
|
||||
* dissapear quickly, [options.fadeout='medium'] and [options.fadeout='slow'] will
|
||||
* wait little longer before disappearing (can be used when [options.message]
|
||||
* is longer), [options.fadeout='no'] will keep rainbowman on screen until
|
||||
* user clicks anywhere outside rainbowman
|
||||
* @param {string} [options.img_url] - URL of the image to be displayed
|
||||
* @param {Boolean} [options.click_close] - If true, destroys rainbowman on click outside
|
||||
* @param {Object} [options]
|
||||
* @param {string} [options.message] Message to be displayed on rainbowman card
|
||||
* @param {string} [options.fadeout='medium'] Delay for rainbowman to disappear
|
||||
* [options.fadeout='fast'] will make rainbowman dissapear quickly,
|
||||
* [options.fadeout='medium'] and [options.fadeout='slow'] will wait
|
||||
* little longer before disappearing (can be used when [options.message]
|
||||
* is longer),
|
||||
* [options.fadeout='no'] will keep rainbowman on screen until user clicks
|
||||
* anywhere outside rainbowman
|
||||
* @param {string} [options.img_url] URL of the image to be displayed
|
||||
* @param {boolean} [options.click_close=true] If true, destroys rainbowman on
|
||||
* click outside
|
||||
*/
|
||||
init: function (options) {
|
||||
this._super.apply(this, arguments);
|
||||
@@ -35,18 +48,6 @@ var RainbowMan = Widget.extend({
|
||||
this.delay = rainbowDelay[this.options.fadeout];
|
||||
core.bus.on('clear_uncommitted_changes', this, this.destroy);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
willStart: function () {
|
||||
var def;
|
||||
if (!qweb.has_template(this.template)) {
|
||||
// we need to manually load the templates when the rainbon_man is used in
|
||||
// the frontend, for example, it may be displayed at the end of a tour.
|
||||
def = ajax.loadXML("/web/static/src/xml/rainbow_man.xml", qweb);
|
||||
}
|
||||
return $.when(this._super.apply(this, arguments), def);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@ var config = require('web.config');
|
||||
var core = require('web.core');
|
||||
var FormView = require('web.FormView');
|
||||
var pyeval = require('web.pyeval');
|
||||
var RainbowMan = require('web.rainbow_man');
|
||||
var RainbowMan = require('web.RainbowMan');
|
||||
var testUtils = require('web.test_utils');
|
||||
var widgetRegistry = require('web.widget_registry');
|
||||
var Widget = require('web.Widget');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
odoo.define('web.rainbow_man_tests', function (require) {
|
||||
odoo.define('web.RainbowMan_tests', function (require) {
|
||||
"use strict";
|
||||
|
||||
var RainbowMan = require('web.rainbow_man');
|
||||
var RainbowMan = require('web.RainbowMan');
|
||||
|
||||
QUnit.module('widgets', {}, function () {
|
||||
|
||||
@@ -15,22 +15,25 @@ QUnit.module('RainbowMan', {
|
||||
}, function () {
|
||||
|
||||
QUnit.test("rendering a rainbowman", function (assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(2);
|
||||
|
||||
var $target = $("#qunit-fixture");
|
||||
|
||||
// Create and display rainbowman
|
||||
var rainbowman = new RainbowMan(this.data);
|
||||
rainbowman.appendTo($target);
|
||||
rainbowman.appendTo($target).then(function () {
|
||||
var $rainbow = rainbowman.$(".o_reward_rainbow");
|
||||
assert.strictEqual($rainbow.length, 1,
|
||||
"Should have displayed rainbow effect");
|
||||
|
||||
var $rainbow = rainbowman.$(".o_reward_rainbow");
|
||||
assert.strictEqual($rainbow.length, 1,
|
||||
"Should have displayed rainbow effect");
|
||||
assert.ok(rainbowman.$('.o_reward_msg_content').html() === 'Congrats!',
|
||||
"Card on the rainbowman should display 'Congrats!' message");
|
||||
|
||||
assert.ok(rainbowman.$('.o_reward_msg_content').html() === 'Congrats!',
|
||||
"Card on the rainbowman should display 'Congrats!' message");
|
||||
rainbowman.destroy();
|
||||
done();
|
||||
});
|
||||
|
||||
rainbowman.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ odoo.define('web_tour.TourManager', function(require) {
|
||||
var core = require('web.core');
|
||||
var local_storage = require('web.local_storage');
|
||||
var mixins = require('web.mixins');
|
||||
var RainbowMan = require('web.rainbow_man');
|
||||
var RainbowMan = require('web.RainbowMan');
|
||||
var ServicesMixin = require('web.ServicesMixin');
|
||||
var session = require('web.session');
|
||||
var Tip = require('web_tour.Tip');
|
||||
|
||||
Reference in New Issue
Block a user