From 001bf74b64072578f9f803aa8212415e9ba04024 Mon Sep 17 00:00:00 2001 From: Daniela Feitosa Date: Sat, 9 May 2009 06:03:17 -0300 Subject: [PATCH] ActionItem1020: Adding wizard on signup --- app/controllers/my_profile/friends_controller.rb | 16 ++++++++++++++-- app/controllers/my_profile/memberships_controller.rb | 20 +++++++++++++++++--- app/controllers/public/account_controller.rb | 41 +++++++++++++++++++++++++++++++++++++++-- app/controllers/public/profile_controller.rb | 11 ++++++++--- app/controllers/public/search_controller.rb | 14 ++++++++++++-- app/helpers/account_helper.rb | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- app/helpers/application_helper.rb | 26 ++++++++++++++++++++++++++ app/helpers/friends_helper.rb | 7 +++++++ app/models/environment.rb | 1 + app/models/profile.rb | 8 +++++++- app/models/tags_block.rb | 4 ++-- app/views/account/_identifier_status.rhtml | 3 +++ app/views/account/_profile_details.rhtml | 21 +++++++++++++++++++++ app/views/account/_signup_form.rhtml | 48 +++++++++++++++++++++++++++++++++--------------- app/views/account/_wizard_steps.rhtml | 12 ++++++++++++ app/views/account/signup.rhtml | 4 ++++ app/views/account/wizard.rhtml | 5 +++++ app/views/blocks/my_network/community.rhtml | 4 ++-- app/views/blocks/my_network/person.rhtml | 4 ++-- app/views/friends/invite.rhtml | 26 ++++++++++++++++++++++---- app/views/home/index.rhtml | 4 ++++ app/views/layouts/wizard.rhtml | 34 ++++++++++++++++++++++++++++++++++ app/views/memberships/new_community.rhtml | 23 +++++++++++++++++++++-- app/views/search/_display_results.rhtml | 7 +++++++ app/views/search/_profile.rhtml | 8 +++++++- app/views/search/_search_form.rhtml | 8 +++++++- app/views/search/communities.rhtml | 12 ++++++++++-- public/stylesheets/common.css | 14 ++++++++++++++ test/functional/account_controller_test.rb | 15 +++++++++++++++ test/functional/friends_controller_test.rb | 36 ++++++++++++++++++++++++++++++++++++ test/functional/memberships_controller_test.rb | 31 ++++++++++++++++++++++--------- test/functional/profile_controller_test.rb | 14 +++++++++++++- test/functional/search_controller_test.rb | 20 ++++++++++++++++++++ test/unit/profile_test.rb | 10 ++++++++-- test/unit/tags_block_test.rb | 2 +- 35 files changed, 511 insertions(+), 58 deletions(-) create mode 100644 app/helpers/friends_helper.rb create mode 100644 app/views/account/_identifier_status.rhtml create mode 100644 app/views/account/_profile_details.rhtml create mode 100644 app/views/account/_wizard_steps.rhtml create mode 100644 app/views/account/wizard.rhtml create mode 100644 app/views/layouts/wizard.rhtml 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
\n"+ - tag_cloud( owner.tags, :id, + tag_cloud( tags, :id, owner.generate_url(:controller => 'profile', :action => 'tag'), :max_size => 16, :min_size => 9 ) + "\n
\n"; diff --git a/app/views/account/_identifier_status.rhtml b/app/views/account/_identifier_status.rhtml new file mode 100644 index 0000000..26ebf5f --- /dev/null +++ b/app/views/account/_identifier_status.rhtml @@ -0,0 +1,3 @@ +
+

<%= @url %> <%= @status %>

+
diff --git a/app/views/account/_profile_details.rhtml b/app/views/account/_profile_details.rhtml new file mode 100644 index 0000000..95a0a0d --- /dev/null +++ b/app/views/account/_profile_details.rhtml @@ -0,0 +1,21 @@ +
+ <%= image_tag(profile_icon(@profile, :portrait)) %> + + <%= @profile.short_name %>
+ <%= _('Type: %s') % getterm(@profile.class.name) %>
+ <%= _('Description: %s') % @profile.description %>
+ <%= _('Members: %s') % @profile.members.size.to_s %>
+ <%= _('Created at: %s') % show_date(@profile.created_at) %>
+ +<% form_tag({ :profile => @profile.identifier, :controller => 'profile', :action => 'join'}) do %> + <%= hidden_field_tag(:confirmation, 1) %> + <%= hidden_field_tag(:wizard, true) %> + <% if @profile.members.include?(user) %> + <%= link_to( _('Leave'), { :profile => user.identifier, :controller => 'memberships', :action => 'leave', :id => @profile.id, :confirmation => 1, :wizard => true }, :method => 'post') %> + <% else %> + <%= submit_button(:ok, _("Join now")) %> + <% end %> + <%= button(:back, _('Back'), {:controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true}) %> +<% end %> + +
diff --git a/app/views/account/_signup_form.rhtml b/app/views/account/_signup_form.rhtml index 54eca21..e69ad06 100644 --- a/app/views/account/_signup_form.rhtml +++ b/app/views/account/_signup_form.rhtml @@ -1,13 +1,15 @@ <%= error_messages_for :user, :person %> -<% if ! defined? hidden_atention || ! hidden_atention %> -

-

-<%= _('Dear user, welcome to the %s network. To start your participation -in this space, fill in the fields below. After this operation, your login and -password will be registered, allowing you to create %s and %s -in this environment.') % [environment.name, __('communities'), __('enterprises')] %> -
+<% if !@wizard %> + <% if ! defined? hidden_atention || ! hidden_atention %> +

+

+ <%= _('Dear user, welcome to the %s network. To start your participation + in this space, fill in the fields below. After this operation, your login and + password will be registered, allowing you to create %s and %s + in this environment.') % [environment.name, __('communities'), __('enterprises')] %> +
+ <% end %> <% end %> <% labelled_form_for :user, @user, @@ -16,12 +18,19 @@ in this environment.') % [environment.name, __('communities'), __('enterprises') <%= hidden_field_tag :invitation_code, @invitation_code %> +<%= hidden_field_tag :wizard, @wizard %> + <%= required_fields_message %> <%= required f.text_field(:login, - :onchange => 'this.value = convToValidLogin( this.value )') %> + :onchange => 'this.value = convToValidLogin( this.value )') %> <%= help %> +<%= observe_field 'user_login', :url => {:action => 'check_url'}, :with => 'identifier', :update => 'url-check' %> + +
+
+ <%= required f.text_field(:email, :help => help=_('This e-mail address will be used to contact you.')) %> <%= help %> @@ -41,13 +50,18 @@ in this environment.') % [environment.name, __('communities'), __('enterprises') <%= icaptcha_field() %> <% if @terms_of_use %> -
+ <%= _("By clicking on 'I accept the terms of use' below you are agreeing to the %s") % + link_to_function(_('Terms of use'), nil) do |page| + page['terms-of-use'].show + end %> + + -

- <%= 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 @@ +
+ <% button_bar do %> + <%= button_to_previous_step(@step) if @step %> + <%= button_to_step(:step, 1, @step, :class => (logged_in? ? 'logged' : 'not-logged')) %> + <% if logged_in? %> + <%= button_to_step(:step, 2, @step) %> + <%= button_to_step(:step, 3, @step) %> + <%= button_to_next_step(@step) if @step %> + <% end %> + <%= button(:ok, _('Finish'), user.url, :target => '_top') if @step == 3 %> + <% end %> +
diff --git a/app/views/account/signup.rhtml b/app/views/account/signup.rhtml index 91dc999..ee20dbb 100644 --- a/app/views/account/signup.rhtml +++ b/app/views/account/signup.rhtml @@ -1,2 +1,6 @@

<%= _('Signup') %>

<%= render :partial => 'signup_form' %> + +<% if @wizard %> + <%= render :partial => 'wizard_steps' %> +<% end %> diff --git a/app/views/account/wizard.rhtml b/app/views/account/wizard.rhtml new file mode 100644 index 0000000..063fe89 --- /dev/null +++ b/app/views/account/wizard.rhtml @@ -0,0 +1,5 @@ +<%= lightbox_close_button _('Close') %> + + diff --git a/app/views/blocks/my_network/community.rhtml b/app/views/blocks/my_network/community.rhtml index 7426817..15cc306 100644 --- a/app/views/blocks/my_network/community.rhtml +++ b/app/views/blocks/my_network/community.rhtml @@ -4,6 +4,6 @@ <% members = owner.members.size %>
  • <%= link_to(n_( 'One member', '%s members', members) % content_tag('b', members), owner.public_profile_url.merge(:action => 'members') ) %>
  • -
  • <%= link_to(n_('One tag', '%s tags', owner.tags.size) % - content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')) %>
  • +
  • <%= link_to(n_('One tag', '%s tags', owner.article_tags.size) % + content_tag('b', owner.article_tags.size), owner.public_profile_url.merge(:action => 'tags')) %>
  • diff --git a/app/views/blocks/my_network/person.rhtml b/app/views/blocks/my_network/person.rhtml index 8a79188..a0ded90 100644 --- a/app/views/blocks/my_network/person.rhtml +++ b/app/views/blocks/my_network/person.rhtml @@ -5,6 +5,6 @@ content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends')) %>
  • <%= link_to(n__('One community', '%s communities', owner.communities.size) % content_tag('b', owner.communities.size), owner.public_profile_url.merge(:action => 'communities')) %>
  • -
  • <%= link_to(n_('One tag', '%s tags', owner.tags.size) % - content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')) %>
  • +
  • <%= link_to(n_('One tag', '%s tags', owner.article_tags.size) % + content_tag('b', owner.article_tags.size), owner.public_profile_url.merge(:action => 'tags')) %>
  • diff --git a/app/views/friends/invite.rhtml b/app/views/friends/invite.rhtml index 197265f..d37c166 100644 --- a/app/views/friends/invite.rhtml +++ b/app/views/friends/invite.rhtml @@ -1,13 +1,16 @@

    <%= __('Invite your friends') %>

    - <% unless @friends %> -

    <%= __('Step 1 of 1: Select address book') %>

    + <% if !@wizard %> +

    <%= __('Step 1 of 1: Select address book') %>

    + <% end %> <% form_tag do %> <%= hidden_field_tag(:import, 1) %> + <%= hidden_field_tag(:wizard, @wizard) %> + <%= [ radio_button_tag(:import_from, "manual", @import_from == "manual", :onclick => 'hide_invite_friend_login_password()') + content_tag('label', __('Manually (empty field)'), :for => "import_from_manual"), radio_button_tag(:import_from, "gmail", @import_from == "gmail", :onclick => 'show_invite_friend_login_password()') + content_tag('label', 'Gmail', :for => 'import_from_gmail'), @@ -38,7 +41,9 @@ <% else %> -

    <%= __('Step 2 of 2: Selecting Friends') %>

    + <% if !@wizard %> +

    <%= __('Step 2 of 2: Selecting Friends') %>

    + <% end %>

    <%= __('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) %>
    <%= labelled_form_field(__('Enter one e-mail address per line:'), text_area_tag(:manual_import_addresses, (@manual_import_addresses || ''), :cols => 72, :rows => 5)) %> @@ -66,7 +72,12 @@ <% end -%>
    -
    + + <%= link_to_function(_('Personalize invitation message'), nil) do |page| + page['invitation-message'].show + end %> + + @@ -76,4 +87,11 @@ <% end %> <% end %> + <% if @wizard && @import_from == 'manual' %> + <%= __('Import now your contacts from %s, %s or %s') % [link_to_import('GMail', :import_from => 'gmail'), link_to_import('Yahoo', :import_from => 'yahoo'), link_to_import('Hotmail', :import_from => 'hotmail')] %> + <% end %> +<% end %> + +<% if @wizard %> + <%= render :partial => 'account/wizard_steps'%> <% end %> diff --git a/app/views/home/index.rhtml b/app/views/home/index.rhtml index a4d59c9..7ad5476 100644 --- a/app/views/home/index.rhtml +++ b/app/views/home/index.rhtml @@ -1,3 +1,7 @@ +<% if environment.enabled?('display_wizard_signup') && !logged_in? %> + <%= lightbox_button(:new, _('Signup'), { :controller => 'account', :action => 'wizard' }, :class => 'wizard') %> +<% end %> + <%= environment.description %> <% if environment.enabled?('enterprise_activation') %> diff --git a/app/views/layouts/wizard.rhtml b/app/views/layouts/wizard.rhtml new file mode 100644 index 0000000..0d278d1 --- /dev/null +++ b/app/views/layouts/wizard.rhtml @@ -0,0 +1,34 @@ + + + + + <%= javascript_include_tag :defaults %> + <%= stylesheet_link_tag '/designs/icons/default/style.css' %> + <%= javascript_include_tag 'jquery-latest.js' %> + + + <%= + # Load the principal css files: + stylesheet_import( %w( common button search forms) + ) + "\n" + + stylesheet_import( %w( common button search forms), + :themed_source => true ) + "\n" + + # Load the boxes's css file if each exists: + import_blocks_stylesheets + + stylesheet_import( "controller_"+ @controller.controller_name() ) + "\n" + + stylesheet_import( "controller_"+ @controller.controller_name(), :themed_source => true ) + %> + + + +
    +
    +
    + <%= yield %> +
    +
    +
    + + diff --git a/app/views/memberships/new_community.rhtml b/app/views/memberships/new_community.rhtml index 08ea548..4ae4893 100644 --- a/app/views/memberships/new_community.rhtml +++ b/app/views/memberships/new_community.rhtml @@ -4,7 +4,7 @@
    -<% labelled_form_for :community, @community do |f| %> +<% labelled_form_for :community, @community, :html => { :multipart => true } do |f| %> <%= required_fields_message %> @@ -12,6 +12,17 @@ <%= f.text_area :description, :style => 'width: 100%; height: 150px;' %> + <%= hidden_field_tag :wizard, params[:wizard] %> + + <%= f.text_field('tag_list', :size => 64) %> + <%= content_tag( 'small', _('Separate tags with commas') ) %> + +
    + <% f.fields_for :image_builder, @community.image do |i| %> + <%= file_field_or_thumbnail(_('Image:'), @community.image, i) %> + <% end %> +
    +
    <%= _('New members must be approved:')%>
    @@ -30,9 +41,17 @@ <% button_bar do %> <%= submit_button(:save, _('Create')) %> - <%= button(:cancel, _('Cancel'), :action => 'index') %> + <% if @wizard %> + <%= button(:back, _('Back'), {:controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true}) %> + <% else %> + <%= button(:cancel, _('Cancel'), :action => 'index') %> + <% end %> <% end %> <% end %>
    + +<% if @wizard %> + <%= render :partial => 'account/wizard_steps' %> +<% end %> diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index d6dc105..da6c868 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -1,5 +1,12 @@
    +<% if @wizard %> +
    + <%= button_without_text('product', '', params.merge(:visualization_mode => 'icons'), :title => _('View as icons')) %> + <%= button_without_text('todo', '', params.merge(:visualization_mode => 'list'), :title => _('View as list')) %> +
    +<% end %> + <% pos2 = :odd # allow to format in a two columns layout pos3 = 3 # allow to format in a thre columns layout diff --git a/app/views/search/_profile.rhtml b/app/views/search/_profile.rhtml index 928677b..13e264b 100644 --- a/app/views/search/_profile.rhtml +++ b/app/views/search/_profile.rhtml @@ -1,2 +1,8 @@ <%# FIXME add more information %> -
  • <%= profile_image_link profile, :portrait %>
  • +<% if (params[:visualization_mode] == 'list') && params[:wizard] %> + <%= profile_add_link profile %> +<% elsif params[:wizard] %> + <%= profile_add_link profile, true, :portrait %> +<% else %> + <%= profile_image_link profile, :portrait %> +<% end %> diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml index b66f815..81d299d 100644 --- a/app/views/search/_search_form.rhtml +++ b/app/views/search/_search_form.rhtml @@ -1,12 +1,16 @@
    <% simple_search = false unless defined? simple_search %> -<% form_tag( { :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, +<% form_tag( { :controller => 'search', :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, :method => 'get', :class => 'search_form' ) do %> <%= '

    %s

    ' % form_title if defined? form_title %> <%= hidden_field_tag :display, params[:display] %> + <%= hidden_field_tag :wizard, @wizard %> + + <%= hidden_field_tag :asset, params[:asset] %> +
    <%= text_field_tag 'query', @query, :id => ( lightbox? ? 'popup-search-input' : '' ), :size => 50 %> @@ -18,6 +22,7 @@ <% end %>
    + <% if !@wizard %>

    <%= _('Search within:') %>

    @@ -52,6 +57,7 @@ page['advanced-search-options'].toggle end %> <% end %> + <% end %> <% if lightbox?; button_bar do %> <%= lightbox_close_button _('Close') %> diff --git a/app/views/search/communities.rhtml b/app/views/search/communities.rhtml index ead5352..2cc053b 100644 --- a/app/views/search/communities.rhtml +++ b/app/views/search/communities.rhtml @@ -6,9 +6,12 @@ <%= search_page_link_to_all( { :asset => params[:asset], :category => @category }) %> - <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> +<% if @wizard %> +
    <%= __('Choose the communities you want to join and/or create your own.') %>
    +<% end %> + <%# FIXME ARMENGUE %> <%= display_results(false) %> @@ -18,8 +21,13 @@ <% if logged_in? %> <% button_bar do %> <%# FIXME shouldn't the user create the community in the current environment instead of going to its home environment? %> - <%= button(:add, _('New community'), user.url.merge(:controller => 'memberships', :action => 'new_community')) %> + <%= button(:add, _('New community'), user.url.merge(:controller => 'memberships', :action => 'new_community', :wizard => @wizard)) %> <% end %> <% end %>
    + +<% if @wizard %> + <%= render :partial => 'account/wizard_steps' %> +<% end %> + diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index 38e3754..064352a 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -468,3 +468,17 @@ div.pending-tasks { #content #access-denied p { text-align: justify; } + +/**** Signup wizard ****/ + +#wizard-iframe { + border: none; +} + +#wizard-content { + font-size: 13px; +} + +#wizard-content h1 { + font-size: 22px; +} diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index c4feb9c..a96773c 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -311,6 +311,21 @@ class AccountControllerTest < Test::Unit::TestCase assert_not_equal 'unknow', Person['save_lang'].last_lang end + should 'signup from wizard' do + assert_difference User, :count do + post :signup, :user => { :login => 'mylogin', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' }, :wizard => true + end + assert_redirected_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + end + + should 'not have layout when fail signup from wizard' do + user = create_user('mylogin').person + post :signup, :user => { :login => 'mylogin', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' }, :wizard => true + assert_response :success + assert_template 'signup' + assert_equal 'layouts/wizard', @response.layout + end + ################################ # # # Enterprise activation tests # diff --git a/test/functional/friends_controller_test.rb b/test/functional/friends_controller_test.rb index 8c91193..251bf3f 100644 --- a/test/functional/friends_controller_test.rb +++ b/test/functional/friends_controller_test.rb @@ -87,6 +87,13 @@ class FriendsControllerTest < Test::Unit::TestCase end end + should 'actualy invite manually added addresses with name and e-mail on wizard' do + assert_difference InviteFriend, :count, 1 do + post :invite, :manual_import_addresses => "Test Name ", :import_from => "manual", :message => "click: ", :confirmation => 1, :wizard => true + assert_redirected_to :action => 'invite', :wizard => true + end + end + should 'actually invite manually added address with only e-mail' do assert_difference InviteFriend, :count, 1 do post :invite, :manual_import_addresses => "test@test.com", :import_from => "manual", :message => "click: ", :confirmation => 1 @@ -94,6 +101,13 @@ class FriendsControllerTest < Test::Unit::TestCase end end + should 'actually invite manually added address with only e-mail on wizard' do + assert_difference InviteFriend, :count, 1 do + post :invite, :manual_import_addresses => "test@test.com", :import_from => "manual", :message => "click: ", :confirmation => 1, :wizard => true + assert_redirected_to :action => 'invite', :wizard => true + end + end + should 'actually invite manually added addresses with e-mail and other format' do assert_difference InviteFriend, :count, 1 do post :invite, :manual_import_addresses => "test@test.cz.com", :import_from => "manual", :message => "click: ", :confirmation => 1 @@ -101,6 +115,13 @@ class FriendsControllerTest < Test::Unit::TestCase end end + should 'actually invite manually added addresses with e-mail and other format on wizard' do + assert_difference InviteFriend, :count, 1 do + post :invite, :manual_import_addresses => "test@test.cz.com", :import_from => "manual", :message => "click: ", :confirmation => 1, :wizard => true + assert_redirected_to :action => 'invite', :wizard => true + end + end + should 'actually invite manually added address with friend object' do assert_difference InviteFriend, :count, 1 do post :invite, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :message => "click: ", :confirmation => 1 @@ -108,10 +129,25 @@ class FriendsControllerTest < Test::Unit::TestCase end end + should 'actually invite manually added address with friend object on wizard' do + assert_difference InviteFriend, :count, 1 do + post :invite, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :message => "click: ", :confirmation => 1, :wizard => true + assert_redirected_to :action => 'invite', :wizard => true + end + end + should 'actually invite more than one manually added addres' do assert_difference InviteFriend, :count, 2 do post :invite, :manual_import_addresses => "Some Friend \r\notherperson@bleble.net\r\n", :import_from => "manual", :message => "click: ", :confirmation => 1 assert_redirected_to :action => 'index' end end + + should 'actually invite more than one manually added addres on wizard' do + assert_difference InviteFriend, :count, 2 do + post :invite, :manual_import_addresses => "Some Friend \r\notherperson@bleble.net\r\n", :import_from => "manual", :message => "click: ", :confirmation => 1, :wizard => true + assert_redirected_to :action => 'invite', :wizard => true + end + end + end diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb index 67f1bf0..ce631c0 100644 --- a/test/functional/memberships_controller_test.rb +++ b/test/functional/memberships_controller_test.rb @@ -50,6 +50,16 @@ class MembershipsControllerTest < Test::Unit::TestCase end end + should 'be able to create a new community on wizard' do + assert_difference Community, :count do + post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '}, :wizard => true + assert_response :redirect + assert_redirected_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + + assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" + end + end + should 'link to new community creation in index' do get :index, :profile => profile.identifier assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/memberships/new_community" } @@ -124,6 +134,18 @@ class MembershipsControllerTest < Test::Unit::TestCase assert_not_includes profile.memberships, community end + should 'leave profile when on wizard' do + community = Community.create!(:name => 'my test community') + community.add_member(profile) + post :leave, :profile => profile.identifier, :id => community.id, :confirmation => '1', :wizard => true + + assert_response :redirect + assert_redirected_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + + profile = Profile.find(@profile.id) + assert_not_includes profile.memberships, community + end + should 'current user is added as admin after create new community' do post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '} assert_equal Profile::Roles.admin, profile.find_roles(Community.find_by_identifier('my-shiny-new-community')).first.role @@ -199,13 +221,4 @@ class MembershipsControllerTest < Test::Unit::TestCase assert_equal 1, assigns(:community).boxes[0].blocks.size end - should 'leave community' do - community = Community.create!(:name =>'Boca do Siri', :identifier => 'boca_do_siri') - community.affiliate(profile, Profile::Roles.all_roles) - post :leave, :profile => profile.identifier, :id => community.id, :confirmation => true - - profile = Profile.find(@profile.id) - assert_not_includes profile.memberships, community - end - end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index d41d1d4..ef22be7 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -324,7 +324,7 @@ class ProfileControllerTest < Test::Unit::TestCase end should 'list tags' do - Person.any_instance.stubs(:tags).returns({ 'one' => 1, 'two' => 2}) + Person.any_instance.stubs(:article_tags).returns({ 'one' => 1, 'two' => 2}) get :tags, :profile => 'testuser' assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/one'} } @@ -451,6 +451,18 @@ class ProfileControllerTest < Test::Unit::TestCase assert profile.memberships.include?(community), 'profile should be actually added to the community' end + should 'join profile from wizard' do + community = Community.create!(:name => 'my test community') + login_as @profile.identifier + post :join, :profile => community.identifier, :confirmation => '1', :wizard => true + + assert_response :redirect + assert_redirected_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + + profile = Profile.find(@profile.id) + assert profile.memberships.include?(community), 'profile should be actually added to the community' + end + should 'create task when join to closed organization' do community = Community.create!(:name => 'my test community', :closed => true) login_as @profile.identifier diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 4baf41b..439fe92 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -238,6 +238,13 @@ class SearchControllerTest < Test::Unit::TestCase assert_equivalent [c3, c1], assigns(:results)[:communities] end + should 'find communities in signup wizard' do + c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) + get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true + assert_includes assigns(:results)[:communities], c1 + assert_equal 'layouts/wizard', @response.layout + end + should 'find products' do ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') prod = ent.products.create!(:name => 'a beautiful product') @@ -971,6 +978,19 @@ class SearchControllerTest < Test::Unit::TestCase end end + should 'display steps when searching on wizard' do + c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) + get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true + assert_equal 'layouts/wizard', @response.layout + assert_tag :tag => 'div', :attributes => {:id => 'wizard-steps'} + end + + should 'not display steps when searching not on wizard' do + c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) + get :index, :query => 'beautiful', :find_in => [ 'communities' ] + assert_equal 'layouts/application', @response.layout + assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'} + end ################################################################## ################################################################## diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index a6d94b8..2d6c4a1 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -304,14 +304,20 @@ class ProfileTest < Test::Unit::TestCase ok('Profile#url must include port options when running in developers mode') { profile.url[:port] == 9999 } end - should 'list tags for profile' do + should 'list article tags for profile' do profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') profile.articles.build(:name => 'first', :tag_list => 'first-tag').save! profile.articles.build(:name => 'second', :tag_list => 'first-tag, second-tag').save! profile.articles.build(:name => 'third', :tag_list => 'first-tag, second-tag, third-tag').save! - assert_equal({ 'first-tag' => 3, 'second-tag' => 2, 'third-tag' => 1 }, profile.tags) + assert_equal({ 'first-tag' => 3, 'second-tag' => 2, 'third-tag' => 1 }, profile.article_tags) + + end + + should 'list tags for profile' do + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :tag_list => 'first-tag, second-tag') + assert_equal(['first-tag', 'second-tag'], profile.tags.map(&:name)) end should 'find content tagged with given tag' do diff --git a/test/unit/tags_block_test.rb b/test/unit/tags_block_test.rb index 075df8e..49b7a82 100644 --- a/test/unit/tags_block_test.rb +++ b/test/unit/tags_block_test.rb @@ -28,7 +28,7 @@ class TagsBlockTest < Test::Unit::TestCase end should 'return (none) when no tags to display' do - block.owner.expects(:tags).returns([]) + block.owner.expects(:article_tags).returns([]) assert_equal '', block.content end -- libgit2 0.21.2