[FIX] web: re-introduce wow effect
When clicking on buttons with classname o_wow (e.g. when marking an opportunity as won).
This commit is contained in:
@@ -81,6 +81,7 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
|
||||
}
|
||||
});
|
||||
},
|
||||
show_wow: '_onShowWow',
|
||||
},
|
||||
init: function (parent) {
|
||||
this.client_options = {};
|
||||
@@ -313,6 +314,22 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
|
||||
this.notification_manager.warn(e.data.title, e.data.message, e.data.sticky);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Displays a thumb up, heart or peace image (randomly) for a moment (e.g.
|
||||
* used when an opportunity is won)
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_onShowWow: function () {
|
||||
var className = 'o_wow_thumbs';
|
||||
if (Math.random() > 0.9) {
|
||||
var otherClasses = ['o_wow_peace', 'o_wow_heart'];
|
||||
className = otherClasses[Math.floor(Math.random()*otherClasses.length)];
|
||||
}
|
||||
var $body = $('body');
|
||||
$body.addClass(className);
|
||||
setTimeout($body.removeClass.bind($body, className), 1000);
|
||||
},
|
||||
});
|
||||
|
||||
return AbstractWebClient;
|
||||
|
||||
@@ -380,10 +380,8 @@ var FormController = BasicController.extend({
|
||||
});
|
||||
}
|
||||
|
||||
if (event.data.show_wow) {
|
||||
def.then(function () {
|
||||
self.show_wow();
|
||||
});
|
||||
if (event.data.showWow) {
|
||||
def.then(this.trigger_up.bind(this, 'show_wow'));
|
||||
}
|
||||
|
||||
def.always(this._enableButtons.bind(this));
|
||||
|
||||
@@ -206,7 +206,7 @@ var FormRenderer = BasicRenderer.extend({
|
||||
self.trigger_up('button_clicked', {
|
||||
attrs: node.attrs,
|
||||
record: self.state,
|
||||
show_wow: self.$el.hasClass('o_wow'), // TODO: implement this (in view)
|
||||
showWow: $el.hasClass('o_wow'),
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -4895,5 +4895,40 @@ QUnit.module('Views', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('wow effect', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data.partner.fields.model_name = { string: "Model name", type: "char" };
|
||||
|
||||
var clickCount = 0;
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<button name="test" string="Mark Won" type="object" class="o_wow"/>' +
|
||||
'</form>',
|
||||
intercepts: {
|
||||
execute_action: function (event) {
|
||||
if (clickCount === 0) {
|
||||
event.data.on_success();
|
||||
} else {
|
||||
event.data.on_fail();
|
||||
}
|
||||
clickCount++;
|
||||
},
|
||||
show_wow: function () {
|
||||
assert.step('wow');
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
form.$('button.o_wow').click();
|
||||
assert.verifySteps(['wow']);
|
||||
form.$('button.o_wow').click();
|
||||
assert.verifySteps(['wow']);
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user