You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.3 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_web_utils.ColorChar', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var fields = require('web.basic_fields');
  23. var registry = require('web.field_registry');
  24. var colorpicker = require('web.colorpicker');
  25. var _t = core._t;
  26. var QWeb = core.qweb;
  27. var FieldColor = fields.InputField.extend({
  28. events: _.extend({}, fields.InputField.prototype.events, {
  29. "click .mk_field_color_button": "_onCustomColorButtonClick",
  30. }),
  31. template: "muk_web_utils.FieldColor",
  32. supportedFieldTypes: ['char'],
  33. start: function() {
  34. this.$input = this.$('.mk_field_color_input');
  35. return this._super.apply(this, arguments);
  36. },
  37. _renderEdit: function () {
  38. this.$('.mk_field_color_input').val(this._formatValue(this.value));
  39. },
  40. _renderReadonly: function () {
  41. this.$el.text(this._formatValue(this.value));
  42. },
  43. _onCustomColorButtonClick: function () {
  44. var ColorpickerDialog = new colorpicker(this, {
  45. dialogClass: 'mk_field_color_picker',
  46. defaultColor: this._getValue(),
  47. });
  48. ColorpickerDialog.on('colorpicker:saved', this, function (event) {
  49. this.$input.val(event.data.hex);
  50. this._setValue(event.data.hex);
  51. });
  52. ColorpickerDialog.open();
  53. },
  54. });
  55. registry.add('color', FieldColor);
  56. return FieldColor;
  57. });