Commit 3eef3769d993aa8e59f7f0463d0cd791c4a74d29
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'virtuoso_integration' of gitlab.com:participa/noosfero into virtuoso_integration
Showing
2 changed files
with
33 additions
and
2 deletions
Show diff stats
plugins/virtuoso/public/triples_management.js
1 | +function is_valid_url(url) { | |
2 | + var pattern =/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/i; | |
3 | + return pattern.test(url); | |
4 | +} | |
5 | + | |
6 | +function validate_search_form() { | |
7 | + graph_uri = jQuery("input#graph_uri"); | |
8 | + query = jQuery("textarea#query"); | |
9 | + | |
10 | + if ( !is_valid_url(graph_uri.val())) { | |
11 | + alert( TRIPLES_MANAGEMENT_GRAPH_URI_REQUIRED_MESSAGE ); | |
12 | + graph_uri.focus(); | |
13 | + return false; | |
14 | + } | |
15 | + | |
16 | + pattern = /.*select\s.*/i | |
17 | + if (!pattern.test(query.val())) { | |
18 | + alert( TRIPLES_MANAGEMENT_QUERY_REQUIRED_MESSAGE ); | |
19 | + query.focus(); | |
20 | + return false; | |
21 | + } | |
22 | + | |
23 | + jQuery("#form-triples-search").submit(); | |
24 | + | |
25 | +} | |
26 | + | |
1 | 27 | function update_triple(triple_id) { |
2 | 28 | graph = jQuery("input#graph_uri").val(); |
3 | 29 | ... | ... |
plugins/virtuoso/views/virtuoso_plugin_admin/triple_management.html.erb
1 | 1 | <div id="virtuoso-triples-management"> |
2 | 2 | <h1><%= _('Virtuoso settings » Triples Management')%></h1> |
3 | 3 | |
4 | - <%= form_tag('/admin/plugin/virtuoso/triples_management', :method => 'post') do %> | |
4 | + <%= form_tag('/admin/plugin/virtuoso/triples_management', :method => 'post', :id => 'form-triples-search') do %> | |
5 | 5 | <%= labelled_form_field(_('Graph URI:'), text_field_tag(:graph_uri, @graph_uri) ) %> |
6 | 6 | <%= labelled_form_field(_('Query SPARQL:'), text_area_tag(:query, @query, :rows => 7)) %> |
7 | 7 | <% button_bar do %> |
8 | - <%= submit_button(:search, _('Search triples')) %> | |
8 | + <%= submit_button(:search, _('Search triples'), :onclick => "validate_search_form(); return false;") %> | |
9 | 9 | <%= colorbox_button('add', _('Add a triple'), { :action => 'add_triple' }) %> |
10 | 10 | <% end %> |
11 | 11 | <% end %> |
... | ... | @@ -54,4 +54,9 @@ |
54 | 54 | |
55 | 55 | </div> |
56 | 56 | |
57 | +<script type="text/javascript"> | |
58 | + TRIPLES_MANAGEMENT_GRAPH_URI_REQUIRED_MESSAGE = '<%= _('A valid GRAPH URI is required') %>'; | |
59 | + TRIPLES_MANAGEMENT_QUERY_REQUIRED_MESSAGE = '<%= _('A valid QUERY is required') %>'; | |
60 | +</script> | |
61 | + | |
57 | 62 | <%= javascript_include_tag '/plugins/virtuoso/triples_management.js' %> | ... | ... |