Commit 5a3e07324d6b59edcbe160b380438d6b71a5021e

Authored by Victor Costa
2 parents 8afc3c46 e343a145

Merge branch 'site_tour' into stable

plugins/site_tour/controllers/site_tour_plugin_admin_controller.rb
... ... @@ -10,11 +10,15 @@ class SiteTourPluginAdminController < PluginAdminController
10 10  
11 11 @settings = Noosfero::Plugin::Settings.new(environment, SiteTourPlugin, settings)
12 12 @settings.actions_csv = convert_to_csv(@settings.actions)
  13 + @settings.group_triggers_csv = convert_to_csv(@settings.group_triggers)
13 14  
14 15 if request.post?
15   - @settings.actions = convert_from_csv(settings[:actions_csv])
  16 + @settings.actions = convert_actions_from_csv(settings[:actions_csv])
16 17 @settings.settings.delete(:actions_csv)
17 18  
  19 + @settings.group_triggers = convert_group_triggers_from_csv(settings[:group_triggers_csv])
  20 + @settings.settings.delete(:group_triggers_csv)
  21 +
18 22 @settings.save!
19 23 session[:notice] = 'Settings succefully saved.'
20 24 redirect_to :action => 'index'
... ... @@ -25,14 +29,22 @@ class SiteTourPluginAdminController < PluginAdminController
25 29  
26 30 def convert_to_csv(actions)
27 31 CSV.generate do |csv|
28   - (@settings.actions||[]).each { |action| csv << action.values }
  32 + (actions||[]).each { |action| csv << action.values }
29 33 end
30 34 end
31 35  
32   - def convert_from_csv(actions_csv)
  36 + def convert_actions_from_csv(actions_csv)
  37 + return [] if actions_csv.blank?
33 38 CSV.parse(actions_csv).map do |action|
34 39 {:language => action[0], :group_name => action[1], :selector => action[2], :description => action[3]}
35 40 end
36 41 end
37 42  
  43 + def convert_group_triggers_from_csv(group_triggers_csv)
  44 + return [] if group_triggers_csv.blank?
  45 + CSV.parse(group_triggers_csv).map do |group|
  46 + {:group_name => group[0], :selector => group[1], :event => group[2]}
  47 + end
  48 + end
  49 +
38 50 end
... ...
plugins/site_tour/lib/site_tour_plugin.rb
... ... @@ -29,7 +29,7 @@ class SiteTourPlugin &lt; Noosfero::Plugin
29 29 settings = Noosfero::Plugin::Settings.new(environment, SiteTourPlugin)
30 30 actions = (settings.actions||[]).select {|action| action[:language] == language}
31 31  
32   - render(:file => 'tour_actions', :locals => { :actions => actions, :js_file => js_file})
  32 + render(:file => 'tour_actions', :locals => { :actions => actions, :group_triggers => settings.group_triggers, :js_file => js_file})
33 33 end
34 34 end
35 35  
... ...
plugins/site_tour/lib/site_tour_plugin/tour_block.rb
1 1 class SiteTourPlugin::TourBlock < Block
2 2  
3 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 :group_triggers, :type => Array, :default => []
4 5 settings_items :display_button, :type => :boolean, :default => true
5 6  
6   - attr_accessible :actions, :display_button
  7 + attr_accessible :actions, :display_button, :group_triggers
7 8  
8 9 before_save do |block|
9 10 block.actions.reject! {|i| i[:group_name].blank? && i[:selector].blank? && i[:description].blank?}
  11 + block.group_triggers.reject! {|i| i[:group_name].blank? && i[:selector].blank? && i[:event].blank?}
10 12 end
11 13  
12 14 def self.description
... ...
plugins/site_tour/public/main.js
1 1 var siteTourPlugin = (function() {
2 2  
3 3 var actions = [];
  4 + var groupTriggers = [];
4 5 var userData = {};
  6 + var intro;
5 7  
6 8 function hasMark(name) {
7 9 return jQuery.cookie("_noosfero_.sitetour." + name) ||
... ... @@ -19,7 +21,7 @@ var siteTourPlugin = (function() {
19 21 jQuery('.site-tour-plugin').removeAttr('data-intro data-intro-name data-step');
20 22 }
21 23  
22   - function configureIntro(force) {
  24 + function configureIntro(force, actions) {
23 25 clearAll();
24 26 for(var i=0; i<actions.length; i++) {
25 27 var action = actions[i];
... ... @@ -38,20 +40,43 @@ var siteTourPlugin = (function() {
38 40 }
39 41 }
40 42  
  43 + function actionsOnload() {
  44 + var groups = jQuery.map(groupTriggers, function(g) { return g.name; });
  45 + return jQuery.grep(actions, function(n, i) { return jQuery.inArray(n.name, groups); });
  46 + }
  47 +
  48 + function actionsByGroup(group) {
  49 + return jQuery.grep(actions, function(n, i) { return n.name===group });
  50 + }
  51 +
  52 + function forceParam() {
  53 + return jQuery.deparam.querystring()['siteTourPlugin']==='force';
  54 + }
  55 +
41 56 return {
42 57 add: function (name, selector, text, step) {
43 58 actions.push({name: name, selector: selector, text: text, step: step});
44 59 },
  60 + addGroupTrigger: function(name, selector, ev) {
  61 + groupTriggers.push({name: name, selector: selector, event: ev});
  62 + plugin = this;
  63 + var handler = function() {
  64 + configureIntro(forceParam(), actionsByGroup(name));
  65 + intro.start();
  66 + jQuery(document).off(ev, selector, handler);
  67 + };
  68 + jQuery(document).on(ev, selector, handler);
  69 + },
45 70 start: function(data, force) {
46   - force = typeof force !== 'undefined' ? force : false;
  71 + force = typeof force !== 'undefined' ? force : false || forceParam();
47 72 userData = data;
48 73  
49   - var intro = introJs();
  74 + intro = introJs();
50 75 intro.onafterchange(function(targetElement) {
51 76 var name = jQuery(targetElement).attr('data-intro-name');
52 77 mark(name);
53 78 });
54   - configureIntro(force);
  79 + configureIntro(force, actionsOnload);
55 80 intro.start();
56 81 },
57 82 force: function() {
... ... @@ -62,6 +87,6 @@ var siteTourPlugin = (function() {
62 87  
63 88 jQuery( document ).ready(function( $ ) {
64 89 $(window).bind('userDataLoaded', function(event, data) {
65   - siteTourPlugin.start(data, jQuery.deparam.querystring()['siteTourPlugin']==='force');
  90 + siteTourPlugin.start(data);
66 91 });
67 92 });
... ...
plugins/site_tour/test/functional/site_tour_plugin_admin_controller_test.rb
... ... @@ -17,6 +17,13 @@ class SiteTourPluginAdminControllerTest &lt; ActionController::TestCase
17 17 assert_equal [{:language => 'en', :group_name => 'tour_plugin', :selector => '.tour-button', :description => 'Click'}], @settings.actions
18 18 end
19 19  
  20 + should 'parse csv and save group triggers array in plugin settings' do
  21 + group_triggers_csv = "tour_plugin,.tour-button,mouseenter"
  22 + post :index, :settings => {"group_triggers_csv" => group_triggers_csv}
  23 + @settings = Noosfero::Plugin::Settings.new(environment.reload, SiteTourPlugin)
  24 + assert_equal [{:group_name => 'tour_plugin', :selector => '.tour-button', :event => 'mouseenter'}], @settings.group_triggers
  25 + end
  26 +
20 27 should 'do not store actions_csv' do
21 28 actions_csv = "en,tour_plugin,.tour-button,Click"
22 29 post :index, :settings => {"actions_csv" => actions_csv}
... ...
plugins/site_tour/views/blocks/tour.html.erb
... ... @@ -7,5 +7,5 @@
7 7 <% edit_mode = controller.send(:boxes_editor?) && controller.send(:uses_design_blocks?) %>
8 8  
9 9 <% unless edit_mode %>
10   - <%= render :file => 'tour_actions', :locals => {:actions => block.actions} %>
  10 + <%= render :file => 'tour_actions', :locals => {:actions => block.actions, :group_triggers => block.group_triggers} %>
11 11 <% end %>
... ...
plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb
... ... @@ -3,7 +3,7 @@
3 3  
4 4 <%= labelled_form_field check_box(:block, :display_button) + _('Display help button'), '' %>
5 5  
6   -<strong><%= _('Actions') %></strong>
  6 +<strong><%= _('Tooltip Actions') %></strong>
7 7 <div id='edit-tour-block'>
8 8 <ul class='list-header'>
9 9 <li class='list-name'><%= _('Group Name') %></li>
... ...
plugins/site_tour/views/site_tour_plugin_admin/index.html.erb
... ... @@ -3,6 +3,7 @@
3 3 <%= form_for(:settings) do |f| %>
4 4  
5 5 <%= labelled_form_field _('Tooltips (CSV format: language, group name, selector, description)'), f.text_area(:actions_csv, :style => 'width: 100%', :class => 'actions-csv') %>
  6 + <%= labelled_form_field _('Group Triggers (CSV format: group name, selector, event (e.g. mouseenter, click))'), f.text_area(:group_triggers_csv, :style => 'width: 100%', :class => 'groups-csv', :rows => 7) %>
6 7  
7 8 <% button_bar do %>
8 9 <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %>
... ...
plugins/site_tour/views/tour_actions.html.erb
... ... @@ -5,8 +5,13 @@
5 5 <script>
6 6 jQuery( document ).ready(function( $ ) {
7 7 <% actions.each_with_index do |action, index| %>
8   - <%= "siteTourPlugin.add('#{j action[:group_name]}','#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %>
  8 + <%= "siteTourPlugin.add('#{j action[:group_name]}', '#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %>
9 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 %>
  14 +
10 15 });
11 16 </script>
12 17 <% end %>
... ...