summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2018-04-18 16:14:28 +0200
committerqsm-odoo <qsm@odoo.com>2018-04-18 16:14:28 +0200
commite41bcb0e311bfa67c78a13e377ae5c4931ecf24e (patch)
tree1bd69ec3142313684ee089d632fd9394f6f2fd16 /addons/web/static/src/js
parent5ea27d471e3c4458361b2fc9862e9a4474b1278b (diff)
parent16ddf4ae541e88bbd9ee0e40672d119b07922563 (diff)
[MERGE] *: use SCSS as language for design (instead of LESS)
The main reason this is done is to prepare the migration to bootstrap 4. It has other advantages though, like speed to compute the css and more convenient language features (if/else/maps/...). Detailed information about this merge can be found in the merge's sub-commits.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/core/dialog.js18
-rw-r--r--addons/web/static/src/js/core/dom.js7
-rw-r--r--addons/web/static/src/js/views/basic/basic_renderer.js32
-rw-r--r--addons/web/static/src/js/views/form/form_controller.js19
-rw-r--r--addons/web/static/src/js/views/form/form_renderer.js39
-rw-r--r--addons/web/static/src/js/views/list/list_controller.js4
-rw-r--r--addons/web/static/src/js/views/list/list_renderer.js12
-rw-r--r--addons/web/static/src/js/widgets/data_export.js2
8 files changed, 75 insertions, 58 deletions
diff --git a/addons/web/static/src/js/core/dialog.js b/addons/web/static/src/js/core/dialog.js
index 5ba24f57cad..7d4796886b7 100644
--- a/addons/web/static/src/js/core/dialog.js
+++ b/addons/web/static/src/js/core/dialog.js
@@ -158,9 +158,9 @@ var Dialog = Widget.extend({
/**
* Show a dialog
- *
+ *
* @param {Object} options
- * @param {boolean} options.shouldFocusButtons if true, put the focus on
+ * @param {boolean} options.shouldFocusButtons if true, put the focus on
* the first button primary when the dialog opens
*/
open: function (options) {
@@ -194,7 +194,7 @@ var Dialog = Widget.extend({
if (this.isDestroyed()) {
return;
}
- var isFocusSet = this._focusOnClose();
+ var isFocusSet = this._focusOnClose();
this._super();
@@ -214,7 +214,7 @@ var Dialog = Widget.extend({
}
},
/**
- * adds the keydown behavior to the dialogs after external files modifies
+ * adds the keydown behavior to the dialogs after external files modifies
* its DOM.
*/
rebindButtonBehavior: function () {
@@ -226,7 +226,7 @@ var Dialog = Widget.extend({
/**
* Manages the focus when the dialog closes. The default behavior is to set the focus on the top-most opened popup.
* The goal of this function is to be overridden by all children of the dialog class.
- *
+ *
* @returns: boolean should return true if the focus has already been set else false.
*/
_focusOnClose: function() {
@@ -237,7 +237,7 @@ var Dialog = Widget.extend({
//--------------------------------------------------------------------------
/**
* Moves the focus to the first button primary in the footer of the dialog
- *
+ *
* @private
* @param {odooEvent} e
*/
@@ -250,17 +250,17 @@ var Dialog = Widget.extend({
}
},
/**
- * Manages the TAB key on the buttons. If you the focus is on a primary
+ * Manages the TAB key on the buttons. If you the focus is on a primary
* button and the users tries to tab to go to the next button, display
* a tooltip
- *
+ *
* @param {jQueryEvent} e
* @private
*/
_onFooterButtonKeyDown: function (e) {
switch(e.which) {
case $.ui.keyCode.TAB:
- if (!e.shiftKey && (e.target.classList.contains("btn-primary") || e.target.classList.contains("oe_highlight"))) {
+ if (!e.shiftKey && e.target.classList.contains("btn-primary")) {
e.preventDefault();
var $primaryButton = $(e.target);
$primaryButton.tooltip({
diff --git a/addons/web/static/src/js/core/dom.js b/addons/web/static/src/js/core/dom.js
index 274f82bcc53..5335ef8e954 100644
--- a/addons/web/static/src/js/core/dom.js
+++ b/addons/web/static/src/js/core/dom.js
@@ -221,7 +221,12 @@ return {
renderButton: function (options) {
var params = options.attrs || {};
params.type = params.type || 'button';
- params.class = 'btn btn-' + (options.size || 'sm') + ' ' + (params.class || 'btn-default');
+ var classes = 'btn-default';
+ if (params.class) {
+ classes = params.class.replace(/\boe_highlight\b/g, 'btn-primary')
+ .replace(/\boe_link\b/g, 'btn-link');
+ }
+ params.class = 'btn btn-' + (options.size || 'sm') + ' ' + classes;
var $button = $('<button/>', params);
if (options.icon) {
if (options.icon.substr(0, 3) === 'fa-') {
diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js
index 80cdd05bff5..c05d467052e 100644
--- a/addons/web/static/src/js/views/basic/basic_renderer.js
+++ b/addons/web/static/src/js/views/basic/basic_renderer.js
@@ -356,6 +356,9 @@ var BasicRenderer = AbstractRenderer.extend({
* @param {Object} node
*/
_handleAttributes: function ($el, node) {
+ if ($el.is('button')) {
+ return;
+ }
if (node.attrs.class) {
$el.addClass(node.attrs.class);
}
@@ -515,6 +518,35 @@ var BasicRenderer = AbstractRenderer.extend({
});
},
/**
+ * Renders a button according to a given node element.
+ *
+ * @private
+ * @param {Object} node
+ * @param {Object} [options]
+ * @param {string} [options.extraClass]
+ * @param {boolean} [options.textAsTitle=false]
+ * @returns {jQuery}
+ */
+ _renderButtonFromNode: function (node, options) {
+ var btnOptions = {
+ attrs: _.omit(node.attrs, 'icon', 'string', 'type', 'name', 'attrs', 'modifiers', 'options'),
+ icon: node.attrs.icon,
+ };
+ if (options && options.extraClass) {
+ var classes = btnOptions.attrs.class ? btnOptions.attrs.class.split(' ') : [];
+ btnOptions.attrs.class = _.uniq(classes.concat(options.extraClass.split(' '))).join(' ');
+ }
+ var str = (node.attrs.string || '').replace(/_/g, '');
+ if (str) {
+ if (options && options.textAsTitle) {
+ btnOptions.attrs.title = str;
+ } else {
+ btnOptions.text = str;
+ }
+ }
+ return dom.renderButton(btnOptions);
+ },
+ /**
* Instantiates the appropriate AbstractField specialization for the given
* node and prepares its rendering and addition to the DOM. Indeed, the
* rendering of the widget will be started and the associated deferred will
diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js
index e66194dcf99..dbb64dc3682 100644
--- a/addons/web/static/src/js/views/form/form_controller.js
+++ b/addons/web/static/src/js/views/form/form_controller.js
@@ -50,8 +50,9 @@ var FormController = BasicController.extend({
autofocus: function () {
if (!this.disableAutofocus) {
var isControlActivted = this.renderer.autofocus();
- if (!isControlActivted) {
- // this can happen in read mode if there are no button with class oe_highlight
+ if (!isControlActivted) {
+ // this can happen in read mode if there are no buttons with
+ // btn-primary class
if (this.$buttons && this.mode === 'readonly') {
return this.$buttons.find('.o_form_button_edit').focus();
}
@@ -239,7 +240,7 @@ var FormController = BasicController.extend({
/**
* Assign on the buttons save and discard additionnal behavior to facilitate
* the work of the users doing input only using the keyboard
- *
+ *
* @param {jQueryElement} $saveCancelButtonContainer The div containing the
* save and cancel buttons
* @private
@@ -257,9 +258,7 @@ var FormController = BasicController.extend({
self._discardChanges.apply(self);
break;
case $.ui.keyCode.TAB:
- if (!e.shiftKey &&
- (e.target.classList.contains("btn-primary") ||
- e.target.classList.contains("oe_highlight"))) {
+ if (!e.shiftKey && e.target.classList.contains("btn-primary")) {
$saveCancelButtonContainer.tooltip('show');
e.preventDefault();
}
@@ -491,11 +490,11 @@ var FormController = BasicController.extend({
*/
_onDoAction: function (event) {
var self=this;
- // A priori, different widgets could write on the "on_success" key.
+ // A priori, different widgets could write on the "on_success" key.
// Below we ensure that all the actions required by those widgets
// are executed in a suitable order before every cycle of destruction.
var callback = event.data.on_success || function () {};
- event.data.on_success = function () {
+ event.data.on_success = function () {
callback();
function isDialog (widget) {
return (widget instanceof Dialog);
@@ -542,7 +541,7 @@ var FormController = BasicController.extend({
},
/**
* Set the focus on the first primary button of the controller (likely Edit)
- *
+ *
* @private
* @param {OdooEvent} event
*/
@@ -554,7 +553,7 @@ var FormController = BasicController.extend({
},
/**
* Reset the focus on the control that openned a Dialog after it was closed
- *
+ *
* @private
* @param {OdooEvent} event
*/
diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js
index eb9ea1f5907..5a6ba2de9f1 100644
--- a/addons/web/static/src/js/views/form/form_renderer.js
+++ b/addons/web/static/src/js/views/form/form_renderer.js
@@ -55,7 +55,7 @@ var FormRenderer = BasicRenderer.extend({
*/
autofocus: function () {
if (this.mode === 'readonly') {
- var firstPrimaryFormButton = this.$el.find('button.oe_highlight:enabled:visible:first()');
+ var firstPrimaryFormButton = this.$el.find('button.btn-primary:enabled:visible:first()');
if (firstPrimaryFormButton.length > 0) {
return firstPrimaryFormButton.focus();
} else {
@@ -345,7 +345,7 @@ var FormRenderer = BasicRenderer.extend({
folded_buttons = [];
}
- // Toggle class to tell if the button box is full (LESS requirement)
+ // Toggle class to tell if the button box is full (CSS requirement)
var full = (visible_buttons.length > nb_buttons);
$result.toggleClass('o_full', full).toggleClass('o_not_full', !full);
@@ -356,10 +356,11 @@ var FormRenderer = BasicRenderer.extend({
// Add the dropdown with folded buttons if any
if (folded_buttons.length) {
- $result.append($("<button>", {
- type: 'button',
- 'class': "btn btn-sm oe_stat_button o_button_more dropdown-toggle",
- 'data-toggle': "dropdown",
+ $result.append(dom.renderButton({
+ attrs: {
+ class: 'oe_stat_button o_button_more dropdown-toggle',
+ 'data-toggle': 'dropdown',
+ },
text: _t("More"),
}));
@@ -392,9 +393,8 @@ var FormRenderer = BasicRenderer.extend({
* @returns {jQueryElement}
*/
_renderHeaderButton: function (node) {
- var $button = $('<button>')
- .text(node.attrs.string)
- .addClass('btn btn-sm btn-default');
+ var $button = this._renderButtonFromNode(node);
+
this._addOnClickAction($button, node);
this._handleAttributes($button, node);
this._registerModifiers(node, this.state, $button);
@@ -582,18 +582,9 @@ var FormRenderer = BasicRenderer.extend({
* @returns {jQueryElement}
*/
_renderStatButton: function (node) {
- var $button = $('<button>').addClass('btn btn-sm oe_stat_button');
- if (node.attrs.icon) {
- $('<div>')
- .addClass('fa fa-fw o_button_icon')
- .addClass(node.attrs.icon)
- .appendTo($button);
- }
- if (node.attrs.string) {
- $('<span>')
- .text(node.attrs.string)
- .appendTo($button);
- }
+ var $button = this._renderButtonFromNode(node, {
+ extraClass: 'oe_stat_button',
+ });
$button.append(_.map(node.children, this._renderNode.bind(this)));
this._addOnClickAction($button, node);
this._handleAttributes($button, node);
@@ -633,11 +624,7 @@ var FormRenderer = BasicRenderer.extend({
* @returns {jQueryElement}
*/
_renderTagButton: function (node) {
- var $button = dom.renderButton({
- attrs: _.omit(node.attrs, 'icon', 'string'),
- icon: node.attrs.icon,
- text: (node.attrs.string || '').replace(/_/g, ''),
- });
+ var $button = this._renderButtonFromNode(node);
$button.append(_.map(node.children, this._renderNode.bind(this)));
this._addOnClickAction($button, node);
this._handleAttributes($button, node);
diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js
index 3262196fa51..b42da9665ad 100644
--- a/addons/web/static/src/js/views/list/list_controller.js
+++ b/addons/web/static/src/js/views/list/list_controller.js
@@ -232,7 +232,7 @@ var ListController = BasicController.extend({
},
/**
* Assign on the buttons create additionnal behavior to facilitate the work of the users doing input only using the keyboard
- *
+ *
* @param {jQueryElement} $createButton The create button itself
*/
_assignCreateKeyboardBehavior: function($createButton) {
@@ -249,7 +249,7 @@ var ListController = BasicController.extend({
self.renderer.giveFocus();
break;
case $.ui.keyCode.TAB:
- if (!e.shiftKey && (e.target.classList.contains("btn-primary") || e.target.classList.contains("oe_highlight"))) {
+ if (!e.shiftKey && e.target.classList.contains("btn-primary")) {
e.preventDefault();
$createButton.tooltip('show');
}
diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js
index 54f556e474b..a304bd0a597 100644
--- a/addons/web/static/src/js/views/list/list_renderer.js
+++ b/addons/web/static/src/js/views/list/list_renderer.js
@@ -312,16 +312,10 @@ var ListRenderer = BasicRenderer.extend({
* @returns {jQuery} a <button> element
*/
_renderButton: function (record, node) {
- var $button = $('<button>', {
- type: 'button',
- title: node.attrs.string,
+ var $button = this._renderButtonFromNode(node, {
+ extraClass: node.attrs.icon ? 'o_icon_button' : undefined,
+ textAsTitle: !!node.attrs.icon,
});
- if (node.attrs.icon) {
- $button.addClass('o_icon_button');
- $button.append($('<i>', {class: 'fa ' + node.attrs.icon}));
- } else {
- $button.text(node.attrs.string);
- }
this._handleAttributes($button, node);
this._registerModifiers(node, record, $button);
diff --git a/addons/web/static/src/js/widgets/data_export.js b/addons/web/static/src/js/widgets/data_export.js
index dd0096f269b..68c8b23af13 100644
--- a/addons/web/static/src/js/widgets/data_export.js
+++ b/addons/web/static/src/js/widgets/data_export.js
@@ -217,7 +217,7 @@ var DataExport = Dialog.extend({
// The default for the ".modal_content" element is "max-height: 100%;"
// but we want it to always expand to "height: 100%;" for this modal.
- // This can be achieved thanks to LESS modification without touching
+ // This can be achieved thanks to CSS modification without touching
// the ".modal-content" rules... but not with Internet explorer (11).
this.$modal.find(".modal-content").css("height", "100%");