summaryrefslogtreecommitdiff
path: root/addons/lunch/static/src/js/lunch_model_extension.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/lunch/static/src/js/lunch_model_extension.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/lunch/static/src/js/lunch_model_extension.js')
-rw-r--r--addons/lunch/static/src/js/lunch_model_extension.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/addons/lunch/static/src/js/lunch_model_extension.js b/addons/lunch/static/src/js/lunch_model_extension.js
new file mode 100644
index 00000000..aec64b97
--- /dev/null
+++ b/addons/lunch/static/src/js/lunch_model_extension.js
@@ -0,0 +1,100 @@
+odoo.define("lunch/static/src/js/lunch_model_extension.js", function (require) {
+ "use strict";
+
+ const ActionModel = require("web/static/src/js/views/action_model.js");
+
+ class LunchModelExtension extends ActionModel.Extension {
+
+ //---------------------------------------------------------------------
+ // Public
+ //---------------------------------------------------------------------
+
+ /**
+ * @override
+ * @returns {any}
+ */
+ get(property) {
+ switch (property) {
+ case "domain": return this.getDomain();
+ case "userId": return this.state.userId;
+ }
+ }
+
+ /**
+ * @override
+ */
+ async load() {
+ await this._updateLocationId();
+ }
+
+ /**
+ * @override
+ */
+ prepareState() {
+ Object.assign(this.state, {
+ locationId: null,
+ userId: null,
+ });
+ }
+
+ //---------------------------------------------------------------------
+ // Actions / Getters
+ //---------------------------------------------------------------------
+
+ /**
+ * @returns {Array[] | null}
+ */
+ getDomain() {
+ if (this.state.locationId) {
+ return [["is_available_at", "in", [this.state.locationId]]];
+ }
+ return null;
+ }
+
+ /**
+ * @param {number} locationId
+ * @returns {Promise}
+ */
+ setLocationId(locationId) {
+ this.state.locationId = locationId;
+ this.env.services.rpc({
+ route: "/lunch/user_location_set",
+ params: {
+ context: this.env.session.user_context,
+ location_id: this.state.locationId,
+ user_id: this.state.userId,
+ },
+ });
+ }
+
+ /**
+ * @param {number} userId
+ * @returns {Promise}
+ */
+ updateUserId(userId) {
+ this.state.userId = userId;
+ this.shouldLoad = true;
+ }
+
+ //---------------------------------------------------------------------
+ // Private
+ //---------------------------------------------------------------------
+
+ /**
+ * @returns {Promise}
+ */
+ async _updateLocationId() {
+ this.state.locationId = await this.env.services.rpc({
+ route: "/lunch/user_location_get",
+ params: {
+ context: this.env.session.user_context,
+ user_id: this.state.userId,
+ },
+ });
+ }
+ }
+
+ ActionModel.registry.add("Lunch", LunchModelExtension, 20);
+
+ return LunchModelExtension;
+});