summaryrefslogtreecommitdiff
path: root/addons/lunch/static/src/js/lunch_controller_common.js
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-07-13 13:18:20 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2020-07-23 08:21:10 +0000
commit3162141e4d71e9c55aff5241c5578571b68c332d (patch)
treeb925820ad917acfce48e4030b06ba55d88ba1c77 /addons/lunch/static/src/js/lunch_controller_common.js
parent7ff2e5822f08616dd22c142e0e05ed4355801760 (diff)
[IMP] lunch: Conversion of model to extension
Conversion of the lunch kanban model to a proper search extension. Now that the view search model supports model extensions, it has become more convenient to provide additional domain informations by appending new extensions. This is why the lunch "location" logic (locationId and userId) has been shifted to a new model extension ("Lunch Model Extension") which provides an additional domain part to the other search extensions. Part of task 2228968 Co-authored-by: Julien Mougenot <jum@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/lunch/static/src/js/lunch_controller_common.js')
-rw-r--r--addons/lunch/static/src/js/lunch_controller_common.js51
1 files changed, 8 insertions, 43 deletions
diff --git a/addons/lunch/static/src/js/lunch_controller_common.js b/addons/lunch/static/src/js/lunch_controller_common.js
index 27ce66ec49c..8cd09316220 100644
--- a/addons/lunch/static/src/js/lunch_controller_common.js
+++ b/addons/lunch/static/src/js/lunch_controller_common.js
@@ -27,7 +27,6 @@ var LunchControllerCommon = {
*/
init: function () {
this._super.apply(this, arguments);
- this.userId = null;
this.editMode = false;
this.updated = false;
this.widgetData = null;
@@ -60,30 +59,16 @@ var LunchControllerCommon = {
},
});
},
- _fetchWidgetData: function () {
- var self = this;
-
- return this._rpc({
+ _fetchWidgetData: async function () {
+ this.widgetData = await this._rpc({
route: '/lunch/infos',
params: {
- user_id: this.userId,
+ user_id: this.searchModel.get('userId'),
context: this.context,
},
- }).then(function (data) {
- self.widgetData = data;
- return self.model._updateLocation(data.user_location[0]);
});
},
/**
- * Override to add the location domain (coming from the LunchWidget)
- * to the searchDomain (coming from the controlPanel).
- *
- * @override
- */
- _getViewDomain: async function () {
- return this.model.getLocationDomain();
- },
- /**
* Renders and appends the lunch banner widget.
*
* @private
@@ -140,28 +125,14 @@ var LunchControllerCommon = {
});
},
_onLocationChanged: function (ev) {
- var self = this;
-
ev.stopPropagation();
-
- this._rpc({
- route: '/lunch/user_location_set',
- params: {
- user_id: this.userId,
- location_id: ev.data.locationId,
- context: this.context,
- },
- }).then(function () {
- self.model._updateLocation(ev.data.locationId).then(function () {
- self.reload();
- });
- });
+ this.searchModel.dispatch('setLocationId', ev.data.locationId);
},
_onOpenWizard: function (ev) {
var self = this;
ev.stopPropagation();
- var ctx = this.userId ? {default_user_id: this.userId} : {};
+ var ctx = this.searchModel.get('userId') ? {default_user_id: this.searchModel.get('userId')} : {};
var options = {
on_close: function () {
@@ -197,7 +168,7 @@ var LunchControllerCommon = {
this._rpc({
route: '/lunch/pay',
params: {
- user_id: this.userId,
+ user_id: this.searchModel.get('userId'),
context: this.context,
},
}).then(function (isPaid) {
@@ -224,13 +195,7 @@ var LunchControllerCommon = {
},
_onUserChanged: function (ev) {
ev.stopPropagation();
-
- var self = this;
-
- this.userId = ev.data.userId;
- this.model._updateUser(ev.data.userId).then(function () {
- self.reload();
- });
+ this.searchModel.dispatch('updateUserId', ev.data.userId);
},
_onUnlinkOrder: function (ev) {
var self = this;
@@ -239,7 +204,7 @@ var LunchControllerCommon = {
this._rpc({
route: '/lunch/trash',
params: {
- user_id: this.userId,
+ user_id: this.searchModel.get('userId'),
context: this.context,
},
}).then(function () {