summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2019-05-23 14:47:45 +0000
committerSébastien Theys <seb@odoo.com>2019-05-27 16:32:52 +0000
commitd4b09c11460c280864d64d73598903bc6235e3b4 (patch)
tree5b8b9658d41e92406bd18c49a4b6af855d80df06
parentb0acd056e952c8e09c21f1d00689675c11d8c411 (diff)
[IMP] web_editor, web_unsplash: remove options duplicate attributes
Since a reference to the options is already kept, there is no need to keep a reference to each option individually. PR: #33509
-rw-r--r--addons/web_editor/static/src/js/wysiwyg/widgets/media.js25
-rw-r--r--addons/web_editor/static/src/xml/wysiwyg.xml4
-rw-r--r--addons/web_unsplash/static/src/js/unsplash_image_widget.js2
3 files changed, 14 insertions, 17 deletions
diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js
index 4e514985dad..6da33d42bd7 100644
--- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js
+++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js
@@ -127,14 +127,10 @@ var FileWidget = SearchableMediaWidget.extend({
this.imagesRows = this.IMAGES_ROWS;
this.IMAGES_DISPLAYED_TOTAL = this.IMAGES_PER_ROW * this.imagesRows;
- this.options = options;
- this.context = options.context;
- this.accept = options.accept;
-
- this.multiImages = options.multiImages;
-
- this.firstFilters = options.firstFilters || [];
- this.lastFilters = options.lastFilters || [];
+ this.options = _.extend({
+ firstFilters: [],
+ lastFilters: [],
+ }, options || {});
this.images = [];
},
@@ -208,7 +204,7 @@ var FileWidget = SearchableMediaWidget.extend({
domain: this._getAttachmentsDomain(needle),
fields: ['name', 'datas_fname', 'mimetype', 'checksum', 'url', 'type', 'res_id', 'res_model', 'access_token'],
order: [{name: 'id', asc: false}],
- context: this.context,
+ context: this.options.context,
},
}).then(function (records) {
self.records = _.chain(records)
@@ -219,13 +215,13 @@ var FileWidget = SearchableMediaWidget.extend({
return (r.url || r.id);
})
.sortBy(function (r) {
- if (_.any(self.firstFilters, function (filter) {
+ if (_.any(self.options.firstFilters, function (filter) {
var regex = new RegExp(filter, 'i');
return r.name.match(regex) || r.datas_fname && r.datas_fname.match(regex);
})) {
return -1;
}
- if (_.any(self.lastFilters, function (filter) {
+ if (_.any(self.options.lastFilters, function (filter) {
var regex = new RegExp(filter, 'i');
return r.name.match(regex) || r.datas_fname && r.datas_fname.match(regex);
})) {
@@ -405,7 +401,8 @@ var FileWidget = SearchableMediaWidget.extend({
*/
_save: function () {
var self = this;
- if (this.multiImages) {
+
+ if (this.options.multiImages) {
return this.images;
}
@@ -480,7 +477,7 @@ var FileWidget = SearchableMediaWidget.extend({
* @private
*/
_toggleImage: function (attachment, clearSearch, forceSelect) {
- if (this.multiImages) {
+ if (this.options.multiImages) {
var img = _.select(this.images, function (v) { return v.id === attachment.id; });
if (img.length) {
if (!forceSelect) {
@@ -569,7 +566,7 @@ var FileWidget = SearchableMediaWidget.extend({
self.$errorText.text(error);
}
- if (!self.multiImages) {
+ if (!self.options.multiImages) {
self.trigger_up('save_request');
}
}
diff --git a/addons/web_editor/static/src/xml/wysiwyg.xml b/addons/web_editor/static/src/xml/wysiwyg.xml
index daa3890fb25..fd4ad33e54d 100644
--- a/addons/web_editor/static/src/xml/wysiwyg.xml
+++ b/addons/web_editor/static/src/xml/wysiwyg.xml
@@ -101,7 +101,7 @@
enctype="multipart/form-data"
t-att-target="iframeName">
<input type="hidden" name="csrf_token" t-att-value="csrf_token"/>
- <input type="hidden" name="filters" t-att-value="widget.firstFilters.join('_')"/>
+ <input type="hidden" name="filters" t-att-value="widget.options.firstFilters.join('_')"/>
<input t-if="widget.options.res_id" type="hidden" name="res_id" t-att-value="widget.options.res_id"/>
<input t-if="widget.options.res_model" type="hidden" name="res_model" t-att-value="widget.options.res_model"/>
<t t-call="wysiwyg.widgets.files.submenu"/>
@@ -119,7 +119,7 @@
<t t-name="wysiwyg.widgets.files.submenu">
<div class="form-inline align-items-center py-4">
- <input type="file" class="d-none o_file_input" name="upload" t-att-accept="widget.accept" multiple="multiple"/>
+ <input type="file" class="d-none o_file_input" name="upload" t-att-accept="widget.options.accept" multiple="multiple"/>
<input type="hidden" name="disable_optimization" value=""/>
<div class="btn-group">
diff --git a/addons/web_unsplash/static/src/js/unsplash_image_widget.js b/addons/web_unsplash/static/src/js/unsplash_image_widget.js
index 5f5100c3da2..963d31c961a 100644
--- a/addons/web_unsplash/static/src/js/unsplash_image_widget.js
+++ b/addons/web_unsplash/static/src/js/unsplash_image_widget.js
@@ -240,7 +240,7 @@ widgetsMedia.ImageWidget.include({
var imgid = $(ev.currentTarget).data('imgid');
var url = $(ev.currentTarget).data('url');
var downloadURL = $(ev.currentTarget).data('download-url');
- if (!this.multiImages) {
+ if (!this.options.multiImages) {
this._unsplash.selectedImages = {};
}
if (imgid in this._unsplash.selectedImages) {