diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/iap/static/src | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/iap/static/src')
| -rw-r--r-- | addons/iap/static/src/img/iap_logo.svg | 88 | ||||
| -rw-r--r-- | addons/iap/static/src/js/crash_manager.js | 72 | ||||
| -rw-r--r-- | addons/iap/static/src/js/iap_buy_more_credits.js | 59 | ||||
| -rw-r--r-- | addons/iap/static/src/js/iap_credit.js | 26 | ||||
| -rw-r--r-- | addons/iap/static/src/xml/iap_templates.xml | 30 |
5 files changed, 275 insertions, 0 deletions
diff --git a/addons/iap/static/src/img/iap_logo.svg b/addons/iap/static/src/img/iap_logo.svg new file mode 100644 index 00000000..e067c2f2 --- /dev/null +++ b/addons/iap/static/src/img/iap_logo.svg @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="680" + height="143" + version="1.1" + id="svg889" + sodipodi:docname="iap_logo.svg" + inkscape:version="0.92.3 (2405546, 2018-03-11)"> + <metadata + id="metadata895"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs893" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1015" + id="namedview891" + showgrid="false" + inkscape:zoom="1.9852941" + inkscape:cx="390.21297" + inkscape:cy="71.751852" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:window-maximized="1" + inkscape:current-layer="svg889" /> + <g + fill="none" + fill-rule="evenodd" + id="g887"> + <g + id="g881" + fill-rule="nonzero"> + <path + d="M397.168 143.475c-30.083 0-54.47-24.387-54.47-54.47 0-30.084 24.387-54.472 54.47-54.472 30.084 0 54.471 24.388 54.471 54.471 0 30.084-24.387 54.471-54.47 54.471zm0-22.365c17.732 0 32.106-14.375 32.106-32.106S414.9 56.9 397.168 56.9c-17.73 0-32.105 14.374-32.105 32.105 0 17.731 14.374 32.106 32.105 32.106zm-115.435 22.365c-30.083 0-54.47-24.387-54.47-54.47 0-30.084 24.387-54.472 54.47-54.472 30.084 0 54.471 24.388 54.471 54.471 0 30.084-24.387 54.471-54.47 54.471zm0-22.365c17.732 0 32.106-14.375 32.106-32.106S299.465 56.9 281.733 56.9c-17.73 0-32.105 14.374-32.105 32.105 0 17.731 14.374 32.106 32.105 32.106z" + id="path875" + fill="#888" /> + <path + d="M222.306 88.575l.001.43c0 30.083-24.387 54.47-54.47 54.47-30.084 0-54.471-24.387-54.471-54.47 0-30.084 24.387-54.472 54.47-54.472a54.23 54.23 0 0 1 32.84 11.009V10.825C200.676 4.847 205.52 0 211.498 0c5.977 0 10.822 4.851 10.822 10.825v77.191c0 .188-.005.374-.014.559zm-54.47 32.535c17.732 0 32.106-14.375 32.106-32.106S185.568 56.9 167.837 56.9c-17.732 0-32.106 14.374-32.106 32.105 0 17.731 14.374 32.106 32.106 32.106z" + id="path877" + fill="#888" /> + <path + d="M54.97 143.354C24.887 143.354.5 118.967.5 88.884.5 58.8 24.887 34.411 54.97 34.411c30.084 0 54.471 24.388 54.471 54.471 0 30.084-24.387 54.471-54.47 54.471zm-.5-22.147c17.732 0 32.106-14.374 32.106-32.106 0-17.73-14.374-32.105-32.105-32.105-17.731 0-32.105 14.374-32.105 32.105 0 17.732 14.374 32.106 32.105 32.106z" + id="path879" + fill="#9C5789" /> + </g> + <g + aria-label="IAP" + style="font-size:134px;font-family:Helvetica;letter-spacing:-4.4380002;fill:#8f8f8f" + id="text885"> + <path + d="M 503.996,45.314 H 491.4 V 143 h 12.596 z" + style="" + id="path903" /> + <path + d="m 572.41003,113.654 10.05,29.346 h 13.936 l -34.304,-97.686 h -16.08 l -34.84,97.686 h 13.266 l 10.318,-29.346 z m -3.484,-10.452 h -31.088 l 16.08,-44.488 z" + style="" + id="path905" /> + <path + d="m 618.61984,101.594 h 30.686 c 7.638,0 13.668,-2.278 18.894,-6.968 5.896,-5.36 8.442,-11.658 8.442,-20.636 0,-18.358 -10.854,-28.676 -30.15,-28.676 h -40.334 V 143 h 12.462 z m 0,-10.988 V 56.302 h 25.996 c 11.926,0 19.028,6.432 19.028,17.152 0,10.72 -7.102,17.152 -19.028,17.152 z" + style="" + id="path907" /> + </g> + </g> +</svg> diff --git a/addons/iap/static/src/js/crash_manager.js b/addons/iap/static/src/js/crash_manager.js new file mode 100644 index 00000000..11324fb6 --- /dev/null +++ b/addons/iap/static/src/js/crash_manager.js @@ -0,0 +1,72 @@ +odoo.define('iap.CrashManager', function (require) { +"use strict"; + +var ajax = require('web.ajax'); +var core = require('web.core'); +var CrashManager = require('web.CrashManager').CrashManager; +var Dialog = require('web.Dialog'); + +var _t = core._t; +var QWeb = core.qweb; + +CrashManager.include({ + /** + * Change button string depending if it's Enterprise and trial available + * (Only change the text message in the button, doesn't change IAP side validation) + * + * @param {boolean} isTrial + * @returns {string} + * @private + */ + _getButtonMessage: function (isTrial){ + var isEnterprise = _.last(odoo.session_info.server_version_info) === 'e'; + return isTrial && isEnterprise ? _t('Start a Trial at Odoo') : _t('Buy credits'); + }, + /** + * @override + */ + rpc_error: function (error) { + var self = this; + if (error.data.name === "odoo.addons.iap.tools.iap_tools.InsufficientCreditError") { + var error_data = JSON.parse(error.data.message); + ajax.jsonRpc('/web/dataset/call_kw', 'call', { + model: 'iap.account', + method: 'get_credits_url', + args: [], + kwargs: { + base_url: error_data.base_url, + service_name: error_data.service_name, + credit: error_data.credit, + trial: error_data.trial + } + }).then(function (url) { + var content = $(QWeb.render('iap.redirect_to_odoo_credit', { + data: error_data, + })); + if (error_data.body) { + content.css('padding', 0); + } + new Dialog(this, { + size: 'large', + title: error_data.title || _t("Insufficient Balance"), + $content: content, + buttons: [{ + text: self._getButtonMessage(error_data.trial), + classes : "btn-primary", + click: function () { + window.open(url, '_blank'); + }, + close:true, + }, { + text: _t("Cancel"), + close: true, + }], + }).open(); + }); + } else { + this._super.apply(this, arguments); + } + }, +}); + +}); diff --git a/addons/iap/static/src/js/iap_buy_more_credits.js b/addons/iap/static/src/js/iap_buy_more_credits.js new file mode 100644 index 00000000..a9ed1c47 --- /dev/null +++ b/addons/iap/static/src/js/iap_buy_more_credits.js @@ -0,0 +1,59 @@ +odoo.define('iap.buy_more_credits', function (require) { +'use strict'; + +var widgetRegistry = require('web.widget_registry'); +var Widget = require('web.Widget'); + +var core = require('web.core'); +var rpc = require('web.rpc'); + +var QWeb = core.qweb; + +var IAPBuyMoreCreditsWidget = Widget.extend({ + className: 'o_field_iap_buy_more_credits', + + /** + * @constructor + * Prepares the basic rendering of edit mode by setting the root to be a + * div.dropdown.open. + * @see FieldChar.init + */ + init: function (parent, data, options) { + this._super.apply(this, arguments); + this.service_name = options.attrs.service_name; + }, + + /** + * @override + */ + start: function () { + this.$widget = $(QWeb.render('iap.buy_more_credits')); + this.$buyLink = this.$widget.find('.buy_credits'); + this.$widget.appendTo(this.$el); + this.$buyLink.click(this._getLink.bind(this)); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + _getLink: function () { + var self = this; + return rpc.query({ + model: 'iap.account', + method: 'get_credits_url', + args: [this.service_name], + }, { + shadow: true, + }).then(function (url) { + return self.do_action({ + type: 'ir.actions.act_url', + url: url, + }); + }); + }, +}); + +widgetRegistry.add('iap_buy_more_credits', IAPBuyMoreCreditsWidget); + +return IAPBuyMoreCreditsWidget; +}); diff --git a/addons/iap/static/src/js/iap_credit.js b/addons/iap/static/src/js/iap_credit.js new file mode 100644 index 00000000..baabd7bd --- /dev/null +++ b/addons/iap/static/src/js/iap_credit.js @@ -0,0 +1,26 @@ +odoo.define('iap.redirect_odoo_credit_widget', function(require) { +"use strict"; + +var AbstractAction = require('web.AbstractAction'); +var core = require('web.core'); + + +var IapOdooCreditRedirect = AbstractAction.extend({ + template: 'iap.redirect_to_odoo_credit', + events : { + "click .redirect_confirm" : "odoo_redirect", + }, + init: function (parent, action) { + this._super(parent, action); + this.url = action.params.url; + }, + + odoo_redirect: function () { + window.open(this.url, '_blank'); + this.do_action({type: 'ir.actions.act_window_close'}); + // framework.redirect(this.url); + }, + +}); +core.action_registry.add('iap_odoo_credit_redirect', IapOdooCreditRedirect); +}); diff --git a/addons/iap/static/src/xml/iap_templates.xml b/addons/iap/static/src/xml/iap_templates.xml new file mode 100644 index 00000000..f35496d8 --- /dev/null +++ b/addons/iap/static/src/xml/iap_templates.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<template id="template" xml:space="preserve"> + + <!-- LAYOUT TEMPLATES --> + <div t-name="iap.redirect_to_odoo_credit"> + <t t-if="data.body"> + <div t-raw="data.body"/> + </t> + <t t-if="!data.body"> + <t t-if="data.message"> + <span t-esc="data.message"/> + </t> + <t t-if="!data.message"> + <span>Insufficient credit to perform this service.</span> + </t> + </t> + </div> + + <t t-extend="DashboardMain"> + <t t-jquery=".o_web_settings_apps" t-operation="after"> + <div class="o_web_settings_iap"></div> + </t> + </t> + + <div t-name="iap.buy_more_credits" class="mt-2 row"> + <div class="col-sm"> + <button class="btn btn-link buy_credits o-hidden-ios"><i class="fa fa-arrow-right"/> Buy credits</button> + </div> + </div> +</template> |
