diff options
| author | David Beguin <dbe@odoo.com> | 2020-01-20 14:48:27 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-04-16 10:26:32 +0000 |
| commit | e52489bf999e4d98499c493bd93f9aa6a04a6a47 (patch) | |
| tree | c348b29809a8271e11d2e95e70be9cbd54c18dda | |
| parent | 45f7463e7a532ca5afbc280de7e86c2deff99921 (diff) | |
[IMP] website_slides: lint and clean slide upload widget and controller code
This commit prepares the next ones from same PR and only clean the code of
slide upload widget + website_slides controller.
Task ID 1981399
PR #43577
| -rw-r--r-- | addons/website_slides/controllers/main.py | 2 | ||||
| -rw-r--r-- | addons/website_slides/static/src/js/slides_upload.js | 47 |
2 files changed, 28 insertions, 21 deletions
diff --git a/addons/website_slides/controllers/main.py b/addons/website_slides/controllers/main.py index e6b71cc9ff2..ba2a8440753 100644 --- a/addons/website_slides/controllers/main.py +++ b/addons/website_slides/controllers/main.py @@ -982,7 +982,7 @@ class WebsiteSlides(WebsiteProfile): @http.route(['/slides/prepare_preview'], type='json', auth='user', methods=['POST'], website=True) def prepare_preview(self, **data): Slide = request.env['slide.slide'] - document_type, document_id = Slide._find_document_data_from_url(data['url']) + unused, document_id = Slide._find_document_data_from_url(data['url']) preview = {} if not document_id: preview['error'] = _('Please enter valid youtube or google doc url') diff --git a/addons/website_slides/static/src/js/slides_upload.js b/addons/website_slides/static/src/js/slides_upload.js index 828207840f1..b5704d68792 100644 --- a/addons/website_slides/static/src/js/slides_upload.js +++ b/addons/website_slides/static/src/js/slides_upload.js @@ -207,7 +207,7 @@ var SlideUploadDialog = Dialog.extend({ * * @private */ - _getSelect2DropdownValues: function (){ + _getSelect2DropdownValues: function () { var result = {}; var self = this; // tags @@ -223,16 +223,16 @@ var SlideUploadDialog = Dialog.extend({ result['tag_ids'] = tagValues; } // category - if (!self.defaultCategoryID){ + if (!self.defaultCategoryID) { var categoryValue = this.$('#category_id').select2('data'); if (categoryValue && categoryValue.create) { result['category_id'] = [0, {'name': categoryValue.text}]; } else if (categoryValue) { - result['category_id'] = [categoryValue.id]; + result['category_id'] = [categoryValue.id]; this.categoryID = categoryValue.id; } } else { - result['category_id'] = [self.defaultCategoryID]; + result['category_id'] = [self.defaultCategoryID]; this.categoryID = self.defaultCategoryID; } return result; @@ -291,23 +291,23 @@ var SlideUploadDialog = Dialog.extend({ } }, fill_data: function (query, data) { - var that = this, + var self = this, tags = {results: []}; _.each(data, function (obj) { - if (that.matcher(query.term, obj[nameKey])) { + if (self.matcher(query.term, obj[nameKey])) { tags.results.push({id: obj.id, text: obj[nameKey]}); } }); query.callback(tags); }, query: function (query) { - var that = this; + var self = this; // fetch data only once and store it if (!this.selection_data) { this.fetch_rpc_fnc().then(function (data) { - that.can_create = data.can_create; - that.fill_data(query, data.read_results); - that.selection_data = data.read_results; + self.can_create = data.can_create; + self.fill_data(query, data.read_results); + self.selection_data = data.read_results; }); } else { this.fill_data(query, this.selection_data); @@ -354,7 +354,7 @@ var SlideUploadDialog = Dialog.extend({ * Show the preview/right column and resize the modal * @private */ - _showPreviewColumn: function() { + _showPreviewColumn: function () { this.$('#o_wslides_js_slide_upload_left_column').removeClass('col').addClass('col-md-6'); this.$('#o_wslides_js_slide_upload_preview_column').removeClass('d-none'); this.$modal.find('.modal-dialog').addClass('modal-lg'); @@ -423,6 +423,7 @@ var SlideUploadDialog = Dialog.extend({ var $input = $(ev.currentTarget); var preventOnchange = $input.data('preventOnchange'); + var $preview = self.$('#slide-image'); var file = ev.target.files[0]; if (!file) { @@ -449,7 +450,7 @@ var SlideUploadDialog = Dialog.extend({ utils.getDataURLFromFile(file).then(function (buffer) { if (isImage) { - self.$('#slide-image').attr('src', buffer); + $preview.attr('src', buffer); } buffer = buffer.split(',')[1]; self.file.data = buffer; @@ -501,7 +502,7 @@ var SlideUploadDialog = Dialog.extend({ viewport: viewport }).then(function () { var imageData = self.$('#data_canvas')[0].toDataURL(); - self.$('#slide-image').attr('src', imageData); + $preview.attr('src', imageData); if (loaded) { self.set('can_submit_form', true); } @@ -559,7 +560,7 @@ var SlideUploadDialog = Dialog.extend({ .text(_.str.sprintf(_t('Failed to install "%s".'), this.modulesToInstallStatus.name)); } } else { - this.modulesToInstallStatus = _.extend({}, _.find(this.modulesToInstall, function (item) { return item.id == moduleId; })); + this.modulesToInstallStatus = _.extend({}, _.find(this.modulesToInstall, function (item) { return item.id === moduleId; })); this.set('state', '_import'); this.$('#o_wslides_install_module_text') .text(_.str.sprintf(_t('Do you want to install the "%s" app?'), this.modulesToInstallStatus.name)); @@ -593,6 +594,7 @@ var SlideUploadDialog = Dialog.extend({ this.modulesToInstallStatus = null; } }, + _onClickFormSubmit: function (ev) { var self = this; var $btn = $(ev.currentTarget); @@ -604,15 +606,20 @@ var SlideUploadDialog = Dialog.extend({ route: '/slides/add_slide', params: values, }).then(function (data) { - if (data.error) { - self.set('state', oldType); - self._alertDisplay(data.error); - } else { - window.location = data.url; - } + self._onFormSubmitDone(data, oldType); }); } }, + + _onFormSubmitDone: function (data, oldType) { + if (data.error) { + this.set('state', oldType); + this._alertDisplay(data.error); + } else { + window.location = data.url; + } + }, + _onClickSlideTypeIcon: function (ev) { var $elem = this.$(ev.currentTarget); var slideType = $elem.data('slideType'); |
