diff --git a/front/salix/components/upload-photo/index.html b/front/salix/components/upload-photo/index.html index 09b36d531e..a9b674f42b 100644 --- a/front/salix/components/upload-photo/index.html +++ b/front/salix/components/upload-photo/index.html @@ -4,7 +4,7 @@ message="Edit photo"> - + - + + + + + + + @@ -37,6 +51,14 @@ + + + + this.editor.bind({url: e.target.result}); - reader.readAsDataURL(value[0]); + if (this.uploadMethod == 'computer') { + const reader = new FileReader(); + reader.onload = e => this.editor.bind({url: e.target.result}); + reader.readAsDataURL(value); + } else if (this.uploadMethod == 'URL') + this.editor.bind({url: value}); } } diff --git a/front/salix/components/upload-photo/index.spec.js b/front/salix/components/upload-photo/index.spec.js index e8ac05fd42..f2aad6a5ca 100644 --- a/front/salix/components/upload-photo/index.spec.js +++ b/front/salix/components/upload-photo/index.spec.js @@ -24,17 +24,30 @@ describe('Salix', () => { }); describe('viewportSelection()', () => { - it('should call to displayEditor() and updatePhotoPreview() methods', () => { - controller.displayEditor = jest.fn(); + it('should call to the updatePhotoPreview() method when uploadMethod property is set to "computer"', () => { controller.updatePhotoPreview = jest.fn(); const files = [{name: 'test.jpg'}]; controller.newPhoto.files = files; + controller.uploadMethod = 'computer'; controller.viewportSelection = {code: 'normal'}; - expect(controller.displayEditor).toHaveBeenCalledWith(); - expect(controller.updatePhotoPreview).toHaveBeenCalledWith(files); + const firstFile = files[0]; + + expect(controller.updatePhotoPreview).toHaveBeenCalledWith(firstFile); + }); + + it('should call to the updatePhotoPreview() method when uploadMethod property is set to "URL"', () => { + controller.updatePhotoPreview = jest.fn(); + + const url = 'http://gothamcity.com/batman.png'; + controller.newPhoto.url = url; + + controller.uploadMethod = 'URL'; + controller.viewportSelection = {code: 'normal'}; + + expect(controller.updatePhotoPreview).toHaveBeenCalledWith(url); }); }); diff --git a/front/salix/components/upload-photo/locale/es.yml b/front/salix/components/upload-photo/locale/es.yml index bba3a985a8..fca0a4ac37 100644 --- a/front/salix/components/upload-photo/locale/es.yml +++ b/front/salix/components/upload-photo/locale/es.yml @@ -3,4 +3,6 @@ Select an image: Selecciona una imagen File name: Nombre del fichero Rotate left: Girar a la izquierda Rotate right: Girar a la derecha -Panoramic: PanorĂ¡mico \ No newline at end of file +Panoramic: PanorĂ¡mico +Select from computer: Seleccionar foto desde ordenador +Import from external URL: Importar desde URL externa \ No newline at end of file