summaryrefslogtreecommitdiff
path: root/addons/lunch/static/src/js/lunch_kanban_controller.js
diff options
context:
space:
mode:
authorAnh Thao Pham (pta) <pta@odoo.com>2020-03-18 07:29:31 +0000
committerYannick Tivisse <yti@odoo.com>2020-04-30 11:40:39 +0000
commit8b6b09fc26dc35f57a68584a668940e1d8bde1ff (patch)
tree45a020f829e1a26b9743800af71219cd74559a5d /addons/lunch/static/src/js/lunch_kanban_controller.js
parent918a5f2cc022994ee08bead25dd79072bf3fba87 (diff)
[IMP] lunch: add list view for lunch.product.report
- Move code from kanban view that is common with list view in common files - Add action to add selected products to cart - Add/update tests closes odoo/odoo#47556 Taskid: 2160048 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/lunch/static/src/js/lunch_kanban_controller.js')
-rw-r--r--addons/lunch/static/src/js/lunch_kanban_controller.js243
1 files changed, 3 insertions, 240 deletions
diff --git a/addons/lunch/static/src/js/lunch_kanban_controller.js b/addons/lunch/static/src/js/lunch_kanban_controller.js
index 6e75d4839b3..dc370a46277 100644
--- a/addons/lunch/static/src/js/lunch_kanban_controller.js
+++ b/addons/lunch/static/src/js/lunch_kanban_controller.js
@@ -6,248 +6,11 @@ odoo.define('lunch.LunchKanbanController', function (require) {
* override of the KanbanController.
*/
-var session = require('web.session');
-var core = require('web.core');
var KanbanController = require('web.KanbanController');
-var LunchKanbanWidget = require('lunch.LunchKanbanWidget');
-var LunchPaymentDialog = require('lunch.LunchPaymentDialog');
+var LunchControllerCommon = require('lunch.LunchControllerCommon');
-var _t = core._t;
-
-var LunchKanbanController = KanbanController.extend({
- custom_events: _.extend({}, KanbanController.prototype.custom_events, {
- add_product: '_onAddProduct',
- change_location: '_onLocationChanged',
- change_user: '_onUserChanged',
- open_wizard: '_onOpenWizard',
- order_now: '_onOrderNow',
- remove_product: '_onRemoveProduct',
- unlink_order: '_onUnlinkOrder',
- }),
-
- /**
- * @override
- */
- init: function () {
- this.userId = null;
- this.editMode = false;
- this.updated = false;
- this.widgetData = null;
- this.context = session.user_context;
- return this._super.apply(this, arguments);
- },
- /**
- * @override
- */
- start: function () {
- // create a div inside o_content that will be used to wrap the lunch
- // banner and kanban renderer (this is required to get the desired
- // layout with the searchPanel to the left)
- var self = this;
- this.$('.o_content').append($('<div>').addClass('o_lunch_kanban'));
- return this._super.apply(this, arguments).then(function () {
- self.$('.o_lunch_kanban').append(self.$('.o_kanban_view'));
- });
- },
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
-
- _fetchPaymentInfo: function () {
- return this._rpc({
- route: '/lunch/payment_message',
- params: {
- context: this.context,
- },
- });
- },
- _fetchWidgetData: function () {
- var self = this;
-
- return this._rpc({
- route: '/lunch/infos',
- params: {
- user_id: this.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 lunchKanbanWidget)
- * to the searchDomain (coming from the controlPanel).
- *
- * @override
- */
- _getViewDomain: async function () {
- return this.model.getLocationDomain();
- },
- /**
- * Renders and appends the lunch banner widget.
- *
- * @private
- */
- _renderLunchKanbanWidget: function () {
- var self = this;
- var oldWidget = this.widget;
- this.widgetData.wallet = parseFloat(this.widgetData.wallet).toFixed(2);
- this.widget = new LunchKanbanWidget(this, _.extend(this.widgetData, {edit: this.editMode}));
- return this.widget.appendTo(document.createDocumentFragment()).then(function () {
- self.$('.o_lunch_kanban').prepend(self.widget.$el);
- if (oldWidget) {
- oldWidget.destroy();
- }
- });
- },
- _showPaymentDialog: function (title) {
- var self = this;
-
- title = title || '';
-
- this._fetchPaymentInfo().then(function (data) {
- var paymentDialog = new LunchPaymentDialog(self, _.extend(data, {title: title}));
- paymentDialog.open();
- });
- },
- /**
- * Override to fetch and display the lunch data. Because of the presence of
- * the searchPanel, also wrap the lunch widget and the kanban renderer into
- * a div, to get the desired layout.
- *
- * @override
- * @private
- */
- _update: function () {
- var def = this._fetchWidgetData().then(this._renderLunchKanbanWidget.bind(this));
- return Promise.all([def, this._super.apply(this, arguments)]);
- },
-
- //--------------------------------------------------------------------------
- // Handlers
- //--------------------------------------------------------------------------
-
- _onAddProduct: function (ev) {
- var self = this;
- ev.stopPropagation();
-
- this._rpc({
- model: 'lunch.order',
- method: 'update_quantity',
- args: [[ev.data.lineId], 1],
- }).then(function () {
- self.reload();
- });
- },
- _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();
- });
- });
- },
- _onOpenWizard: function (ev) {
- var self = this;
- ev.stopPropagation();
-
- var ctx = this.userId ? {default_user_id: this.userId} : {};
-
- var options = {
- on_close: function () {
- self.reload();
- },
- };
-
- // YTI TODO Maybe don't always pass the default_product_id
- var action = {
- res_model: 'lunch.order',
- name: _t('Configure Your Order'),
- type: 'ir.actions.act_window',
- views: [[false, 'form']],
- target: 'new',
- context: _.extend(ctx, {default_product_id: ev.data.productId}),
- };
-
- if (ev.data.lineId) {
- action = _.extend(action, {
- res_id: ev.data.lineId,
- context: _.extend(action.context, {
- active_id: ev.data.lineId,
- }),
- });
- }
-
- this.do_action(action, options);
- },
- _onOrderNow: function (ev) {
- var self = this;
- ev.stopPropagation();
-
- this._rpc({
- route: '/lunch/pay',
- params: {
- user_id: this.userId,
- context: this.context,
- },
- }).then(function (isPaid) {
- if (isPaid) {
- // TODO: feedback?
- self.reload();
- } else {
- self._showPaymentDialog(_t("Not enough money in your wallet"));
- self.reload();
- }
- });
- },
- _onRemoveProduct: function (ev) {
- var self = this;
- ev.stopPropagation();
-
- this._rpc({
- model: 'lunch.order',
- method: 'update_quantity',
- args: [[ev.data.lineId], -1],
- }).then(function () {
- self.reload();
- });
- },
- _onUserChanged: function (ev) {
- ev.stopPropagation();
-
- var self = this;
-
- this.userId = ev.data.userId;
- this.model._updateUser(ev.data.userId).then(function () {
- self.reload();
- });
- },
- _onUnlinkOrder: function (ev) {
- var self = this;
- ev.stopPropagation();
-
- this._rpc({
- route: '/lunch/trash',
- params: {
- user_id: this.userId,
- context: this.context,
- },
- }).then(function () {
- self.reload();
- });
- },
+var LunchKanbanController = KanbanController.extend(LunchControllerCommon , {
+ custom_events: _.extend({}, KanbanController.prototype.custom_events, LunchControllerCommon.custom_events),
});
return LunchKanbanController;