Commit f76beedf10848d0b4faeaa181a680322fbd54b7a

Authored by Victor Costa
1 parent d4a3f0fd

virtuoso: select a custom query when creating a new template

plugins/virtuoso/controllers/public/virtuoso_plugin_public_controller.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class VirtuosoPluginPublicController < PublicController
  2 +
  3 + def custom_query
  4 + render :json => environment.virtuoso_plugin_custom_queries.find(params[:id])
  5 + end
  6 +
  7 +end
... ...
plugins/virtuoso/public/custom_query.js 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +jQuery(document).ready(function($) {
  2 + $('#copy_custom_query').on('click', function() {
  3 + $.getJSON("/plugin/virtuoso/public/custom_query", {id: $('#select_custom_query').val()}, function(data) {
  4 + $('#article_query').val(data.custom_query.query);
  5 + tinymce.get('article_template').setContent(data.custom_query.template);
  6 + });
  7 + });
  8 +});
... ...
plugins/virtuoso/views/cms/virtuoso_plugin/_triples_template.html.erb
... ... @@ -4,8 +4,14 @@
4 4 <%= render :file => 'shared/tiny_mce' %>
5 5  
6 6 <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %>
7   - <%= labelled_form_field(_('SPARQL Query'), text_area(:article, :query, :style => 'width: 98%; height: 120px;')) %>
8 7  
  8 + <div class="custom-query">
  9 + <span class="label"><%= _('Custom Query/Template selection: ') %></span>
  10 + <%= select_tag :select_custom_query, options_from_collection_for_select(environment.virtuoso_plugin_custom_queries, :id, :name) %>
  11 + <%= button :clone, _('Copy'), '#', :id => 'copy_custom_query' %>
  12 + </div>
  13 +
  14 + <%= labelled_form_field(_('SPARQL Query'), text_area(:article, :query, :style => 'width: 98%; height: 120px;')) %>
9 15 <div class="template">
10 16 <span class="label"><%= _('Template') %></span>
11 17 <span class="reference" style="float: right;"><a href="https://github.com/Shopify/liquid/wiki/Liquid-for-Designers"><%= _('Template reference') %></a></span>
... ... @@ -17,3 +23,4 @@
17 23 <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %>
18 24 <%= render :partial => 'general_fields' %>
19 25 </div>
  26 +<%= javascript_include_tag '/plugins/virtuoso/custom_query.js' %>
... ...