Commit abab689d9c5c449f38957d1afde377e240230306

Authored by Victor Costa
1 parent 003e4658

site_tour: add a block to configure step-by-step tour

plugins/site_tour/lib/site_tour_plugin.rb
... ... @@ -33,4 +33,8 @@ class SiteTourPlugin < Noosfero::Plugin
33 33 end
34 34 end
35 35  
  36 + def self.extra_blocks
  37 + { SiteTourPlugin::TourBlock => {} }
  38 + end
  39 +
36 40 end
... ...
plugins/site_tour/lib/site_tour_plugin/tour_block.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class SiteTourPlugin::TourBlock < Block
  2 +
  3 + settings_items :actions, :type => Array, :default => [{:group_name => 'tour_plugin', :selector => '.site-tour-plugin_tour-block .tour-button', :description => _('Click to start tour!')}]
  4 + settings_items :display_button, :type => :boolean, :default => true
  5 +
  6 + attr_accessible :actions, :display_button
  7 +
  8 + before_save do |block|
  9 + block.actions.reject! {|i| i[:group_name].blank? && i[:selector].blank? && i[:description].blank?}
  10 + end
  11 +
  12 + def self.description
  13 + _('Site Tour Block')
  14 + end
  15 +
  16 + def help
  17 + _('Configure a step-by-step tour.')
  18 + end
  19 +
  20 + def content(args={})
  21 + block = self
  22 + proc do
  23 + render :file => 'blocks/tour', :locals => {:block => block}
  24 + end
  25 + end
  26 +
  27 +end
... ...
plugins/site_tour/public/edit_tour_block.css 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +
  2 +#edit-tour-block #droppable-tour-actions {
  3 + padding-left: 23px;
  4 + margin-top: -12px;
  5 +}
  6 +
  7 +#edit-tour-block #droppable-tour-actions li {
  8 + list-style-type: none;
  9 +}
  10 +
  11 +#edit-tour-block .action-row {
  12 + line-height: 25px;
  13 + margin-bottom: 5px;
  14 + padding: 10px 1px 10px 10px;
  15 + cursor: pointer;
  16 + width: 97%;
  17 +}
  18 +
  19 +#edit-tour-block .action-row:hover {
  20 + background: #ddd url(../images/drag-and-drop.png) no-repeat;
  21 + background-position: 98% 15px;
  22 +}
  23 +
  24 +#edit-tour-block .action-row li {
  25 + list-style-type: none;
  26 + display: inline;
  27 + margin-left: 5px;
  28 +}
  29 +
  30 +#edit-tour-block {
  31 + width: 620px;
  32 + position: relative;
  33 + left: -24px;
  34 +}
  35 +
  36 +#edit-tour-block #new-template {
  37 + display: none;
  38 +}
  39 +
  40 +#edit-tour-block .list-header {
  41 + width: 98%;
  42 + height: 25px;
  43 + padding: 10px 1px 10px 10px;
  44 + margin-bottom: 5px;
  45 + cursor: pointer;
  46 +}
  47 +
  48 +#edit-tour-block .list-header li {
  49 + list-style-type: none;
  50 + display: inline;
  51 + font-weight: bold;
  52 + font-size: 14px;
  53 + text-align: center;
  54 +}
  55 +
  56 +#edit-tour-block .list-header .list-name {
  57 + margin-left: 50px;
  58 +}
  59 +#edit-tour-block .list-header .list-selector {
  60 + margin-left: 63px;
  61 +}
  62 +#edit-tour-block .list-header .list-description {
  63 + margin-left: 68px;
  64 +}
... ...
plugins/site_tour/public/edit_tour_block.js 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +function add_new_action() {
  2 + var new_action = jQuery('#edit-tour-block #new-template>li').clone();
  3 + new_action.show();
  4 + jQuery('#droppable-tour-actions').append(new_action);
  5 +}
  6 +
  7 +jQuery(document).ready(function(){
  8 + jQuery('#edit-tour-block').on('click', '.delete-tour-action-row', function() {
  9 + jQuery(this).parent().parent().remove();
  10 + return false;
  11 + });
  12 +
  13 + jQuery("#droppable-tour-actions").sortable({
  14 + revert: true,
  15 + axis: "y"
  16 + });
  17 +});
... ...
plugins/site_tour/test/unit/tour_block_test.rb 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class TrackListBlockTest < ActionView::TestCase
  4 +
  5 + ActionView::Base.send :include, ApplicationHelper
  6 +
  7 + def setup
  8 + @block = fast_create(SiteTourPlugin::TourBlock)
  9 + end
  10 +
  11 + attr_accessor :block
  12 +
  13 + should 'do not save empty actions' do
  14 + block.actions = [{:group_name => '', :selector => nil, :description => ' '}]
  15 + block.save!
  16 + assert_equal [], block.actions
  17 + end
  18 +
  19 + should 'render script tag in visualization mode' do
  20 + controller.expects(:boxes_editor?).returns(false)
  21 + assert_tag_in_string instance_eval(&block.content), :tag => 'script'
  22 + end
  23 +
  24 + should 'do not render script tag when editing' do
  25 + controller.expects(:boxes_editor?).returns(true)
  26 + controller.expects(:uses_design_blocks?).returns(true)
  27 + assert_no_tag_in_string instance_eval(&block.content), :tag => 'script'
  28 + end
  29 +
  30 + should 'display help button' do
  31 + controller.expects(:boxes_editor?).returns(false)
  32 + assert_tag_in_string instance_eval(&block.content), :tag => 'a', :attributes => {:class => 'button icon-help with-text tour-button'}
  33 + end
  34 +
  35 + should 'do not display help button when display_button is false' do
  36 + block.display_button = false
  37 + controller.expects(:boxes_editor?).returns(false)
  38 + assert_no_tag_in_string instance_eval(&block.content), :tag => 'a', :attributes => {:class => 'button icon-help with-text tour-button'}
  39 + end
  40 +
  41 +end
... ...
plugins/site_tour/views/blocks/tour.html.erb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<% if block.display_button %>
  4 + <%= button :help, _('Help'), '#', :class => 'tour-button', :onclick => 'siteTourPlugin.force();' %>
  5 +<% end %>
  6 +
  7 +<% edit_mode = controller.send(:boxes_editor?) && controller.send(:uses_design_blocks?) %>
  8 +
  9 +<% unless edit_mode %>
  10 + <script>
  11 + jQuery( document ).ready(function( $ ) {
  12 + <% block.actions.each_with_index do |action, index| %>
  13 + <%= "siteTourPlugin.add('#{j action[:group_name]}','#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %>
  14 + <% end %>
  15 + });
  16 + </script>
  17 +<% end %>
... ...
plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +<%= javascript_include_tag '/plugins/site_tour/edit_tour_block.js' %>
  2 +<%= stylesheet_link_tag '/plugins/site_tour/edit_tour_block.css' %>
  3 +
  4 +<%= labelled_form_field check_box(:block, :display_button) + _('Display help button'), '' %>
  5 +
  6 +<strong><%= _('Actions') %></strong>
  7 +<div id='edit-tour-block'>
  8 + <ul class='list-header'>
  9 + <li class='list-name'><%= _('Group Name') %></li>
  10 + <li class='list-selector'><%= _('Selector') %></li>
  11 + <li class='list-description'><%= _('Description') %></li>
  12 + </ul>
  13 + <ul id="droppable-tour-actions">
  14 + <% for action in @block.actions do %>
  15 + <%= render :partial => 'box_organizer/site_tour_plugin/tour_block_item', :locals => {:action => action} %>
  16 + <% end %>
  17 + </ul>
  18 +
  19 + <div id="new-template">
  20 + <% template_action = {} %>
  21 + <%= render :partial => 'box_organizer/site_tour_plugin/tour_block_item', :locals => {:action => template_action} %>
  22 + </div>
  23 +</div>
  24 +
  25 +<%= link_to_function(_('New'), 'add_new_action();', :class => 'button icon-add with-text') %>
... ...
plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block_item.html.erb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +<li>
  2 + <ul class="action-row">
  3 + <li>
  4 + <%= text_field_tag 'block[actions][][group_name]', action[:group_name], :class => 'group-name', :maxlength => 20 %>
  5 + </li>
  6 + <li>
  7 + <%= text_field_tag 'block[actions][][selector]', action[:selector], :class => 'selector' %>
  8 + </li>
  9 + <li>
  10 + <%= text_field_tag 'block[actions][][description]', action[:description], :class => 'description' %>
  11 + </li>
  12 + <li>
  13 + <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-tour-action-row") %>
  14 + </li>
  15 + </ul>
  16 +</li>
... ...
plugins/site_tour/views/environment_design/site_tour_plugin 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../box_organizer/site_tour_plugin
0 2 \ No newline at end of file
... ...
plugins/site_tour/views/profile_design/site_tour_plugin 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../box_organizer/site_tour_plugin
0 2 \ No newline at end of file
... ...