summaryrefslogtreecommitdiff
path: root/muk_web_theme/static/src/js/views
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 17:14:58 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 17:14:58 +0700
commit1ca3b3df3421961caec3b747a364071c80f5c7da (patch)
tree6778a1f0f3f9b4c6e26d6d87ccde16e24da6c9d6 /muk_web_theme/static/src/js/views
parentb57188be371d36d96caac4b8d65a40745c0e972c (diff)
initial commit
Diffstat (limited to 'muk_web_theme/static/src/js/views')
-rw-r--r--muk_web_theme/static/src/js/views/form_renderer.js50
-rw-r--r--muk_web_theme/static/src/js/views/form_view.js49
-rw-r--r--muk_web_theme/static/src/js/views/kanban_column.js42
-rw-r--r--muk_web_theme/static/src/js/views/kanban_quick_create.js44
-rw-r--r--muk_web_theme/static/src/js/views/kanban_renderer.js271
5 files changed, 456 insertions, 0 deletions
diff --git a/muk_web_theme/static/src/js/views/form_renderer.js b/muk_web_theme/static/src/js/views/form_renderer.js
new file mode 100644
index 0000000..87a202d
--- /dev/null
+++ b/muk_web_theme/static/src/js/views/form_renderer.js
@@ -0,0 +1,50 @@
+/**********************************************************************************
+*
+* Copyright (c) 2017-today MuK IT GmbH.
+*
+* This file is part of MuK Grid Snippets
+* (see https://mukit.at).
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+**********************************************************************************/
+
+odoo.define('muk_web_theme.FormRenderer', function (require) {
+"use strict";
+
+const core = require('web.core');
+const config = require("web.config");
+
+const FormRenderer = require('web.FormRenderer');
+
+FormRenderer.include({
+ _renderHeaderButtons() {
+ const $buttons = this._super(...arguments);
+ if (
+ !config.device.isMobile ||
+ !$buttons.is(":has(>:not(.o_invisible_modifier))")
+ ) {
+ return $buttons;
+ }
+
+ $buttons.addClass("dropdown-menu");
+ const $dropdown = $(
+ core.qweb.render("muk_web_theme.MenuStatusbarButtons")
+ );
+ $buttons.addClass("dropdown-menu").appendTo($dropdown);
+ return $dropdown;
+ },
+});
+
+}); \ No newline at end of file
diff --git a/muk_web_theme/static/src/js/views/form_view.js b/muk_web_theme/static/src/js/views/form_view.js
new file mode 100644
index 0000000..3bd2610
--- /dev/null
+++ b/muk_web_theme/static/src/js/views/form_view.js
@@ -0,0 +1,49 @@
+/**********************************************************************************
+*
+* Copyright (c) 2017-today MuK IT GmbH.
+*
+* This file is part of MuK Grid Snippets
+* (see https://mukit.at).
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+**********************************************************************************/
+
+odoo.define('muk_web_theme.FormView', function (require) {
+"use strict";
+
+const config = require("web.config");
+
+const FormView = require('web.FormView');
+const QuickCreateFormView = require('web.QuickCreateFormView');
+
+FormView.include({
+ init() {
+ this._super(...arguments);
+ if (config.device.isMobile) {
+ this.controllerParams.disableAutofocus = true;
+ }
+ },
+});
+
+QuickCreateFormView.include({
+ init() {
+ this._super(...arguments);
+ if (config.device.isMobile) {
+ this.controllerParams.disableAutofocus = true;
+ }
+ },
+});
+
+});
diff --git a/muk_web_theme/static/src/js/views/kanban_column.js b/muk_web_theme/static/src/js/views/kanban_column.js
new file mode 100644
index 0000000..0cdc8dd
--- /dev/null
+++ b/muk_web_theme/static/src/js/views/kanban_column.js
@@ -0,0 +1,42 @@
+/**********************************************************************************
+*
+* Copyright (c) 2017-today MuK IT GmbH.
+*
+* This file is part of MuK Grid Snippets
+* (see https://mukit.at).
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+**********************************************************************************/
+
+odoo.define('muk_web_theme.KanbanColumn', function (require) {
+"use strict";
+
+const config = require('web.config');
+
+const KanbanColumn = require('web.KanbanColumn');
+
+if (!config.device.isMobile) {
+ return;
+}
+
+KanbanColumn.include({
+ init() {
+ this._super(...arguments);
+ this.recordsDraggable = false;
+ this.canBeFolded = false;
+ },
+});
+
+});
diff --git a/muk_web_theme/static/src/js/views/kanban_quick_create.js b/muk_web_theme/static/src/js/views/kanban_quick_create.js
new file mode 100644
index 0000000..b86ed52
--- /dev/null
+++ b/muk_web_theme/static/src/js/views/kanban_quick_create.js
@@ -0,0 +1,44 @@
+/**********************************************************************************
+*
+* Copyright (c) 2017-today MuK IT GmbH.
+*
+* This file is part of MuK Grid Snippets
+* (see https://mukit.at).
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+**********************************************************************************/
+
+odoo.define('muk_web_theme.kanban_column_quick_create', function (require) {
+"use strict";
+
+const config = require('web.config');
+
+const KanbanRenderer = require('web.kanban_column_quick_create');
+
+KanbanRenderer.include({
+ init() {
+ this._super(...arguments);
+ this.isMobile = config.device.isMobile;
+ },
+ _cancel() {
+ if (!config.device.isMobile) {
+ this._super(...arguments);
+ } else if (!this.folded) {
+ this.$input.val('');
+ }
+ },
+});
+
+});
diff --git a/muk_web_theme/static/src/js/views/kanban_renderer.js b/muk_web_theme/static/src/js/views/kanban_renderer.js
new file mode 100644
index 0000000..2cdd94d
--- /dev/null
+++ b/muk_web_theme/static/src/js/views/kanban_renderer.js
@@ -0,0 +1,271 @@
+/**********************************************************************************
+*
+* Copyright (c) 2017-today MuK IT GmbH.
+*
+* This file is part of MuK Grid Snippets
+* (see https://mukit.at).
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+**********************************************************************************/
+
+odoo.define('muk_web_theme.KanbanRenderer', function (require) {
+"use strict";
+
+const config = require('web.config');
+const core = require('web.core');
+
+const KanbanRenderer = require('web.KanbanRenderer');
+
+const _t = core._t;
+const qweb = core.qweb;
+
+if (!config.device.isMobile) {
+ return;
+}
+
+KanbanRenderer.include({
+ custom_events: _.extend({}, KanbanRenderer.prototype.custom_events || {}, {
+ quick_create_column_created: '_onColumnAdded',
+ }),
+ events: _.extend({}, KanbanRenderer.prototype.events, {
+ 'click .o_kanban_mobile_tab': '_onMobileTabClicked',
+ 'click .o_kanban_mobile_add_column': '_onMobileQuickCreateClicked',
+ }),
+ ANIMATE: true,
+ init() {
+ this._super.apply(this, arguments);
+ this.activeColumnIndex = 0;
+ this._scrollPosition = null;
+ },
+ on_attach_callback() {
+ if (this._scrollPosition && this.state.groupedBy.length && this.widgets.length) {
+ var $column = this.widgets[this.activeColumnIndex].$el;
+ $column.scrollLeft(this._scrollPosition.left);
+ $column.scrollTop(this._scrollPosition.top);
+ }
+ this._computeTabPosition();
+ this._super.apply(this, arguments);
+ },
+ on_detach_callback() {
+ if (this.state.groupedBy.length && this.widgets.length) {
+ var $column = this.widgets[this.activeColumnIndex].$el;
+ this._scrollPosition = {
+ left: $column.scrollLeft(),
+ top: $column.scrollTop(),
+ };
+ } else {
+ this._scrollPosition = null;
+ }
+ this._super.apply(this, arguments);
+ },
+ addQuickCreate() {
+ if(this._canCreateColumn() && !this.quickCreate.folded) {
+ this._onMobileQuickCreateClicked();
+ }
+ return this.widgets[this.activeColumnIndex].addQuickCreate();
+ },
+ updateColumn(localID) {
+ var index = _.findIndex(this.widgets, {db_id: localID});
+ var $column = this.widgets[index].$el;
+ var scrollTop = $column.scrollTop();
+ return this._super.apply(this, arguments)
+ .then(() => this._layoutUpdate(false))
+ .then(() => $column.scrollTop(scrollTop));
+ },
+ _canCreateColumn: function() {
+ return this.quickCreateEnabled && this.quickCreate && this.widgets.length;
+ },
+ _computeColumnPosition(animate) {
+ if (this.widgets.length) {
+ const rtl = _t.database.parameters.direction === 'rtl';
+ this.$('.o_kanban_group').show();
+ const $columnAfter = this._toNode(this.widgets.filter((widget, index) => index > this.activeColumnIndex));
+ const promiseAfter = this._updateColumnCss($columnAfter, rtl ? {right: '100%'} : {left: '100%'}, animate);
+ const $columnBefore = this._toNode(this.widgets.filter((widget, index) => index < this.activeColumnIndex));
+ const promiseBefore = this._updateColumnCss($columnBefore, rtl ? {right: '-100%'} : {left: '-100%'}, animate);
+ const $columnCurrent = this._toNode(this.widgets.filter((widget, index) => index === this.activeColumnIndex));
+ const promiseCurrent = this._updateColumnCss($columnCurrent, rtl ? {right: '0%'} : {left: '0%'}, animate);
+ promiseAfter
+ .then(promiseBefore)
+ .then(promiseCurrent)
+ .then(() => {
+ $columnAfter.hide();
+ $columnBefore.hide();
+ });
+ }
+ },
+ _computeCurrentColumn() {
+ if (this.widgets.length) {
+ var column = this.widgets[this.activeColumnIndex];
+ if (!column) {
+ return;
+ }
+ var columnID = column.id || column.db_id;
+ this.$('.o_kanban_mobile_tab.o_current, .o_kanban_group.o_current')
+ .removeClass('o_current');
+ this.$('.o_kanban_group[data-id="' + columnID + '"], ' +
+ '.o_kanban_mobile_tab[data-id="' + columnID + '"]')
+ .addClass('o_current');
+ }
+ },
+ _computeTabPosition() {
+ this._computeTabJustification();
+ this._computeTabScrollPosition();
+ },
+ _computeTabScrollPosition() {
+ if (this.widgets.length) {
+ var lastItemIndex = this.widgets.length - 1;
+ var moveToIndex = this.activeColumnIndex;
+ var scrollToLeft = 0;
+ for (var i = 0; i < moveToIndex; i++) {
+ var columnWidth = this._getTabWidth(this.widgets[i]);
+ if (moveToIndex !== lastItemIndex && i === moveToIndex - 1) {
+ var partialWidth = 0.75;
+ scrollToLeft += columnWidth * partialWidth;
+ } else {
+ scrollToLeft += columnWidth;
+ }
+ }
+ this.$('.o_kanban_mobile_tabs').scrollLeft(scrollToLeft);
+ }
+ },
+ _computeTabJustification() {
+ if (this.widgets.length) {
+ var self = this;
+ var widthChilds = this.widgets.reduce(function (total, column) {
+ return total + self._getTabWidth(column);
+ }, 0);
+ var $tabs = this.$('.o_kanban_mobile_tabs');
+ $tabs.toggleClass('justify-content-between', $tabs.outerWidth() >= widthChilds);
+ }
+ },
+ _enableSwipe() {
+ var self = this;
+ var step = _t.database.parameters.direction === 'rtl' ? -1 : 1;
+ this.$el.swipe({
+ excludedElements: ".o_kanban_mobile_tabs",
+ swipeLeft() {
+ var moveToIndex = self.activeColumnIndex + step;
+ if (moveToIndex < self.widgets.length) {
+ self._moveToGroup(moveToIndex, self.ANIMATE);
+ }
+ },
+ swipeRight() {
+ var moveToIndex = self.activeColumnIndex - step;
+ if (moveToIndex > -1) {
+ self._moveToGroup(moveToIndex, self.ANIMATE);
+ }
+ }
+ });
+ },
+ _getTabWidth (column) {
+ var columnID = column.id || column.db_id;
+ return this.$('.o_kanban_mobile_tab[data-id="' + columnID + '"]').outerWidth();
+ },
+ _layoutUpdate (animate) {
+ this._computeCurrentColumn();
+ this._computeTabPosition();
+ this._computeColumnPosition(animate);
+ },
+ _moveToGroup(moveToIndex, animate) {
+ if (moveToIndex < 0 || moveToIndex >= this.widgets.length) {
+ this._layoutUpdate(animate);
+ return Promise.resolve();
+ }
+ this.activeColumnIndex = moveToIndex;
+ var column = this.widgets[this.activeColumnIndex];
+ if (column.data.isOpen) {
+ this._layoutUpdate(animate);
+ } else {
+ this.trigger_up('column_toggle_fold', {
+ db_id: column.db_id,
+ onSuccess: () => this._layoutUpdate(animate)
+ });
+ }
+ this._enableSwipe();
+ return Promise.resolve();
+ },
+ _renderGrouped(fragment) {
+ var self = this;
+ var newFragment = document.createDocumentFragment();
+ this._super.apply(this, [newFragment]);
+ this.defs.push(Promise.all(this.defs).then(function () {
+ var data = [];
+ _.each(self.state.data, function (group) {
+ if (!group.value) {
+ group = _.extend({}, group, {value: _t('Undefined')});
+ data.unshift(group);
+ } else {
+ data.push(group);
+ }
+ });
+
+ var kanbanColumnContainer = document.createElement('div');
+ kanbanColumnContainer.classList.add('o_kanban_columns_content');
+ kanbanColumnContainer.appendChild(newFragment);
+ fragment.appendChild(kanbanColumnContainer);
+ $(qweb.render('KanbanView.MobileTabs', {
+ data: data,
+ quickCreateEnabled: self._canCreateColumn()
+ })).prependTo(fragment);
+ }));
+ },
+ _renderView() {
+ var self = this;
+ return this._super.apply(this, arguments).then(function () {
+ if (self.state.groupedBy.length) {
+ return self._moveToGroup(0);
+ } else {
+ if(self._canCreateColumn()) {
+ self._onMobileQuickCreateClicked();
+ }
+ return Promise.resolve();
+ }
+ });
+ },
+ _toNode(widgets) {
+ const selectorCss = widgets
+ .map(widget => '.o_kanban_group[data-id="' + (widget.id || widget.db_id) + '"]')
+ .join(', ');
+ return this.$(selectorCss);
+ },
+ _updateColumnCss($column, cssProperties, animate) {
+ if (animate) {
+ return new Promise(resolve => $column.animate(cssProperties, 'fast', resolve));
+ } else {
+ $column.css(cssProperties);
+ return Promise.resolve();
+ }
+ },
+ _onColumnAdded() {
+ this._computeTabPosition();
+ if(this._canCreateColumn() && !this.quickCreate.folded) {
+ this.quickCreate.toggleFold();
+ }
+ },
+ _onMobileQuickCreateClicked: function() {
+ this.$('.o_kanban_group').toggle();
+ this.quickCreate.toggleFold();
+ },
+ _onMobileTabClicked(event) {
+ if(this._canCreateColumn() && !this.quickCreate.folded) {
+ this.quickCreate.toggleFold();
+ }
+ this._moveToGroup($(event.currentTarget).index(), true);
+ },
+ _renderExampleBackground() {},
+});
+
+}); \ No newline at end of file