diff --git a/plugins/dspace/lib/dspace_plugin/library.rb b/plugins/dspace/lib/dspace_plugin/library.rb index 3bef566..b73bf8d 100644 --- a/plugins/dspace/lib/dspace_plugin/library.rb +++ b/plugins/dspace/lib/dspace_plugin/library.rb @@ -1,9 +1,15 @@ class DspacePlugin::Library < Blog - settings_items :server_url, :type => :string, :default => "http://dspace.example.com/" + settings_items :dspace_server_url, :type => :string settings_items :gather_option, :type => :string, :default => "collections" - attr_accessible :server_url, :gather_option + attr_accessible :dspace_server_url, :gather_option + + def dspace_server_url_valid + errors.add(self.dspace_server_url, _("is not a valid URL. Please correct it and resubmit.")) unless url_valid?(self.dspace_server_url) + end + + validate :dspace_server_url_valid def self.icon_name(article = nil) 'dspace' @@ -32,4 +38,11 @@ class DspacePlugin::Library < Blog DspacePlugin::Collection.find(:all) end + protected + + def url_valid?(url) + url = URI.parse(url) rescue false + url.kind_of?(URI::HTTP) || url.kind_of?(URI::HTTPS) + end + end diff --git a/plugins/dspace/views/cms/dspace_plugin/_library.html.erb b/plugins/dspace/views/cms/dspace_plugin/_library.html.erb index 2807a20..19c385d 100644 --- a/plugins/dspace/views/cms/dspace_plugin/_library.html.erb +++ b/plugins/dspace/views/cms/dspace_plugin/_library.html.erb @@ -67,7 +67,7 @@ <%= labelled_form_field(_('Items per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> -<%= labelled_form_field(_('Address of DSpace library:'), text_field(:article, :server_url)) %> +<%= required f.text_field(:dspace_server_url, :size => '150', :maxlength => 150) %> <%= content_tag( 'div', radio_button( :article, :gather_option, 'collections' ) + content_tag('label', _('Get collections'), :for => 'article_get_collections')) %> -- libgit2 0.21.2