summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/fields/field_utils.js17
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js41
-rw-r--r--addons/web/static/src/scss/bs_mixins_overrides.scss20
-rw-r--r--addons/web/static/src/scss/utils.scss33
4 files changed, 69 insertions, 42 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index 9d40c88019d..bbdee83c4f9 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -587,6 +587,22 @@ function parseFloatTime(value) {
}
/**
+ * Parse a String containing a percentage and convert it to float.
+ * The percentage can be a regular xx.xx float or a xx%.
+ *
+ * @param {string} value
+ * The string to be parsed
+ * @returns {float}
+ * @throws {Error} if the value couldn't be converted to float
+ */
+function parsePercentage(value) {
+ if (value.slice(-1) === '%') {
+ return parseFloat(value.slice(0, -1)) / 100;
+ }
+ return parseFloat(value);
+}
+
+/**
* Parse a String containing integer with language formating
*
* @param {string} value
@@ -668,6 +684,7 @@ return {
many2one: parseMany2one,
monetary: parseMonetary,
one2many: _.identity,
+ percentage: parsePercentage,
reference: parseMany2one,
selection: _.identity, // todo
text: _.identity, // todo
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index 0701c1d1046..d0f15aeb369 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -3733,27 +3733,21 @@ var BasicModel = AbstractModel.extend({
_makeDefaultRecord: function (modelName, params) {
var self = this;
- var determineExtraFields = function () {
- // Fields that are present in the originating view, that need to be initialized
- // Hence preventing their value to crash when getting back to the originating view
- var parentRecord = self.localData[params.parentID];
-
- var originView = parentRecord && parentRecord.fieldsInfo;
- if (!originView || !originView[parentRecord.viewType])
- return [];
-
- var fieldsFromOrigin = _.filter(Object.keys(originView[parentRecord.viewType]),
- function (fieldname) {
- return params.fields[fieldname] !== undefined;
- });
-
- return fieldsFromOrigin;
- };
-
- var fieldNames = Object.keys(params.fieldsInfo[params.viewType]);
+ var targetView = params.viewType;
+ var fields = params.fields;
+ var fieldsInfo = params.fieldsInfo;
+ var fieldNames = Object.keys(fieldsInfo[targetView]);
var fields_key = _.without(fieldNames, '__last_update');
- var extraFields = determineExtraFields();
+ // Fields that are present in the originating view, that need to be initialized
+ // Hence preventing their value to crash when getting back to the originating view
+ var parentRecord = self.localData[params.parentID];
+ if (parentRecord) {
+ var originView = parentRecord.viewType;
+ fieldNames = _.union(fieldNames, Object.keys(parentRecord.fieldsInfo[originView]));
+ fieldsInfo[targetView] = _.defaults({}, fieldsInfo[targetView], parentRecord.fieldsInfo[originView]);
+ fields = _.defaults({}, fields, parentRecord.fields);
+ }
return this._rpc({
model: modelName,
@@ -3762,15 +3756,14 @@ var BasicModel = AbstractModel.extend({
context: params.context,
})
.then(function (result) {
-
var record = self._makeDataPoint({
modelName: modelName,
- fields: params.fields,
- fieldsInfo: params.fieldsInfo,
+ fields: fields,
+ fieldsInfo: fieldsInfo,
context: params.context,
parentID: params.parentID,
res_ids: params.res_ids,
- viewType: params.viewType,
+ viewType: targetView,
});
// We want to overwrite the default value of the handle field (if any),
@@ -3787,7 +3780,7 @@ var BasicModel = AbstractModel.extend({
result[overrideDefaultFields.field] = overrideDefaultFields.value;
}
- return self.applyDefaultValues(record.id, result, {fieldNames: _.union(fieldNames, extraFields)})
+ return self.applyDefaultValues(record.id, result, {fieldNames: fieldNames})
.then(function () {
var def = $.Deferred();
self._performOnChange(record, fields_key).always(function () {
diff --git a/addons/web/static/src/scss/bs_mixins_overrides.scss b/addons/web/static/src/scss/bs_mixins_overrides.scss
index b321b900493..fdaa3cd5ec3 100644
--- a/addons/web/static/src/scss/bs_mixins_overrides.scss
+++ b/addons/web/static/src/scss/bs_mixins_overrides.scss
@@ -3,21 +3,11 @@
// Those will affect the way bootstrap is generated wherever bootstrap is used
//------------------------------------------------------------------------------
-// Override color-yiq function to handle the alpha component of colors
-@function color-yiq($alphacolor, $background: $body-bg) {
- $color: mix(rgba($alphacolor, 1.0), $background, percentage(alpha($alphacolor)));
-
- $r: red($color);
- $g: green($color);
- $b: blue($color);
-
- $yiq: (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
-
- @if ($yiq >= $yiq-contrasted-threshold) {
- @return $yiq-text-dark;
- } @else {
- @return $yiq-text-light;
- }
+// Override color-yiq function to handle the alpha component of colors and
+// automatic threshold
+@function color-yiq($color, $background: $body-bg, $cross-mix: true) {
+ $threshold: if($yiq-contrasted-threshold != false, $yiq-contrasted-threshold / 255 * 100%, false);
+ @return o-get-most-contrast($color, $yiq-text-light, $yiq-text-dark, $background, $threshold, $cross-mix);
}
@mixin o-bg-color($color, $text-color: null, $with-muted: true) {
diff --git a/addons/web/static/src/scss/utils.scss b/addons/web/static/src/scss/utils.scss
index e63e0c6650f..5ac917fcd75 100644
--- a/addons/web/static/src/scss/utils.scss
+++ b/addons/web/static/src/scss/utils.scss
@@ -66,9 +66,36 @@
@function luma($color) {
@return ((red($color) * .299) + (green($color) * .587) + (blue($color) * .114)) / 255 * 100%;
}
-@function o-get-most-contrast($color, $c1, $c2) {
- $luma: luma($color);
- @return if(abs($luma - luma($c1)) > abs($luma - luma($c2)), $c1, $c2);
+//
+// Given two colors, returns the one which has the most constrast with another
+// given color. Careful: if you want to find the text color which will suit the
+// most on a given background color, you should use the 'color-yiq' function.
+//
+@function o-get-most-contrast($color, $c1, $c2, $background: #FFFFFF, $threshold: false, $cross-mix: true) {
+ $background: if($background == null, #FFFFFF, $background);
+
+ $real-color: mix(rgba($color, 1.0), $background, percentage(alpha($color)));
+ $luma: luma($real-color);
+
+ $cross-color: if($cross-mix, $real-color, $background);
+
+ $real-c1: mix(rgba($c1, 1.0), $cross-color, percentage(alpha($c1)));
+ $luma-c1: luma($real-c1);
+
+ $real-c2: mix(rgba($c2, 1.0), $cross-color, percentage(alpha($c2)));
+ $luma-c2: luma($real-c2);
+
+ $-dark: if($luma-c1 <= $luma-c2, $c1, $c2);
+ $-light: if($luma-c1 > $luma-c2, $c1, $c2);
+
+ @if $threshold == false {
+ // Automatic threshold: give a really small preference to light results
+ // as bootstrap does by default (mainly by compatibility at the moment
+ // this code is written)
+ $threshold: ($luma-c1 + $luma-c2) * 0.515; // 150 / 145.63 * 0.5 would be the BS value
+ }
+
+ @return if($luma > $threshold, $-dark, $-light);
}
// ------------------------------------------------------------------