From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/iap/static/src/img/iap_logo.svg | 88 ++++++++++++++++++++++++ addons/iap/static/src/js/crash_manager.js | 72 +++++++++++++++++++ addons/iap/static/src/js/iap_buy_more_credits.js | 59 ++++++++++++++++ addons/iap/static/src/js/iap_credit.js | 26 +++++++ addons/iap/static/src/xml/iap_templates.xml | 30 ++++++++ 5 files changed, 275 insertions(+) create mode 100644 addons/iap/static/src/img/iap_logo.svg create mode 100644 addons/iap/static/src/js/crash_manager.js create mode 100644 addons/iap/static/src/js/iap_buy_more_credits.js create mode 100644 addons/iap/static/src/js/iap_credit.js create mode 100644 addons/iap/static/src/xml/iap_templates.xml (limited to 'addons/iap/static/src') 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 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + 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 @@ + + -- cgit v1.2.3