summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields/basic_fields.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js67
1 files changed, 61 insertions, 6 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 11da78c89e0..4e63e5d3613 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -23,6 +23,7 @@ var utils = require('web.utils');
var view_dialogs = require('web.view_dialogs');
var field_utils = require('web.field_utils');
var time = require('web.time');
+var ColorpickerDialog = require('web.ColorpickerDialog');
require("web.zoomodoo");
@@ -373,11 +374,11 @@ var NumericField = InputField.extend({
// Private
//--------------------------------------------------------------------------
- /**
+ /**
* Evaluate a string representing a simple formula,
* a formula is composed of numbers and arithmetic operations
* (ex: 4+3*2)
- *
+ *
* Supported arithmetic operations: + - * / ^ ( )
* Since each number in the formula can be expressed in user locale,
* we parse each float value inside the formula using the user context
@@ -385,7 +386,7 @@ var NumericField = InputField.extend({
* We assume that this function is used as a calculator so operand ^ (xor)
* is replaced by operand ** (power) so that users that are used to
* excel or libreoffice are not confused
- *
+ *
* @private
* @param expr
* @return a float representing the result of the evaluated formula
@@ -1756,7 +1757,7 @@ var FieldBinaryImage = AbstractFieldBinary.extend({
},
/**
* Returns the image URL from a model.
- *
+ *
* @private
* @param {string} model model from which to retrieve the image
* @param {string} res_id id of the record
@@ -1769,7 +1770,7 @@ var FieldBinaryImage = AbstractFieldBinary.extend({
model: model,
id: JSON.stringify(res_id),
field: field,
- // unique forces a reload of the image when the record has been updated
+ // unique forces a reload of the image when the record has been updated
unique: field_utils.format.datetime(unique).replace(/[^0-9]/g, ''),
});
},
@@ -1811,7 +1812,7 @@ var FieldBinaryImage = AbstractFieldBinary.extend({
},
/**
* Only enable the zoom on image in read-only mode, and if the option is enabled.
- *
+ *
* @override
* @private
*/
@@ -3204,6 +3205,59 @@ var AceEditor = DebouncedField.extend({
},
});
+
+/**
+ * The FieldColor widget give a visual representation of a color
+ * Clicking on it bring up an instance of ColorpickerDialog
+ */
+var FieldColor = AbstractField.extend({
+ template: 'FieldColor',
+ events: {
+ 'click .o_field_color': '_onColorClick',
+ },
+ custom_events: {
+ 'colorpicker:saved': '_onColorpickerSaved',
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ * @private
+ */
+ _render: function () {
+ this._super.apply(this, arguments);
+ this.$('.o_field_color').data('value', this.value)
+ .css('background-color', this.value)
+ .attr('title', this.value);
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {MouseEvent} ev
+ */
+ _onColorClick: function (ev) {
+ new ColorpickerDialog(this, {
+ defaultColor: this.value,
+ noTransparency: true,
+ }).open();
+ },
+
+ /**
+ * @private
+ * @param {OdooEvent} ev
+ */
+ _onColorpickerSaved: function (ev) {
+ this._setValue(ev.data.hex);
+ },
+});
+
return {
TranslatableFieldMixin: TranslatableFieldMixin,
DebouncedField: DebouncedField,
@@ -3247,6 +3301,7 @@ return {
CharCopyClipboard: CharCopyClipboard,
JournalDashboardGraph: JournalDashboardGraph,
AceEditor: AceEditor,
+ FieldColor: FieldColor,
};
});