|
@ -17,7 +17,7 @@ |
|
|
* |
|
|
* |
|
|
**********************************************************************************/ |
|
|
**********************************************************************************/ |
|
|
|
|
|
|
|
|
odoo.define('muk_web_utils.ColorChar', function (require) { |
|
|
|
|
|
|
|
|
odoo.define('muk_web_utils.color', function (require) { |
|
|
"use strict"; |
|
|
"use strict"; |
|
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
var core = require('web.core'); |
|
@ -25,6 +25,8 @@ var fields = require('web.basic_fields'); |
|
|
var registry = require('web.field_registry'); |
|
|
var registry = require('web.field_registry'); |
|
|
var colorpicker = require('web.colorpicker'); |
|
|
var colorpicker = require('web.colorpicker'); |
|
|
|
|
|
|
|
|
|
|
|
var AbstractField = require('web.AbstractField'); |
|
|
|
|
|
|
|
|
var _t = core._t; |
|
|
var _t = core._t; |
|
|
var QWeb = core.qweb; |
|
|
var QWeb = core.qweb; |
|
|
|
|
|
|
|
@ -63,7 +65,7 @@ var FieldColor = fields.InputField.extend({ |
|
|
if((/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i).test(value)) { |
|
|
if((/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i).test(value)) { |
|
|
return value; |
|
|
return value; |
|
|
} else { |
|
|
} else { |
|
|
throw new Error(_.str.sprintf(core._t("'%s' is not a correct color value"), value)); |
|
|
|
|
|
|
|
|
throw new Error(_.str.sprintf(_t("'%s' is not a correct color value"), value)); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
_onCustomColorButtonClick: function () { |
|
|
_onCustomColorButtonClick: function () { |
|
@ -79,7 +81,43 @@ var FieldColor = fields.InputField.extend({ |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var FieldColorIndex = AbstractField.extend({ |
|
|
|
|
|
events: _.extend({}, AbstractField.prototype.events, { |
|
|
|
|
|
'change': '_onChange', |
|
|
|
|
|
}), |
|
|
|
|
|
template: 'muk_web_utils.FieldColorIndex', |
|
|
|
|
|
supportedFieldTypes: ['integer'], |
|
|
|
|
|
isSet: function () { |
|
|
|
|
|
return this.value === 0 || this._super.apply(this, arguments); |
|
|
|
|
|
}, |
|
|
|
|
|
getFocusableElement: function () { |
|
|
|
|
|
return this.$el.is('select') ? this.$el : $(); |
|
|
|
|
|
}, |
|
|
|
|
|
_renderEdit: function () { |
|
|
|
|
|
this.$el.addClass('mk_color_index_' + this.value); |
|
|
|
|
|
this.$('option[value="' + this.value + '"]').prop('selected', true); |
|
|
|
|
|
}, |
|
|
|
|
|
_renderReadonly: function () { |
|
|
|
|
|
this.$el.addClass('mk_color_index_' + this.value); |
|
|
|
|
|
this.$el.empty().text('Color ' + this._formatValue(this.value)); |
|
|
|
|
|
}, |
|
|
|
|
|
_onChange: function (event) { |
|
|
|
|
|
this.$el.removeClass(function (index, className) { |
|
|
|
|
|
return (className.match (/(^|\s)mk_color_index_\S+/g) || []).join(' '); |
|
|
|
|
|
}); |
|
|
|
|
|
this.$el.addClass('mk_color_index_' + this.$el.val()); |
|
|
|
|
|
this._setValue(this.$el.val()); |
|
|
|
|
|
}, |
|
|
|
|
|
_parseValue: function (value) { |
|
|
|
|
|
if(0 > value || value > 12) { |
|
|
|
|
|
throw new Error(_.str.sprintf(_t("'%s' is not a correct color index (0-12)"), value)); |
|
|
|
|
|
} |
|
|
|
|
|
return value; |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
registry.add('color', FieldColor); |
|
|
registry.add('color', FieldColor); |
|
|
|
|
|
registry.add('color_index', FieldColorIndex); |
|
|
|
|
|
|
|
|
return FieldColor; |
|
|
return FieldColor; |
|
|
|
|
|
|