diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb index 82d4a80..43894bd 100644 --- a/app/controllers/my_profile/friends_controller.rb +++ b/app/controllers/my_profile/friends_controller.rb @@ -30,7 +30,8 @@ class FriendsController < MyProfileController end def invite - + @wizard = params[:wizard].blank? ? false : params[:wizard] + @step = 3 if request.post? && params[:import] begin case params[:import_from] @@ -80,7 +81,12 @@ class FriendsController < MyProfileController end flash[:notice] = __('Your invitations have been sent.') - redirect_to :action => 'index' + if @wizard + redirect_to :action => 'invite', :wizard => true + return + else + redirect_to :action => 'index' + end else flash.now[:notice] = __('Please enter a valid email address.') end @@ -92,6 +98,12 @@ class FriendsController < MyProfileController @import_from = params[:import_from] || "manual" @message = params[:message] || environment.message_for_friend_invitation + if @wizard + if !params[:import] + @friends = [] + end + render :layout => 'wizard' + end end end diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb index b7fb269..b8a1334 100644 --- a/app/controllers/my_profile/memberships_controller.rb +++ b/app/controllers/my_profile/memberships_controller.rb @@ -8,22 +8,36 @@ class MembershipsController < MyProfileController def leave @to_leave = Profile.find(params[:id]) - + @wizard = params[:wizard] if request.post? && params[:confirmation] @to_leave.remove_member(profile) - redirect_to :action => 'index' + if @wizard + redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + else + redirect_to :action => 'index' + end end end def new_community @community = Community.new(params[:community]) + @wizard = params[:wizard].blank? ? false : params[:wizard] if request.post? @community.environment = environment if @community.save @community.add_admin(profile) - redirect_to :action => 'index' + if @wizard + redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + return + else + redirect_to :action => 'index' + return + end end end + if @wizard + render :layout => 'wizard' + end end def destroy_community diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 2f4a0f8..bd62497 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -43,6 +43,8 @@ class AccountController < ApplicationController # action to register an user to the application def signup @invitation_code = params[:invitation_code] + @wizard = params[:wizard].blank? ? false : params[:wizard] + @step = 1 begin @user = User.new(params[:user]) @user.terms_of_use = environment.terms_of_use @@ -60,15 +62,36 @@ class AccountController < ApplicationController invitation.update_attributes!({:friend => @user.person}) invitation.finish end - go_to_user_initial_page if redirect? flash[:notice] = _("Thanks for signing up!") + if @wizard + redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + return + else + go_to_user_initial_page if redirect? + end end + if @wizard + render :layout => 'wizard' + end rescue ActiveRecord::RecordInvalid @person.valid? - render :action => 'signup' + if @wizard + render :action => 'signup', :layout => 'wizard' + else + render :action => 'signup' + end end end + def wizard + render :layout => false + end + + def profile_details + @profile = Profile.find_by_identifier(params[:profile]) + render :partial => 'profile_details', :layout => 'wizard' + end + # action to perform logout from the application def logout self.current_user.person.update_attribute(:last_lang, cookies[:lang]) @@ -204,6 +227,20 @@ class AccountController < ApplicationController end end + def check_url + @identifier = params[:identifier] + valid = Person.is_available?(@identifier) + if valid + @status = _('Available!') + @status_class = 'available' + else + @status = _('Unavailable!') + @status_class = 'unavailable' + end + @url = environment.top_url + '/' + @identifier + render :partial => 'identifier_status' + end + protected def redirect? diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 1935ea0..9a89675 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -7,11 +7,11 @@ class ProfileController < PublicController helper TagsHelper def index - @tags = profile.tags + @tags = profile.article_tags end def tags - @tags = profile.tags + @tags = profile.article_tags end def tag @@ -44,10 +44,15 @@ class ProfileController < PublicController end def join + @wizard = params[:wizard] if request.post? && params[:confirmation] profile.add_member(current_user.person) flash[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? - redirect_to profile.url + if @wizard + redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + else + redirect_to profile.url + end else if request.xhr? render :layout => false diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 45480e5..fc47ca9 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -151,6 +151,8 @@ class SearchController < PublicController end def index + @wizard = params[:wizard].blank? ? false : params[:wizard] + @step = 2 @query = params[:query] || '' @filtered_query = remove_stop_words(@query) @product_category = ProductCategory.find(params[:product_category]) if params[:product_category] @@ -175,12 +177,20 @@ class SearchController < PublicController if respond_to?(specific_action) @asset_name = getterm(@names[@results.keys.first]) send(specific_action) - render :action => specific_action + if @wizard + render :action => specific_action, :layout => 'wizard' + else + render :action => specific_action + end return end end - render :action => 'index' + if @wizard + render :action => 'index', :layout => 'wizard' + else + render :action => 'index' + end end alias :assets :index diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb index 1b63056..0c1b349 100644 --- a/app/helpers/account_helper.rb +++ b/app/helpers/account_helper.rb @@ -1,2 +1,56 @@ module AccountHelper -end \ No newline at end of file + + include GetText + + def button_to_step(type, step, current_step, html_options = {}) + if current_step == step + the_class = 'active' + if html_options.has_key?(:class) + html_options[:class] << " #{the_class}" + else + html_options[:class] = the_class + end + end + if step == 1 + url = '#' + else + url = send('url_step_' + step.to_s) + end + button(type, step.to_s, url, html_options) + end + + def button_to_step_without_text(type, step, html_options = {}) + url = 'url_step_' + step + button_without_text(type, step, send(url), html_options) + end + + def button_to_previous_step(step, html_options = {}) + step = step - 1 + if step > 1 + button_to_step_without_text(:left, step.to_s, html_options) + end + end + + def button_to_next_step(step, html_options = {}) + step = step + 1 + if step < 4 + button_to_step_without_text(:forward, step.to_s, html_options) + end + end + + def url_step_1 + options = {:controller => 'account', :action => 'signup', :wizard => true} + Noosfero.url_options.merge(options) + end + + def url_step_2 + options = {:controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true} + Noosfero.url_options.merge(options) + end + + def url_step_3 + options = {:controller => 'friends', :action => 'invite', :profile => user.identifier, :wizard => true} + Noosfero.url_options.merge(options) + end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f7b35bf..c54e13b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -24,6 +24,8 @@ module ApplicationHelper include DisplayHelper + include AccountHelper + # Displays context help. You can pass the content of the help message as the # first parameter or using template code inside a block passed to this # method. *Note*: the block is ignored if content is not @@ -403,6 +405,30 @@ module ApplicationHelper end end + # displays a link to add the profile with its image (as generated by + # #profile_image) or only its name below. + def profile_add_link( profile, image=false, size=:portrait, tag='li') + the_class = profile.members.include?(user) ? 'profile_member' : '' + name = profile.short_name + if image + display = content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + + content_tag( 'span', name, :class => 'org' ) + + profile_cat_icons( profile ) + the_class << ' vcard' + else + display = content_tag( 'span', name, :class => 'org' ) + end + content_tag tag, + link_to_remote( display, + :update => 'search-results', + :url => {:controller => 'account', :action => 'profile_details', :profile => profile.identifier}, + :onclick => 'document.location.href = this.href', # work-arround for ie. + :class => 'profile_link url', + :help => _('Click on this icon to add %s\'s to your network') % profile.name, + :title => profile.name ), + :class => the_class + end + # displays a link to the profile homepage with its image (as generated by # #profile_image) and its name below it. def profile_image_link( profile, size=:portrait, tag='li' ) diff --git a/app/helpers/friends_helper.rb b/app/helpers/friends_helper.rb new file mode 100644 index 0000000..40edf26 --- /dev/null +++ b/app/helpers/friends_helper.rb @@ -0,0 +1,7 @@ +module FriendsHelper + + def link_to_import(text, options = {}) + options.merge!({:action => 'invite', :import => 1, :wizard => true}) + link_to text, options + end +end diff --git a/app/models/environment.rb b/app/models/environment.rb index e6972a1..f8fef0d 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -46,6 +46,7 @@ class Environment < ActiveRecord::Base 'wysiwyg_editor_for_environment_home' => _('Use WYSIWYG editor to edit environment home page'), 'media_panel' => _('Media panel in WYSIWYG editor'), 'select_preferred_domain' => _('Select preferred domains per profile'), + 'display_wizard_signup' => _('Display wizard signup'), } end diff --git a/app/models/profile.rb b/app/models/profile.rb index c9a84bd..918a6fd 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -45,6 +45,8 @@ class Profile < ActiveRecord::Base acts_as_searchable :additional_fields => [ :extra_data_for_index ] + acts_as_taggable + # FIXME ugly workaround def self.human_attribute_name(attrib) _(self.superclass.human_attribute_name(attrib)) @@ -193,6 +195,10 @@ class Profile < ActiveRecord::Base self[:identifier] = value end + def self.is_available?(identifier) + !(identifier =~ IDENTIFIER_FORMAT).nil? && !RESERVED_IDENTIFIERS.include?(identifier) && Profile.find(:first, :conditions => ['environment_id = ? and identifier = ?', Environment.default.id, identifier]).nil? + end + validates_presence_of :identifier, :name validates_format_of :identifier, :with => IDENTIFIER_FORMAT, :if => lambda { |profile| !profile.identifier.blank? } validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS @@ -370,7 +376,7 @@ class Profile < ActiveRecord::Base end # FIXME this can be SLOW - def tags + def article_tags totals = {} articles.each do |article| article.tags.each do |tag| diff --git a/app/models/tags_block.rb b/app/models/tags_block.rb index f03a4a4..cf9f961 100644 --- a/app/models/tags_block.rb +++ b/app/models/tags_block.rb @@ -18,12 +18,12 @@ class TagsBlock < Block end def content - tags = owner.tags + tags = owner.article_tags return '' if tags.empty? block_title(title) + "\n
<%= @url %> <%= @status %>
+- <%= check_box 'user', 'terms_accepted' %> - <%= _('I accept the terms of use') %> -
+<%= labelled_check_box(_('I accept the terms of use'), 'user[terms_accepted]') %>
<% end %> <% if params[:enterprise_code] %> @@ -58,6 +72,10 @@ in this environment.') % [environment.name, __('communities'), __('enterprises') <% end %> <% button_bar do %> - <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> + <% if @wizard %> + <%= submit_button('save', _('Sign up'), :class => 'icon-menu-login') %> + <% else %> + <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> + <% end %> <% end %> <% end -%> diff --git a/app/views/account/_wizard_steps.rhtml b/app/views/account/_wizard_steps.rhtml new file mode 100644 index 0000000..59ee4dc --- /dev/null +++ b/app/views/account/_wizard_steps.rhtml @@ -0,0 +1,12 @@ +<%= __('Indicate which friends you want to invite.') %>
@@ -46,6 +51,7 @@ <% form_tag do %> <%= hidden_field_tag(:confirmation, 1) %> <%= hidden_field_tag(:import_from, @import_from) %> + <%= hidden_field_tag(:wizard, @wizard) %>