summaryrefslogtreecommitdiff
path: root/addons/website/static/src/snippets/s_progress_bar/options.js
diff options
context:
space:
mode:
authorBenjamin Vray <bvr@odoo.com>2020-03-03 10:01:29 +0000
committerqsm-odoo <qsm@odoo.com>2020-03-24 16:07:14 +0000
commitefe8ea267624930e0b634b063d4e4aa4daab674b (patch)
treecd4dddace19a765b96f1fb2cccbbd881c989fd72 /addons/website/static/src/snippets/s_progress_bar/options.js
parentc87f61d26b432c9355b0b75ecd16059a946f2eae (diff)
[IMP] website: review progress bar snippet
Add an input field to define the value of the progress bar instead of the previous system by mousedown. Disable animated by default. Part of https://github.com/odoo/odoo/pull/46503 task-2194309
Diffstat (limited to 'addons/website/static/src/snippets/s_progress_bar/options.js')
-rw-r--r--addons/website/static/src/snippets/s_progress_bar/options.js73
1 files changed, 20 insertions, 53 deletions
diff --git a/addons/website/static/src/snippets/s_progress_bar/options.js b/addons/website/static/src/snippets/s_progress_bar/options.js
index 06644e3f168..d3f544a0515 100644
--- a/addons/website/static/src/snippets/s_progress_bar/options.js
+++ b/addons/website/static/src/snippets/s_progress_bar/options.js
@@ -2,20 +2,12 @@ odoo.define('website.s_progress_bar_options', function (require) {
'use strict';
const core = require('web.core');
+const utils = require('web.utils');
const options = require('web_editor.snippets.options');
const _t = core._t;
options.registry.progress = options.Class.extend({
- /**
- * @override
- */
- start: function () {
- if (this.$overlay) {
- this._bindMoveProgress();
- }
- this._super();
- },
//--------------------------------------------------------------------------
// Options
@@ -47,6 +39,22 @@ options.registry.progress = options.Class.extend({
$text.insertBefore(this.$target.find('.progress'));
}
},
+ /**
+ * Sets the progress bar value.
+ *
+ * @see this.selectClass for parameters
+ */
+ progressBarValue: function (previewMode, widgetValue, params) {
+ let value = parseInt(widgetValue);
+ value = utils.confine(value, 0, 100);
+ const $progressBar = this.$target.find('.progress-bar');
+ const $progressBarText = this.$target.find('.s_progress_bar_text');
+ // Target precisely the XX% not only XX to not replace wrong element
+ // eg 'Since 1978 we have completed 45%' <- don't replace 1978
+ $progressBarText.text($progressBarText.text().replace(/[0-9]+%/, value + '%'));
+ $progressBar.attr("aria-valuenow", value);
+ $progressBar.css("width", value + "%");
+ },
//--------------------------------------------------------------------------
// Private
@@ -62,52 +70,11 @@ options.registry.progress = options.Class.extend({
.parent('.progress-bar').length;
return isInline ? 'inline' : 'below';
}
+ case 'progressBarValue': {
+ return this.$target.find('.progress-bar').attr('aria-valuenow') + '%';
+ }
}
return this._super(...arguments);
},
- /**
- * Binds the editor padding feature to the progress bar width.
- */
- _bindMoveProgress: function () {
- var self = this;
- var $e = this.$overlay.find(".o_handle.e").removeClass("readonly");
- const $progressBar = this.$target.find('.progress-bar');
- const $parent = $progressBar.parent();
- var pos = $parent.offset();
- var width = $parent.width();
- var time;
- function move(event) {
- clearTimeout(time);
- time = setTimeout(function () {
- var value = (event.clientX - pos.left) / width * 100 | 0;
- if (value > 100) {
- value = 100;
- }
- if (value < 0) {
- value = 0;
- }
- const $progressBarText = self.$target.find('.s_progress_bar_text');
- // Target precisely the XX% not only XX to not replace wrong element
- // eg 'Since 1978 we have completed 45%' <- don't replace 1978
- $progressBarText.text($progressBarText.text().replace(/[0-9]+%/, value + '%'));
- $progressBar.attr("data-value", value);
- $progressBar.attr("aria-valuenow", value);
- if (value < 3) {
- value = 3;
- }
- $progressBar.css("width", value + "%");
- }, 5);
- }
- $e.on("mousedown", function () {
- self.$overlay.addClass('d-none');
- $(document)
- .on("mousemove", move)
- .one("mouseup", function () {
- self.$overlay.removeClass('d-none');
- $(document).off("mousemove", move);
- self.trigger_up('cover_update');
- });
- });
- },
});
});