diff options
Diffstat (limited to 'addons/google_drive/static/src')
| -rw-r--r-- | addons/google_drive/static/src/css/google_drive.css | 5 | ||||
| -rw-r--r-- | addons/google_drive/static/src/img/drive_icon.png | bin | 0 -> 1542 bytes | |||
| -rw-r--r-- | addons/google_drive/static/src/img/drive_icon_mono.png | bin | 0 -> 479 bytes | |||
| -rw-r--r-- | addons/google_drive/static/src/js/gdrive.js | 93 | ||||
| -rw-r--r-- | addons/google_drive/static/src/xml/gdrive.xml | 14 |
5 files changed, 112 insertions, 0 deletions
diff --git a/addons/google_drive/static/src/css/google_drive.css b/addons/google_drive/static/src/css/google_drive.css new file mode 100644 index 00000000..ce2b2259 --- /dev/null +++ b/addons/google_drive/static/src/css/google_drive.css @@ -0,0 +1,5 @@ +li.oe_share_gdoc > a:after { + content: url('/google_drive/static/src/img/drive_icon.png'); + position: absolute; + right: 5px; +} diff --git a/addons/google_drive/static/src/img/drive_icon.png b/addons/google_drive/static/src/img/drive_icon.png Binary files differnew file mode 100644 index 00000000..1553aa31 --- /dev/null +++ b/addons/google_drive/static/src/img/drive_icon.png diff --git a/addons/google_drive/static/src/img/drive_icon_mono.png b/addons/google_drive/static/src/img/drive_icon_mono.png Binary files differnew file mode 100644 index 00000000..9fd836b6 --- /dev/null +++ b/addons/google_drive/static/src/img/drive_icon_mono.png diff --git a/addons/google_drive/static/src/js/gdrive.js b/addons/google_drive/static/src/js/gdrive.js new file mode 100644 index 00000000..d6090aa9 --- /dev/null +++ b/addons/google_drive/static/src/js/gdrive.js @@ -0,0 +1,93 @@ +odoo.define('google_drive.ActionMenus', function (require) { + "use strict"; + + const ActionMenus = require('web.ActionMenus'); + const DropdownMenuItem = require('web.DropdownMenuItem'); + + /** + * Fetches the google drive action menu item props. To do so this function + * is given its parent props and env, as well as the RPC function bound to + * the parent context. + * Note that we use the bound RPC to benefit from its added behaviour (see + * web/component_extension). + * @param {Object} props + * @param {number[]} props.activeIds + * @param {Object} props.context + * @param {Object} env + * @param {Object} env.action The current action + * @param {Object} env.view The current view + * @param {Function} rpc Bound to the ActionMenus context + * @returns {Object | boolean} item props or false + */ + async function googleDrivePropsGetter(props, env, rpc) { + const [activeId] = props.activeIds; + const { context } = props; + if (env.view.type !== "form" || !activeId) { + return false; + } + const items = await rpc({ + args: [env.action.res_model, activeId], + context, + method: 'get_google_drive_config', + model: 'google.drive.config', + }); + return Boolean(items.length) && { activeId, context, items }; + } + + /** + * 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 + */ + class GoogleDriveMenu extends DropdownMenuItem { + + //--------------------------------------------------------------------- + // Handlers + //--------------------------------------------------------------------- + + /** + * @private + * @param {number} itemId + * @returns {Promise} + */ + async _onGoogleDocItemClick(itemId) { + const resID = this.props.activeId; + 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', + }); + if (url) { + window.open(url, '_blank'); + } + } + } + GoogleDriveMenu.props = { + activeId: Number, + context: Object, + items: { + type: Array, + element: Object, + }, + }; + GoogleDriveMenu.template = 'GoogleDriveMenu'; + + ActionMenus.registry.add('google-drive-menu', { + Component: GoogleDriveMenu, + getProps: googleDrivePropsGetter, + }); + + 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 00000000..d12b3459 --- /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="props.items" 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> |
