summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields/upgrade_fields.js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-03-05 10:05:56 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit905e01921f3c3ef43ace6fc537d1d8c0d280002c (patch)
tree265c43ab21c5401a5d9f0f3d64d86f1ac417451c /addons/web/static/src/js/fields/upgrade_fields.js
parent54d4c73af4ad05c7640d28c1892247c9538b8017 (diff)
[REF] web, *: redesign all JS views
This commit introduce a full redesign of all JS views. We started basically from scratch. The goal was to unify all the various views under a common framework, to make them testable, to make then usable in different conditions (in studio, or in the frontend), and to make our lives easier. Some important points are: - we introduced new coding guidelines (camelCase, 80 chars width, ...) - we have a brand new testing framework (still QUnit based) - kanban view moved to the web addon - calendar view (formerly web_calender) moved to web as well - the tree view was removed - all new code should be documented We hope that this code is the start of a new era for the Odoo web client, we want to have a high quality codebase, well documented, well tested, well designed. Work done by the framework team: mostly aab, ged, chm, dmo, qsm
Diffstat (limited to 'addons/web/static/src/js/fields/upgrade_fields.js')
-rw-r--r--addons/web/static/src/js/fields/upgrade_fields.js177
1 files changed, 177 insertions, 0 deletions
diff --git a/addons/web/static/src/js/fields/upgrade_fields.js b/addons/web/static/src/js/fields/upgrade_fields.js
new file mode 100644
index 00000000000..8d72cecf391
--- /dev/null
+++ b/addons/web/static/src/js/fields/upgrade_fields.js
@@ -0,0 +1,177 @@
+odoo.define('web.upgrade_widgets', function (require) {
+"use strict";
+
+/**
+ * The upgrade widgets are intended to be used in config settings.
+ * When checked, an upgrade popup is showed to the user.
+ */
+
+var basic_fields = require('web.basic_fields');
+var core = require('web.core');
+var Dialog = require('web.Dialog');
+var field_registry = require('web.field_registry');
+var framework = require('web.framework');
+var relational_fields = require('web.relational_fields');
+
+var _t = core._t;
+var QWeb = core.qweb;
+
+var FieldBoolean = basic_fields.FieldBoolean;
+var FieldRadio = relational_fields.FieldRadio;
+
+
+/**
+ * Mixin that defines the common functions shared between Boolean and Radio
+ * upgrade widgets
+ */
+var AbstractFieldUpgrade = {
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * Redirects the user to the odoo-enterprise/uprade page
+ *
+ * @private
+ * @returns {Deferred}
+ */
+ _confirmUpgrade: function () {
+ var args = [[["share", "=", false]]];
+ return this.performModelRPC('res.users', 'search_count', args).then(function (data) {
+ framework.redirect("https://www.odoo.com/odoo-enterprise/upgrade?num_users=" + data);
+ });
+ },
+ /**
+ * This function is meant to be overriden to insert the 'Enterprise' label
+ * JQuery node at the right place.
+ *
+ * @abstract
+ * @private
+ * @param {JQuery} the 'Enterprise' label to insert
+ */
+ _insertEnterpriseLabel: function ($enterprise_label) {},
+ /**
+ * Opens the Upgrade dialog.
+ *
+ * @private
+ */
+ _openDialog: function () {
+ var message = $(QWeb.render('EnterpriseUpgrade'));
+
+ var buttons = [
+ {
+ text: _t("Upgrade now"),
+ classes: 'btn-primary',
+ close: true,
+ click: this._confirmUpgrade.bind(this),
+ },
+ {
+ text: _t("Cancel"),
+ close: true,
+ },
+ ];
+
+ new Dialog(this, {
+ size: 'medium',
+ buttons: buttons,
+ $content: $('<div>', {
+ html: message,
+ }),
+ title: _t("Odoo Enterprise"),
+ }).open();
+ },
+ /**
+ * @override
+ * @private
+ */
+ _render: function () {
+ this._super.apply(this, arguments);
+ this._insertEnterpriseLabel($("<span>", {
+ text: "Enterprise",
+ 'class': "label label-primary oe_inline"
+ }));
+ },
+ /**
+ * This function is meant to be overriden to reset the $el to its initial
+ * state.
+ *
+ * @abstract
+ * @private
+ */
+ _resetValue: function () {},
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @param {MouseEvent}
+ */
+ _onInputClicked: function (event) {
+ if ($(event.currentTarget).prop("checked")) {
+ this._openDialog().on('closed', this, this._resetValue.bind(this));
+ }
+ },
+
+};
+
+var UpgradeBoolean = FieldBoolean.extend(AbstractFieldUpgrade, {
+ events: _.extend({}, FieldBoolean.prototype.events, {
+ 'click input': '_onInputClicked',
+ }),
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ */
+ _insertEnterpriseLabel: function ($enterprise_label) {
+ this.$el.append('&nbsp;').append($enterprise_label);
+ },
+ /**
+ * @override
+ */
+ _resetValue: function () {
+ this.$input.prop("checked", false).change();
+ },
+});
+
+var UpgradeRadio = FieldRadio.extend(AbstractFieldUpgrade, {
+ events: _.extend({}, FieldRadio.prototype.events, {
+ 'click input:last': '_onInputClicked',
+ }),
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
+ isSet: function () {
+ return true;
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ */
+ _insertEnterpriseLabel: function ($enterprise_label) {
+ this.$('label').last().append('&nbsp;').append($enterprise_label);
+ },
+ /**
+ * @override
+ */
+ _resetValue: function () {
+ this.$('input').first().prop("checked", true).click();
+ },
+});
+
+
+field_registry
+ .add('upgrade_boolean', UpgradeBoolean)
+ .add('upgrade_radio', UpgradeRadio);
+
+});