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.js205
1 files changed, 134 insertions, 71 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index a62043b28c8..b14d71c0b26 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -8,7 +8,6 @@ odoo.define('web.basic_fields', function (require) {
*/
var AbstractField = require('web.AbstractField');
-var config = require('web.config');
var core = require('web.core');
var crash_manager = require('web.crash_manager');
var datepicker = require('web.datepicker');
@@ -313,13 +312,23 @@ var InputField = DebouncedField.extend({
this._super.apply(this, arguments);
// the following code only makes sense in edit mode, with an input
- if (this.mode === 'edit') {
+ if (this.mode === 'edit' && ev.data.direction !== 'cancel') {
var input = this.$input[0];
var selecting = (input.selectionEnd !== input.selectionStart);
if ((ev.data.direction === "left" && (selecting || input.selectionStart !== 0))
- || (ev.data.direction === "right" && (selecting || input.selectionStart !== input.value.length))) {
+ || (ev.data.direction === "right" && (selecting || input.selectionStart !== input.value.length))) {
ev.stopPropagation();
}
+ if (ev.data.direction ==='next' &&
+ this.attrs.modifiersValue &&
+ this.attrs.modifiersValue.required) {
+ if (!this.$input.val()){
+ this.setInvalidClass();
+ ev.stopPropagation();
+ } else {
+ this.removeInvalidClass();
+ }
+ }
}
},
});
@@ -973,87 +982,22 @@ var FieldPhone = FieldEmail.extend({
className: 'o_field_phone',
prefix: 'tel',
- /**
- * The phone widget is an extension of email, with the distinction that, in
- * some cases, we do not want to show a clickable widget in readonly.
- * In particular, we only want to make it clickable if the device can call
- * this particular number. This is controlled by the _canCall function.
- *
- * @override
- */
- init: function () {
- this._super.apply(this, arguments);
- if (this.mode === 'readonly' && !this._canCall()) {
- this.tagName = 'span';
- }
- },
- /**
- * Returns the associated link only if there is one.
- *
- * @override
- */
- getFocusableElement: function () {
- if (this.mode !== 'readonly' || this._canCall()) {
- return this._super.apply(this, arguments);
- }
- return $();
- },
-
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
- * In readonly, we only make the widget clickable if the device can call it.
- * Additionally, we obfuscate the phone number to prevent Skype from seeing it.
- *
* @override
* @private
*/
_renderReadonly: function () {
this._super();
- if (this._canCall()) {
- // Split phone number into two to prevent Skype app from finding it
- var text = this.$el.text();
- var part1 = _.escape(text.substr(0, text.length/2));
- var part2 = _.escape(text.substr(text.length/2));
- this.$el.html(part1 + "­" + part2);
- } else {
- this.$el.removeClass('o_form_uri');
- }
+
// This class should technically be there in case of a very very long
// phone number, but it breaks the o_row mechanism, which is more
// important right now.
this.$el.removeClass('o_text_overflow');
},
-
- /**
- * Remove possibly present ­ characters when saving number
- *
- * @override
- * @private
- */
- _setValue: function (value, options) {
- // NOT NEEDED AS OF SAAS-11.3
- if (value) {
- // remove possibly pasted ­ characters
- value = value.replace(/\u00AD/g, '');
- }
- return this._super(value, options);
- },
-
- /**
- * Phone fields are clickable in readonly on small screens ~= on phones.
- * This can be overriden by call-capable modules to display a clickable
- * link in different situations, like always regardless of screen size,
- * or only allow national calls for example.
- *
- * @override
- * @private
- */
- _canCall: function () {
- return config.device.isMobile;
- }
});
var UrlWidget = InputField.extend({
@@ -1233,6 +1177,18 @@ var FieldBinaryImage = AbstractFieldBinary.extend({
}
}
var $img = $(qweb.render("FieldBinaryImage-img", {widget: this, url: url}));
+ // override css size attributes (could have been defined in css files)
+ // if specified on the widget
+ var width = this.nodeOptions.size ? this.nodeOptions.size[0] : this.attrs.width;
+ var height = this.nodeOptions.size ? this.nodeOptions.size[1] : this.attrs.height;
+ if (width) {
+ $img.attr('width', width);
+ $img.css('max-width', width + 'px');
+ }
+ if (height) {
+ $img.attr('height', height);
+ $img.css('max-height', height + 'px');
+ }
this.$('> img').remove();
this.$el.prepend($img);
$img.on('error', function () {
@@ -1325,6 +1281,112 @@ var FieldBinaryFile = AbstractFieldBinary.extend({
},
});
+var FieldPdfViewer = FieldBinaryFile.extend({
+ supportedFieldTypes: ['binary'],
+ template: 'FieldPdfViewer',
+ /**
+ * @override
+ */
+ init: function () {
+ this._super.apply(this, arguments);
+ this.PDFViewerApplication = false;
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {DOMElement} iframe
+ */
+ _disableButtons: function (iframe) {
+ if (this.mode === 'readonly') {
+ $(iframe).contents().find('button#download').hide();
+ }
+ $(iframe).contents().find('button#openFile').hide();
+ },
+ /**
+ * @private
+ * @returns {string} the pdf viewer URI
+ */
+ _getURI: function () {
+ var queryObj = {
+ model: this.model,
+ field: this.name,
+ id: this.res_id,
+ };
+ var page = this.recordData[this.name + '_page'] || 1;
+ var queryString = $.param(queryObj);
+ var url = encodeURIComponent('/web/image?' + queryString);
+ var viewerURL = '/web/static/lib/pdfjs/web/viewer.html?file=';
+ return viewerURL + url + '#page=' + page;
+ },
+ /**
+ * @private
+ * @override
+ */
+ _render: function () {
+ var self = this;
+ var $pdfViewer = this.$('.o_form_pdf_controls').children().add(this.$('.o_pdfview_iframe'));
+ var $selectUpload = this.$('.o_select_file_button').first();
+ var $iFrame = this.$('.o_pdfview_iframe');
+
+ $iFrame.on('load', function () {
+ self.PDFViewerApplication = this.contentWindow.window.PDFViewerApplication;
+ self._disableButtons(this);
+ });
+ if (this.mode === "readonly" && this.value) {
+ $iFrame.attr('src', this._getURI());
+ } else {
+ if (this.value) {
+ var binSize = utils.is_bin_size(this.value);
+ $pdfViewer.removeClass('o_hidden');
+ $selectUpload.addClass('o_hidden');
+ if (binSize) {
+ $iFrame.attr('src', this._getURI());
+ }
+ } else {
+ $pdfViewer.addClass('o_hidden');
+ $selectUpload.removeClass('o_hidden');
+ }
+ }
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ * @private
+ * @param {Event} ev
+ */
+ on_file_change: function (ev) {
+ this._super.apply(this, arguments);
+ if (this.PDFViewerApplication) {
+ var files = ev.target.files;
+ if (!files || files.length === 0) {
+ return;
+ }
+ var file = files[0];
+ // TOCheck: is there requirement to fallback on FileReader if browser don't support URL
+ this.PDFViewerApplication.open(URL.createObjectURL(file), 0);
+ }
+ },
+ /**
+ * Remove the behaviour of on_save_as in FieldBinaryFile.
+ *
+ * @override
+ * @private
+ * @param {MouseEvent} ev
+ */
+ on_save_as: function (ev) {
+ ev.stopPropagation();
+ },
+
+});
+
var PriorityWidget = AbstractField.extend({
// the current implementation of this widget makes it
// only usable for fields of type selection
@@ -2109,7 +2171,7 @@ var JournalDashboardGraph = AbstractField.extend({
self.chart.forceY([0]);
self.chart.options({
x: function (d, u) { return u; },
- margin: {'left': 0, 'right': 0, 'top': 0, 'bottom': 0},
+ margin: {'left': 0, 'right': 0, 'top': 5, 'bottom': 0},
showYAxis: false,
showLegend: false,
});
@@ -2410,7 +2472,7 @@ var FieldDomain = AbstractField.extend({
var AceEditor = DebouncedField.extend({
template: "AceEditor",
jsLibs: [
- '/web/static/lib/ace/ace.odoo-custom.js',
+ '/web/static/lib/ace/ace.js',
[
'/web/static/lib/ace/mode-python.js',
'/web/static/lib/ace/mode-xml.js'
@@ -2557,6 +2619,7 @@ return {
DebouncedField: DebouncedField,
FieldEmail: FieldEmail,
FieldBinaryFile: FieldBinaryFile,
+ FieldPdfViewer: FieldPdfViewer,
FieldBinaryImage: FieldBinaryImage,
FieldBoolean: FieldBoolean,
FieldBooleanButton: FieldBooleanButton,