Commit a47c9449ff652631af9dc996b6db33a4711fc5cb

Authored by Victor Costa
2 parents 377edbac 0056aa48

Merge branch 'site_tour' into stable

Conflicts:
	plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb
	plugins/site_tour/views/tour_actions.html.erb
plugins/site_tour/public/edit_tour_block.css
  1 +#edit-tour-block .list-items {
  2 + margin-bottom: 25px;
  3 +}
1 4  
2   -#edit-tour-block #droppable-tour-actions {
3   - padding-left: 23px;
  5 +#edit-tour-block .droppable-items {
  6 + padding-left: 0;
4 7 margin-top: -12px;
5 8 }
6 9  
7   -#edit-tour-block #droppable-tour-actions li {
  10 +#edit-tour-block .droppable-items li {
8 11 list-style-type: none;
9 12 }
10 13  
11   -#edit-tour-block .action-row {
  14 +#edit-tour-block .item-row {
12 15 line-height: 25px;
13 16 margin-bottom: 5px;
14   - padding: 10px 1px 10px 10px;
  17 + padding: 0;
15 18 cursor: pointer;
16 19 width: 97%;
17 20 }
18 21  
19   -#edit-tour-block .action-row:hover {
20   - background: #ddd url(../images/drag-and-drop.png) no-repeat;
  22 +#edit-tour-block .item-row:hover {
  23 + background: #ddd url(/images/drag-and-drop.png) no-repeat;
21 24 background-position: 98% 15px;
22 25 }
23 26  
24   -#edit-tour-block .action-row li {
  27 +#edit-tour-block .item-row li {
25 28 list-style-type: none;
26 29 display: inline;
27 30 margin-left: 5px;
... ... @@ -30,7 +33,6 @@
30 33 #edit-tour-block {
31 34 width: 620px;
32 35 position: relative;
33   - left: -24px;
34 36 }
35 37  
36 38 #edit-tour-block #new-template {
... ... @@ -39,8 +41,7 @@
39 41  
40 42 #edit-tour-block .list-header {
41 43 width: 98%;
42   - height: 25px;
43   - padding: 10px 1px 10px 10px;
  44 + padding: 0 1px 10px 10px;
44 45 margin-bottom: 5px;
45 46 cursor: pointer;
46 47 }
... ... @@ -49,16 +50,16 @@
49 50 list-style-type: none;
50 51 display: inline;
51 52 font-weight: bold;
52   - font-size: 14px;
  53 + font-size: 12px;
53 54 text-align: center;
54 55 }
55 56  
56 57 #edit-tour-block .list-header .list-name {
57   - margin-left: 50px;
  58 + margin-left: 20px;
58 59 }
59 60 #edit-tour-block .list-header .list-selector {
60 61 margin-left: 63px;
61 62 }
62   -#edit-tour-block .list-header .list-description {
  63 +#edit-tour-block .list-header .list-description, #edit-tour-block .list-header .list-event {
63 64 margin-left: 68px;
64 65 }
... ...
plugins/site_tour/public/edit_tour_block.js
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 1 jQuery(document).ready(function(){
8   - jQuery('#edit-tour-block').on('click', '.delete-tour-action-row', function() {
  2 + jQuery('#edit-tour-block').on('click', '.add-item', function() {
  3 + var container = jQuery(this).closest('.list-items');
  4 + var new_action = container.find('#new-template>li').clone();
  5 + new_action.show();
  6 + container.find('.droppable-items').append(new_action);
  7 + });
  8 +
  9 + jQuery('#edit-tour-block').on('click', '.delete-tour-block-item', function() {
9 10 jQuery(this).parent().parent().remove();
10 11 return false;
11 12 });
12 13  
13   - jQuery("#droppable-tour-actions").sortable({
  14 + jQuery("#edit-tour-block .droppable-items").sortable({
14 15 revert: true,
15 16 axis: "y"
16 17 });
... ...
plugins/site_tour/test/functional/site_tour_plugin_admin_controller_test.rb
... ... @@ -31,13 +31,29 @@ class SiteTourPluginAdminControllerTest < ActionController::TestCase
31 31 assert_equal nil, @settings.settings[:actions_csv]
32 32 end
33 33  
  34 + should 'do not store group_triggers_csv' do
  35 + group_triggers_csv = "tour_plugin,.tour-button,click"
  36 + post :index, :settings => {"group_triggers_csv" => group_triggers_csv}
  37 + @settings = Noosfero::Plugin::Settings.new(environment.reload, SiteTourPlugin)
  38 + assert_equal nil, @settings.settings[:group_triggers_csv]
  39 + end
  40 +
34 41 should 'convert actions array to csv to enable user edition' do
35 42 @settings = Noosfero::Plugin::Settings.new(environment.reload, SiteTourPlugin)
36 43 @settings.actions = [{:language => 'en', :group_name => 'tour_plugin', :selector => '.tour-button', :description => 'Click'}]
37 44 @settings.save!
38 45  
39 46 get :index
40   - assert_tag :tag => 'textarea', :content => "\nen,tour_plugin,.tour-button,Click\n"
  47 + assert_tag :tag => 'textarea', :attributes => {:class => 'actions-csv'}, :content => "\nen,tour_plugin,.tour-button,Click\n"
  48 + end
  49 +
  50 + should 'convert group_triggers array to csv to enable user edition' do
  51 + @settings = Noosfero::Plugin::Settings.new(environment.reload, SiteTourPlugin)
  52 + @settings.group_triggers = [{:group_name => 'tour_plugin', :selector => '.tour-button', :event => 'click'}]
  53 + @settings.save!
  54 +
  55 + get :index
  56 + assert_tag :tag => 'textarea', :attributes => {:class => 'groups-csv'}, :content => "\ntour_plugin,.tour-button,click\n"
41 57 end
42 58  
43 59 end
... ...
plugins/site_tour/test/unit/site_tour_plugin_test.rb
... ... @@ -38,4 +38,36 @@ class SiteTourPluginTest < ActionView::TestCase
38 38 assert_no_tag_in_string instance_exec(&plugin.body_ending), :tag => "script"
39 39 end
40 40  
  41 + should 'render javascript tag with tooltip actions and group triggers' do
  42 + expects(:language).returns('en').at_least_once
  43 +
  44 + settings = Noosfero::Plugin::Settings.new(Environment.default, SiteTourPlugin)
  45 + settings.actions = [{:language => 'en', :group_name => 'test', :selector => 'body', :description => 'Test'}]
  46 + settings.group_triggers = [{:group_name => 'test', :selector => 'body', :event => 'click'}]
  47 + settings.save!
  48 +
  49 + expects(:environment).returns(Environment.default)
  50 + body_ending = instance_exec(&plugin.body_ending)
  51 + assert_match /siteTourPlugin\.add\('test', 'body', 'Test', 1\);/, body_ending
  52 + assert_match /siteTourPlugin\.addGroupTrigger\('test', 'body', 'click'\);/, body_ending
  53 + end
  54 +
  55 + should 'start each tooltip group with the correct step order' do
  56 + expects(:language).returns('en').at_least_once
  57 +
  58 + settings = Noosfero::Plugin::Settings.new(Environment.default, SiteTourPlugin)
  59 + settings.actions = [
  60 + {:language => 'en', :group_name => 'test_a', :selector => 'body', :description => 'Test A1'},
  61 + {:language => 'en', :group_name => 'test_a', :selector => 'body', :description => 'Test A2'},
  62 + {:language => 'en', :group_name => 'test_b', :selector => 'body', :description => 'Test B1'},
  63 + ]
  64 + settings.save!
  65 +
  66 + expects(:environment).returns(Environment.default)
  67 + body_ending = instance_exec(&plugin.body_ending)
  68 + assert_match /siteTourPlugin\.add\('test_a', 'body', 'Test A1', 1\);/, body_ending
  69 + assert_match /siteTourPlugin\.add\('test_a', 'body', 'Test A2', 2\);/, body_ending
  70 + assert_match /siteTourPlugin\.add\('test_b', 'body', 'Test B1', 1\);/, body_ending
  71 + end
  72 +
41 73 end
... ...
plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb
... ... @@ -3,23 +3,41 @@
3 3  
4 4 <%= labelled_form_field check_box(:block, :display_button) + _('Display help button'), '' %>
5 5  
6   -<strong><%= _('Tooltip Actions') %></strong>
7 6 <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>
  7 + <div id="tooltip-actions" class="list-items">
  8 + <h3><%= _('Tooltip Actions') %></h3>
  9 + <ul class='list-header'>
  10 + <li class='list-name'><%= _('Group Name') %></li>
  11 + <li class='list-selector'><%= _('Selector') %></li>
  12 + <li class='list-description'><%= _('Description') %></li>
  13 + </ul>
  14 + <ul id="droppable-tour-actions" class="droppable-items">
  15 + <% for action in @block.actions do %>
  16 + <%= render :partial => 'box_organizer/site_tour_plugin/tour_block_item', :locals => {:action => action} %>
  17 + <% end %>
  18 + </ul>
  19 + <div id="new-template">
  20 + <%= render :partial => 'box_organizer/site_tour_plugin/tour_block_item', :locals => {:action => {} } %>
  21 + </div>
  22 + <%= link_to_function(_('New Tooltip'), :class => 'add-item button icon-add with-text') %>
  23 + </div>
18 24  
19   - <div id="new-template">
20   - <% template_action = {} %>
21   - <%= render :partial => 'box_organizer/site_tour_plugin/tour_block_item', :locals => {:action => template_action} %>
  25 + <div id="group-triggers" class="list-items">
  26 + <h3><%= _('Group Triggers') %></h3>
  27 + <ul class='list-header'>
  28 + <li class='list-name'><%= _('Group Name') %></li>
  29 + <li class='list-selector'><%= _('Selector') %></li>
  30 + <li class='list-event'><%= _('Event') %></li>
  31 + </ul>
  32 + <ul id="droppable-tour-group-triggers" class="droppable-items">
  33 + <% for group in @block.group_triggers do %>
  34 + <%= render :partial => 'box_organizer/site_tour_plugin/tour_block_group_item', :locals => {:group => group} %>
  35 + <% end %>
  36 + </ul>
  37 + <div id="new-template">
  38 + <%= render :partial => 'box_organizer/site_tour_plugin/tour_block_group_item', :locals => {:group => {} } %>
  39 + </div>
  40 + <%= link_to_function(_('New Group Trigger'), :class => 'add-item button icon-add with-text') %>
22 41 </div>
23   -</div>
24 42  
25   -<%= link_to_function(_('New'), 'add_new_action();', :class => 'button icon-add with-text') %>
  43 +</div>
... ...
plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block_group_item.html.erb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +<li>
  2 + <ul class="item-row">
  3 + <li>
  4 + <%= text_field_tag 'block[group_triggers][][group_name]', group[:group_name], :class => 'group-name', :maxlength => 20 %>
  5 + </li>
  6 + <li>
  7 + <%= text_field_tag 'block[group_triggers][][selector]', group[:selector], :class => 'selector' %>
  8 + </li>
  9 + <li>
  10 + <%= text_field_tag 'block[group_triggers][][event]', group[:event], :class => 'description' %>
  11 + </li>
  12 + <li>
  13 + <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-tour-block-item") %>
  14 + </li>
  15 + </ul>
  16 +</li>
  17 +
... ...
plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block_item.html.erb
1 1 <li>
2   - <ul class="action-row">
  2 + <ul class="item-row">
3 3 <li>
4 4 <%= text_field_tag 'block[actions][][group_name]', action[:group_name], :class => 'group-name', :maxlength => 20 %>
5 5 </li>
... ... @@ -10,7 +10,7 @@
10 10 <%= text_field_tag 'block[actions][][description]', action[:description], :class => 'description' %>
11 11 </li>
12 12 <li>
13   - <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-tour-action-row") %>
  13 + <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-tour-block-item") %>
14 14 </li>
15 15 </ul>
16 16 </li>
... ...
plugins/site_tour/views/tour_actions.html.erb
... ... @@ -4,14 +4,15 @@
4 4 <% if actions.present? %>
5 5 <script>
6 6 jQuery( document ).ready(function( $ ) {
7   - <% actions.each_with_index do |action, index| %>
8   - <%= "siteTourPlugin.add('#{j action[:group_name]}', '#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %>
9   - <% end %>
10   -
11   - <% (group_triggers||[]).each_with_index do |group, index| %>
12   - <%= "siteTourPlugin.addGroupTrigger('#{j group[:group_name]}', '#{j group[:selector]}', '#{j group[:event]}');" %>
13   - <% end %>
  7 + <% actions.group_by {|h| h[:group_name]}.each do |group, group_actions| %>
  8 + <% group_actions.each_with_index do |action, index| %>
  9 + <%= "siteTourPlugin.add('#{j action[:group_name]}', '#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %>
  10 + <% end %>
  11 + <% end %>
14 12  
  13 + <% (group_triggers||[]).each_with_index do |group, index| %>
  14 + <%= "siteTourPlugin.addGroupTrigger('#{j group[:group_name]}', '#{j group[:selector]}', '#{j group[:event]}');" %>
  15 + <% end %>
15 16 });
16 17 </script>
17 18 <% end %>
... ...