Commit 8a213fa704c8de874c5be4e149bd21b5c83f9897
1 parent
6950a50d
Exists in
staging
and in
4 other branches
rename setting item 'server_url' to 'dspace_server_url'; add validation for sett…
…ing item/field 'dspace_server_url'
Showing
2 changed files
with
16 additions
and
3 deletions
Show diff stats
plugins/dspace/lib/dspace_plugin/library.rb
1 | 1 | class DspacePlugin::Library < Blog |
2 | 2 | |
3 | - settings_items :server_url, :type => :string, :default => "http://dspace.example.com/" | |
3 | + settings_items :dspace_server_url, :type => :string | |
4 | 4 | settings_items :gather_option, :type => :string, :default => "collections" |
5 | 5 | |
6 | - attr_accessible :server_url, :gather_option | |
6 | + attr_accessible :dspace_server_url, :gather_option | |
7 | + | |
8 | + def dspace_server_url_valid | |
9 | + errors.add(self.dspace_server_url, _("is not a valid URL. Please correct it and resubmit.")) unless url_valid?(self.dspace_server_url) | |
10 | + end | |
11 | + | |
12 | + validate :dspace_server_url_valid | |
7 | 13 | |
8 | 14 | def self.icon_name(article = nil) |
9 | 15 | 'dspace' |
... | ... | @@ -32,4 +38,11 @@ class DspacePlugin::Library < Blog |
32 | 38 | DspacePlugin::Collection.find(:all) |
33 | 39 | end |
34 | 40 | |
41 | + protected | |
42 | + | |
43 | + def url_valid?(url) | |
44 | + url = URI.parse(url) rescue false | |
45 | + url.kind_of?(URI::HTTP) || url.kind_of?(URI::HTTPS) | |
46 | + end | |
47 | + | |
35 | 48 | end | ... | ... |
plugins/dspace/views/cms/dspace_plugin/_library.html.erb
... | ... | @@ -67,7 +67,7 @@ |
67 | 67 | |
68 | 68 | <%= labelled_form_field(_('Items per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> |
69 | 69 | |
70 | -<%= labelled_form_field(_('Address of DSpace library:'), text_field(:article, :server_url)) %> | |
70 | +<%= required f.text_field(:dspace_server_url, :size => '150', :maxlength => 150) %> | |
71 | 71 | |
72 | 72 | <%= content_tag( 'div', radio_button( :article, :gather_option, 'collections' ) + content_tag('label', _('Get collections'), :for => 'article_get_collections')) %> |
73 | 73 | ... | ... |