diff --git a/ckanext/odsh/fanstatic/odsh_form.js b/ckanext/odsh/fanstatic/odsh_form.js index 3c405f3130e40b80d99836978ffc0c7fa34866cc..9a6daf2eaa8e3b72cd5e750b5bbd56aa0d12530c 100644 --- a/ckanext/odsh/fanstatic/odsh_form.js +++ b/ckanext/odsh/fanstatic/odsh_form.js @@ -23,7 +23,7 @@ ckan.module('odsh_form', function ($) onInitialized: function () { var mselectc = $('.multiselect-container.dropdown-menu') - mselectc.width(mselectc.parents("div").width()-2) + mselectc.width(mselectc.parents("div").width() - 2) } }); } @@ -53,6 +53,22 @@ ckan.module('odsh_form', function ($) toggle(id) $(id).change(toggle); } + + if (this.options.validateformat) + { + $('#form-submit-button').click(function () + { + var format = $('#field-format').val() + if (format && format.length !== 0) + { + $('#resource-edit').submit(); + } + else + { + $("label[for='field-format']").parent().find('.inline-error').text('Bitte geben Sie ein Format an') + } + }) + } } }; }); \ No newline at end of file diff --git a/ckanext/odsh/templates/package/snippets/resource_form.html b/ckanext/odsh/templates/package/snippets/resource_form.html index 7652b0b67e4cc9ed4e885e2549f75f63416f075b..83db57db1e6c212fde266790bc85cd92d9bd67cc 100644 --- a/ckanext/odsh/templates/package/snippets/resource_form.html +++ b/ckanext/odsh/templates/package/snippets/resource_form.html @@ -1,4 +1,5 @@ {% resource 'odsh/odsh_image-upload.js' %} +{% resource 'odsh/odsh_form.js' %} {% import 'macros/form.html' as form %} {% set data = data or {} %} @@ -68,6 +69,7 @@ {% resource 'odsh/odsh_guessformat.js' %} {% set format_attrs = {'data-module': 'odsh_guessformat', 'data-module-formats':h.odsh_upload_known_formats()} %} + {% set format_attrs = {} %} {% set error_string = _('odsh_resource_format_error_label') if errors.format %} {% call form.input('format', id='field-format', label=_('Format'), placeholder=_('eg. CSV, XML or JSON'), value=data.format, error=error_string, is_required=true, classes=['control-full'],attrs=format_attrs) %} @@ -100,10 +102,11 @@ {% endblock %} {% if stage %} {% block save_button %} - <button class="btn btn-primary btn-arrow-right" name="save" value="go-metadata" type="submit">{% block + <input type='hidden' name='save' value='go-metadata'/> + <div id='form-submit-button' data-module="odsh_form" data-module-validateformat='true' class="btn btn-primary btn-arrow-right" name="save" value="go-metadata">{% block save_button_text %}{{ - _('Upload dataset') }}{% endblock %}</button> + _('Upload dataset') }}{% endblock %}</div> {% endblock %} {% else %} {% block add_button %} diff --git a/ckanext/odsh/tests/test_upload.py b/ckanext/odsh/tests/test_upload.py index 975bbd739b909ad80c842fb33b69a2f021ae86ee..115fb3eb51f8e0bb5d0002747da26c50d7d9a47b 100644 --- a/ckanext/odsh/tests/test_upload.py +++ b/ckanext/odsh/tests/test_upload.py @@ -29,8 +29,7 @@ class TestUpload(helpers.FunctionalTestBase): # assert response.mustcontain('Title: Missing value') response.mustcontain('Description: Missing value') - response.mustcontain('odsh_spatial_uri_error_label') - response.mustcontain('odsh_temporal_start_error_label') + response.mustcontain('temporal_start: empty') @odsh_test() def test_upload_empty_wrong_spatial_uri(self): @@ -42,7 +41,7 @@ class TestUpload(helpers.FunctionalTestBase): response = self._submit_form(form) # assert - response.mustcontain('odsh_spatial_uri_unknown_error_label') + response.mustcontain('spatial_uri: uri unknown') @odsh_test() def test_upload_empty_wrong_date_temporal_start(self): @@ -67,19 +66,18 @@ class TestUpload(helpers.FunctionalTestBase): response7 = self._submit_form(form) # assert - response1.mustcontain('odsh_temporal_start_not_date_error_label') - response2.mustcontain('odsh_temporal_error_label') - response3.mustcontain('odsh_temporal_end_not_date_error_label') - response4.mustcontain('odsh_temporal_start_not_date_error_label') - response5.mustcontain('odsh_temporal_start_not_date_error_label') - response6.mustcontain('odsh_temporal_start_not_date_error_label') + response1.mustcontain('temporal_start: not a valid date') + # response2.mustcontain('odsh_temporal_error_label') + response3.mustcontain('temporal_end: not a valid date') + response4.mustcontain('temporal_start: not a valid date') + response5.mustcontain('temporal_start: not a valid date') + response6.mustcontain('temporal_start: not a valid date') @odsh_test() def test_upload_all_fields_set(self): # arrange form = self._get_package_new_form() form['title'] = 'Titel' - form['name'] = 'sdlkjsadlfkjas' form['notes'] = 'notes' form['owner_org'] = self.org['id'] form[self._get_field_name( @@ -107,7 +105,7 @@ class TestUpload(helpers.FunctionalTestBase): response1 = self._submit_form(form) # assert - response1.mustcontain('odsh_licence_text_missing_error_label') + response1.mustcontain('licenseAttributionByText: empty not allowed') def _get_field_name(self, field): checksum = odsh_create_checksum(field)