summaryrefslogtreecommitdiff
path: root/addons/google_drive/static
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-03-11 09:38:29 +0000
committerJulien Mougenot <jum@odoo.com>2020-03-13 14:08:33 +0000
commite68d3bb09d1f844387ceb20aa76022ace48507d9 (patch)
treed238fa35dcb11e5628112377a9daf569405ca74b /addons/google_drive/static
parent18e5416636b19b0953b1e6e26bfaeab1ebecce4c (diff)
[REF] *: Adapt all modules to new control panel
Adaptation of the code throughout all modules to properly instantiate the newly refactored control panel and update it accordingly. Part of task 2196029 Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/google_drive/static')
-rw-r--r--addons/google_drive/static/src/js/gdrive.js168
-rw-r--r--addons/google_drive/static/src/xml/gdrive.xml14
2 files changed, 88 insertions, 94 deletions
diff --git a/addons/google_drive/static/src/js/gdrive.js b/addons/google_drive/static/src/js/gdrive.js
index 7ed0487e84d..03d8e798229 100644
--- a/addons/google_drive/static/src/js/gdrive.js
+++ b/addons/google_drive/static/src/js/gdrive.js
@@ -1,110 +1,90 @@
-odoo.define('google_drive.sidebar', function (require) {
-"use strict";
+odoo.define('google_drive.ActionMenus', function (require) {
+ "use strict";
-/**
- * The purpose of this file is to include the Sidebar widget to add Google
- * Drive related items.
- */
+ const ActionMenus = require('web.ActionMenus');
+ const DropdownMenuItem = require('web.DropdownMenuItem');
-var Sidebar = require('web.Sidebar');
-
-
-Sidebar.include({
- // TO DO: clean me in master
/**
- * @override
+ * Google drive menu
+ *
+ * This component is actually a set of list items used to enrich the ActionMenus's
+ * "Action" dropdown list (@see ActionMenus). It will fetch
+ * the current user's google drive configuration and set the result as its
+ * items if any.
+ * @extends DropdownMenuItem
*/
- start: function () {
- var def;
- if (this.options.viewType === "form") {
- def = this._addGoogleDocItems(this.env.model, this.env.activeIds[0]);
+ class GoogleDriveMenu extends DropdownMenuItem {
+
+ async willStart() {
+ if (this.env.view.type === "form" && this.props.activeIds[0]) {
+ this.gdriveItems = await this._getGoogleDocItems();
+ } else {
+ this.gdriveItems = [];
+ }
}
- return Promise.resolve(def).then(this._super.bind(this));
- },
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
+ //---------------------------------------------------------------------
+ // Private
+ //---------------------------------------------------------------------
- /**
- * @private
- * @param {string} model
- * @param {integer} resID
- * @returns {Promise}
- */
- _addGoogleDocItems: function (model, resID) {
- var self = this;
- if (!resID) {
- return Promise.resolve();
- }
- var gdoc_item = _.indexOf(_.pluck(self.items.other, 'classname'), 'oe_share_gdoc');
- if (gdoc_item !== -1) {
- self.items.other.splice(gdoc_item, 1);
+ /**
+ * @private
+ * @returns {Promise<Object[]>}
+ */
+ async _getGoogleDocItems() {
+ const items = await this.rpc({
+ args: [this.env.action.res_model, this.props.activeIds[0]],
+ context: this.props.context,
+ method: 'get_google_drive_config',
+ model: 'google.drive.config',
+ });
+ return items;
}
- return this._rpc({
- args: [this.env.model, resID],
- context: this.env.context,
- method: 'get_google_drive_config',
- model: 'google.drive.config',
- }).then(function (r) {
- if (!_.isEmpty(r)) {
- _.each(r, function (res) {
- var already_there = false;
- for (var i = 0; i < self.items.other.length; i++) {
- var item = self.items.other[i];
- if (item.classname === 'oe_share_gdoc' && item.label.indexOf(res.name) > -1) {
- already_there = true;
- break;
- }
- }
- if (!already_there) {
- self._addItems('other', [{
- callback: self._onGoogleDocItemClicked.bind(self, res.id),
- classname: 'oe_share_gdoc',
- config_id: res.id,
- label: res.name,
- res_id: resID,
- res_model: model,
- }]);
- }
- });
- }
- });
- },
- //--------------------------------------------------------------------------
- // Handlers
- //--------------------------------------------------------------------------
+ //---------------------------------------------------------------------
+ // Handlers
+ //---------------------------------------------------------------------
- /**
- * @private
- * @param {integer} configID
- * @param {integer} resID
- */
- _onGoogleDocItemClicked: function (configID) {
- var self = this;
- var resID = this.env.activeIds[0];
- var domain = [['id', '=', configID]];
- var fields = ['google_drive_resource_id', 'google_drive_client_id'];
- this._rpc({
- args: [domain, fields],
- method: 'search_read',
- model: 'google.drive.config',
- }).then(function (configs) {
- self._rpc({
- args: [configID, resID, configs[0].google_drive_resource_id],
- context: self.env.context,
+ /**
+ * @private
+ * @param {number} itemId
+ * @returns {Promise}
+ */
+ async _onGoogleDocItemClick(itemId) {
+ const resID = this.props.activeIds[0];
+ const domain = [['id', '=', itemId]];
+ const fields = ['google_drive_resource_id', 'google_drive_client_id'];
+ const configs = await this.rpc({
+ args: [domain, fields],
+ method: 'search_read',
+ model: 'google.drive.config',
+ });
+ const url = await this.rpc({
+ args: [itemId, resID, configs[0].google_drive_resource_id],
+ context: this.props.context,
method: 'get_google_drive_url',
model: 'google.drive.config',
- }).then(function (url) {
- if (url){
- window.open(url, '_blank');
- }
});
- });
- },
+ if (url) {
+ window.open(url, '_blank');
+ }
+ }
+ }
+ GoogleDriveMenu.props = {
+ activeIds: Array,
+ context: Object,
+ };
+ GoogleDriveMenu.template = 'GoogleDriveMenu';
-});
+ ActionMenus.registry.add('google-drive-menu', {
+ Component: GoogleDriveMenu,
+ getProps(parentProps) {
+ return {
+ activeIds: parentProps.activeIds,
+ context: parentProps.context,
+ };
+ },
+ });
-return Sidebar;
+ return GoogleDriveMenu;
});
diff --git a/addons/google_drive/static/src/xml/gdrive.xml b/addons/google_drive/static/src/xml/gdrive.xml
new file mode 100644
index 00000000000..48ce57494c9
--- /dev/null
+++ b/addons/google_drive/static/src/xml/gdrive.xml
@@ -0,0 +1,14 @@
+<templates>
+ <t t-name="GoogleDriveMenu" owl="1">
+ <li>
+ <ul class="o_embed_menu">
+ <li t-foreach="gdriveItems" t-as="gdriveItem" t-key="gdriveItem.id"
+ role="menuitem"
+ class="o_menu_item oe_share_gdoc_item dropdown-item"
+ >
+ <a href="#" t-esc="gdriveItem.name" t-on-click.prevent="_onGoogleDocItemClick(gdriveItem.id)"/>
+ </li>
+ </ul>
+ </li>
+ </t>
+</templates>