diff --git a/web_widget_timepicker/README.rst b/web_widget_timepicker/README.rst new file mode 100644 index 000000000..541d96227 --- /dev/null +++ b/web_widget_timepicker/README.rst @@ -0,0 +1,110 @@ +===================== +Web Timepicker Widget +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/12.0/web_widget_timepicker + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_widget_timepicker + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module provides a timepicker widget for float fields. +It can be used as a replacement for the standard float_time widget in form views. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +In the form view declaration, put widget='timepicker' attribute in the field tag:: + + ... + +
+ ... + + + ... + + + ... + +Additional bootstrap datetime-picker plugin options can be specified by an options attribute:: + + ... + + ... + +See the available options at `datetime-picker `_. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* VividLab +* Kaushal Prajapati +* Alexandre Díaz + +Contributors +~~~~~~~~~~~~ + +* Michael Fried +* Kaushal Prajapati +* Alexandre Díaz +* David Alonso + +Other credits +~~~~~~~~~~~~~ + +* The module uses the `datetime-picker `__. plugin by Jonathan Peterson. This software is made available under the open source MIT License. Copyright (c) 2015 Jonathan Peterson + +* Odoo Community Association (OCA) + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_timepicker/__init__.py b/web_widget_timepicker/__init__.py new file mode 100644 index 000000000..ef5ae3587 --- /dev/null +++ b/web_widget_timepicker/__init__.py @@ -0,0 +1 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). diff --git a/web_widget_timepicker/__manifest__.py b/web_widget_timepicker/__manifest__.py new file mode 100644 index 000000000..a38f6416d --- /dev/null +++ b/web_widget_timepicker/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2016 Vividlab () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Web Timepicker Widget", + "version": "12.0.1.0.0", + "author": "VividLab, " + "Kaushal Prajapati, " + "Alexandre Díaz, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Web", + "website": "https://github.com/OCA/web/", + 'installable': True, + "depends": [ + "web", + ], + "data": [ + "views/web_widget_timepicker_assets.xml", + ], +} diff --git a/web_widget_timepicker/i18n/web_widget_timepicker.pot b/web_widget_timepicker/i18n/web_widget_timepicker.pot new file mode 100644 index 000000000..447d3bb3c --- /dev/null +++ b/web_widget_timepicker/i18n/web_widget_timepicker.pot @@ -0,0 +1,14 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + diff --git a/web_widget_timepicker/readme/CONTRIBUTORS.rst b/web_widget_timepicker/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..2665dd982 --- /dev/null +++ b/web_widget_timepicker/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Michael Fried +* Kaushal Prajapati +* Alexandre Díaz +* David Alonso diff --git a/web_widget_timepicker/readme/CREDITS.rst b/web_widget_timepicker/readme/CREDITS.rst new file mode 100644 index 000000000..602d29ffd --- /dev/null +++ b/web_widget_timepicker/readme/CREDITS.rst @@ -0,0 +1,3 @@ +* The module uses the `datetime-picker `__. plugin by Jonathan Peterson. This software is made available under the open source MIT License. Copyright (c) 2015 Jonathan Peterson + +* Odoo Community Association (OCA) diff --git a/web_widget_timepicker/readme/DESCRIPTION.rst b/web_widget_timepicker/readme/DESCRIPTION.rst new file mode 100644 index 000000000..39e20ae4e --- /dev/null +++ b/web_widget_timepicker/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module provides a timepicker widget for float fields. +It can be used as a replacement for the standard float_time widget in form views. diff --git a/web_widget_timepicker/readme/USAGE.rst b/web_widget_timepicker/readme/USAGE.rst new file mode 100644 index 000000000..a848ae29e --- /dev/null +++ b/web_widget_timepicker/readme/USAGE.rst @@ -0,0 +1,20 @@ +In the form view declaration, put widget='timepicker' attribute in the field tag:: + + ... + +
+ ... + + + ... + + + ... + +Additional bootstrap datetime-picker plugin options can be specified by an options attribute:: + + ... + + ... + +See the available options at `datetime-picker `_. diff --git a/web_widget_timepicker/static/description/icon.png b/web_widget_timepicker/static/description/icon.png new file mode 100644 index 000000000..912166077 Binary files /dev/null and b/web_widget_timepicker/static/description/icon.png differ diff --git a/web_widget_timepicker/static/description/index.html b/web_widget_timepicker/static/description/index.html new file mode 100644 index 000000000..ca61080ee --- /dev/null +++ b/web_widget_timepicker/static/description/index.html @@ -0,0 +1,457 @@ + + + + + + +Web Timepicker Widget + + + +
+

Web Timepicker Widget

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

This module provides a timepicker widget for float fields. +It can be used as a replacement for the standard float_time widget in form views.

+

Table of contents

+ +
+

Usage

+

In the form view declaration, put widget=’timepicker’ attribute in the field tag:

+
+...
+<field name="arch" type="xml">
+    <form string="View name">
+        ...
+        <field name="name"/>
+        <field name="mytimefieldname" widget="timepicker"/>
+        ...
+    </form>
+</field>
+...
+
+

Additional bootstrap datetime-picker plugin options can be specified by an options attribute:

+
+...
+<field name="mytimefieldname" widget="timepicker" options="{'datepicker': {'stepping': 15}}"/>
+...
+
+

See the available options at datetime-picker.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • VividLab
  • +
  • Kaushal Prajapati
  • +
  • Alexandre Díaz
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+
    +
  • The module uses the datetime-picker. plugin by Jonathan Peterson. This software is made available under the open source MIT License. Copyright (c) 2015 Jonathan Peterson
  • +
  • Odoo Community Association (OCA)
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_widget_timepicker/static/src/js/web_widget_timepicker.js b/web_widget_timepicker/static/src/js/web_widget_timepicker.js new file mode 100644 index 000000000..791faf65c --- /dev/null +++ b/web_widget_timepicker/static/src/js/web_widget_timepicker.js @@ -0,0 +1,96 @@ +/* Copyright 2016 Vividlab + * Copyright 2017 Kaushal Prajapati + * Copyright 2019 Alexandre Díaz + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ +odoo.define('web_widget_timepicker', function (require) { + 'use strict'; + + var field_registry = require('web.field_registry'); + var field_utils = require('web.field_utils'); + var basic_fields = require('web.basic_fields'); + var datepicker = require('web.datepicker'); + var FieldDate = basic_fields.FieldDate; + + + var TimeWidget = datepicker.DateWidget.extend({ + type_of_date: "float_time", + + _onShow: function () { + if (this.$input.val().length !== 0 && this.isValid()) { + var value = this.$input.val(); + this.picker.date(new moment(value, this.options.format)); + this.$input.select(); + } + }, + + setValue: function (value) { + this.set({'value': value}); + var formatted_value = value ? this._formatClient(value) : null; + this.$input.val(formatted_value); + if (this.picker) { + var fdate = new moment(formatted_value, this.options.format); + this.picker.date(fdate && fdate.isValid() + ? fdate : new moment()); + } + }, + + getValue: function () { + var value = this.get('value'); + return value ? this._formatClient(value) : null; + }, + + changeDatetime: function () { + if (this.isValid()) { + var oldValue = this.getValue(); + this._setValueFromUi(); + var newValue = this.getValue(); + if (oldValue && newValue && newValue !== oldValue) { + this.trigger("datetime_changed"); + } + } + }, + }); + + var FieldTimePicker = FieldDate.extend({ + supportedFieldTypes: ['float'], + floatTimeFormat: "HH:mm", + + init: function () { + this._super.apply(this, arguments); + var defDate = null; + if (this.value) { + defDate = new moment(this._formatValue(this.value), + this.floatTimeFormat); + } + // Hard-Coded Format: Field is an float and conversion only accept + // HH:mm format + this.datepickerOptions = _.extend(this.datepickerOptions, { + format: this.floatTimeFormat, + defaultDate: defDate && defDate.isValid() + ? defDate : new moment(), + }); + }, + + _isSameValue: function (value) { + return value === this.value; + }, + + _makeDatePicker: function () { + return new TimeWidget(this, this.datepickerOptions); + }, + + _formatValue: function (value) { + return field_utils.format.float_time(value); + }, + + _parseValue: function (value) { + return field_utils.parse.float_time(value); + }, + }); + + field_registry.add('timepicker', FieldTimePicker); + return { + TimeWidget: TimeWidget, + FieldTimePicker: FieldTimePicker, + }; +}); diff --git a/web_widget_timepicker/views/web_widget_timepicker_assets.xml b/web_widget_timepicker/views/web_widget_timepicker_assets.xml new file mode 100644 index 000000000..3b46bf38c --- /dev/null +++ b/web_widget_timepicker/views/web_widget_timepicker_assets.xml @@ -0,0 +1,12 @@ + + + +