diff --git a/openstack_dashboard/dashboards/project/images/images/forms.py b/openstack_dashboard/dashboards/project/images/images/forms.py index fac38bf46d..e5f3d80952 100644 --- a/openstack_dashboard/dashboards/project/images/images/forms.py +++ b/openstack_dashboard/dashboards/project/images/images/forms.py @@ -101,27 +101,29 @@ class CreateImageForm(forms.SelfHandlingForm): widget=forms.Select(attrs={ 'class': 'switchable', 'data-slug': 'source'})) + image_url_attrs = { + 'class': 'switched', + 'data-switch-on': 'source', + 'data-source-url': _('Image Location'), + 'ng-model': 'ctrl.copyFrom', + 'ng-change': 'ctrl.selectImageFormat(ctrl.copyFrom)' + } image_url = ImageURLField(label=_("Image Location"), help_text=_("An external (HTTP/HTTPS) URL to " "load the image from."), - widget=forms.TextInput(attrs={ - 'class': 'switched', - 'data-switch-on': 'source', - 'data-source-url': _('Image Location'), - 'ng-model': 'copyFrom', - 'ng-change': - 'ctrl.selectImageFormat(copyFrom)'}), + widget=forms.TextInput(attrs=image_url_attrs), required=False) + image_attrs = { + 'class': 'switched', + 'data-switch-on': 'source', + 'data-source-file': _('Image File'), + 'ng-model': 'ctrl.imageFile', + 'ng-change': 'ctrl.selectImageFormat(ctrl.imageFile.name)', + 'image-file-on-change': None + } image_file = forms.FileField(label=_("Image File"), help_text=_("A local image to upload."), - widget=forms.FileInput(attrs={ - 'class': 'switched', - 'data-switch-on': 'source', - 'data-source-file': _('Image File'), - 'ng-model': 'imageFile', - 'ng-change': - 'ctrl.selectImageFormat(imageFile.name)', - 'image-file-on-change': None}), + widget=forms.FileInput(attrs=image_attrs), required=False) kernel = forms.ChoiceField( label=_('Kernel'), diff --git a/openstack_dashboard/static/app/tech-debt/image-form.controller.js b/openstack_dashboard/static/app/tech-debt/image-form.controller.js index ea6594f716..0784d2bcaa 100644 --- a/openstack_dashboard/static/app/tech-debt/image-form.controller.js +++ b/openstack_dashboard/static/app/tech-debt/image-form.controller.js @@ -21,8 +21,8 @@ function ImageFormController() { var ctrl = this; - ctrl.copyFrom = angular.element('.image_url').val(); - ctrl.diskFormat = angular.element('.disk_format').val(); + ctrl.copyFrom = angular.element('#id_image_url').val(); + ctrl.diskFormat = angular.element('#id_disk_format option:selected').val(); ctrl.selectImageFormat = function (path) { if (!path) { return; } var format = path.substr(path.lastIndexOf(".") + 1).toLowerCase().replace(/[^a-z0-9]+/gi, ""); diff --git a/openstack_dashboard/static/app/tech-debt/image-form.controller.spec.js b/openstack_dashboard/static/app/tech-debt/image-form.controller.spec.js index f54af5b346..1e3c6b02d5 100644 --- a/openstack_dashboard/static/app/tech-debt/image-form.controller.spec.js +++ b/openstack_dashboard/static/app/tech-debt/image-form.controller.spec.js @@ -19,7 +19,7 @@ describe('horizon.app.tech-debt.ImageFormController', function() { var $document, controller; - var gzHtml = '
'; + var gzHtml = ''; beforeEach(module('horizon.app.tech-debt')); beforeEach(inject(function($injector) { @@ -32,19 +32,20 @@ } it('should set copyFrom', function() { - $document.find('body').append(''); + $document.find('body').append(''); var ctrl = createController(); expect(ctrl.copyFrom).toEqual('ImageUrl'); - $document.find('.image_url').remove(); + $document.find('#id_image_url').remove(); }); it('should set diskFormat', function() { - $document.find('body').append(''); + $document.find('body').append(''); var ctrl = createController(); expect(ctrl.diskFormat).toEqual('DiskFormat'); - $document.find('.disk_format').remove(); + $document.find('#id_disk_format').remove(); }); it('should set image format to detected format', function() {