diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c622771..e86ecfb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -11,7 +11,7 @@ module ApplicationHelper include BoxesHelper include FormsHelper - + include AssetsHelper include BlockHelper @@ -94,7 +94,7 @@ module ApplicationHelper if options[:type] == :textile content = RedCloth.new(content).to_html end - + options[:class] = '' if ! options[:class] options[:class] += ' button icon-help' # with-text @@ -269,7 +269,7 @@ module ApplicationHelper if klass.nil? raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' end - + name = klass.name.underscore if File.exists?(File.join(RAILS_ROOT, 'app', 'views', params[:controller], "_#{name}.rhtml")) name @@ -285,7 +285,7 @@ module ApplicationHelper # DEPRECATED. Do not use this. def stylesheet_import(*sources) options = sources.last.is_a?(Hash) ? sources.pop : { } - themed_source = options.delete(:themed_source) + themed_source = options.delete(:themed_source) content_tag( 'style', "\n" + @@ -299,7 +299,7 @@ module ApplicationHelper end.join(), { "type" => "text/css" }.merge(options) ) - end + end # DEPRECATED. Do not use this. def filename_for_stylesheet(name, in_theme) @@ -391,7 +391,7 @@ module ApplicationHelper Theme.find(current_theme).owner.identifier end - # generates a image tag for the profile. + # generates a image tag for the profile. # # If the profile has no image set yet, then a default image is used. def profile_image(profile, size=:portrait, opt={}) @@ -787,8 +787,9 @@ module ApplicationHelper field_html ||= '' field_html += capture(&block) end - if (controller.action_name == 'signup') - if profile.signup_fields.include?(name) || profile.required_fields.include?(name) + + if controller.action_name == 'signup' || controller.action_name == 'new_community' || (controller.controller_name == "enterprise_registration" && controller.action_name == 'index') + if profile.signup_fields.include?(name) result = field_html end else @@ -796,6 +797,7 @@ module ApplicationHelper result = field_html end end + if is_required result = required(result) end diff --git a/app/models/community.rb b/app/models/community.rb index 9a1e98b..4285efb 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -23,10 +23,6 @@ class Community < Organization xss_terminate :only => [ :name, :address, :contact_phone, :description ], :on => 'validation' FIELDS = %w[ - city - state - country - zip_code language ] @@ -38,7 +34,7 @@ class Community < Organization super self.required_fields.each do |field| if self.send(field).blank? - self.errors.add(field, _('%{fn} is mandatory')) + self.errors.add(field, _('%{fn} can\'t be blank')) end end end @@ -51,6 +47,10 @@ class Community < Organization environment ? environment.required_community_fields : [] end + def signup_fields + environment ? environment.signup_community_fields : [] + end + def name=(value) super(value) self.identifier = value.to_slug diff --git a/app/models/create_community.rb b/app/models/create_community.rb index b4157df..69eee37 100644 --- a/app/models/create_community.rb +++ b/app/models/create_community.rb @@ -14,7 +14,7 @@ class CreateCommunity < Task acts_as_having_image - DATA_FIELDS = Community.fields + ['name', 'closed', 'tag_list'] + DATA_FIELDS = Community.fields + ['name', 'closed'] DATA_FIELDS.each do |field| # getter @@ -30,7 +30,7 @@ class CreateCommunity < Task def validate self.environment.required_community_fields.each do |field| if self.send(field).blank? - self.errors.add(field, _('%{fn} is mandatory')) + self.errors.add(field, _('%{fn} can\'t be blank')) end end end diff --git a/app/models/create_enterprise.rb b/app/models/create_enterprise.rb index e5adca8..36d7c86 100644 --- a/app/models/create_enterprise.rb +++ b/app/models/create_enterprise.rb @@ -106,6 +106,10 @@ class CreateEnterprise < Task environment ? environment.required_enterprise_fields : [] end + def signup_fields + environment ? environment.signup_enterprise_fields : [] + end + def community? false end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 6e20217..2383e61 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -27,10 +27,6 @@ class Enterprise < Organization FIELDS = %w[ business_name - zip_code - city - state - country organization_website historic_and_current_context activities_short_description @@ -59,6 +55,10 @@ class Enterprise < Organization environment ? environment.required_enterprise_fields : [] end + def signup_fields + environment ? environment.signup_enterprise_fields : [] + end + def product_categories products.map{|p| p.category_full_name}.compact end diff --git a/app/models/environment.rb b/app/models/environment.rb index af3280b..9de3ddb 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -238,7 +238,7 @@ class Environment < ActiveRecord::Base def activation_blocked_text self.settings['activation_blocked_text'] end - + def activation_blocked_text= value self.settings['activation_blocked_text'] = value end @@ -327,14 +327,25 @@ class Environment < ActiveRecord::Base if values['schooling'] && values['schooling']['active'] == 'true' schooling_status = values['schooling'] end + self.settings[:custom_person_fields] = values.delete_if { |key, value| ! Person.fields.include?(key)} + self.settings[:custom_person_fields].each_pair do |key, value| + if value['required'] == 'true' + self.settings[:custom_person_fields][key]['active'] = 'true' + self.settings[:custom_person_fields][key]['signup'] = 'true' + end + if value['signup'] == 'true' + self.settings[:custom_person_fields][key]['active'] = 'true' + end + end + if schooling_status self.settings[:custom_person_fields]['schooling_status'] = schooling_status end end def custom_person_field(field, status) - if (custom_person_fields[field] && custom_person_fields[field][status] == 'true') + if (custom_person_fields[field] && custom_person_fields[field][status] == 'true') return true end false @@ -390,10 +401,19 @@ class Environment < ActiveRecord::Base def custom_enterprise_fields=(values) self.settings[:custom_enterprise_fields] = values.delete_if { |key, value| ! Enterprise.fields.include?(key)} + self.settings[:custom_enterprise_fields].each_pair do |key, value| + if value['required'] == 'true' + self.settings[:custom_enterprise_fields][key]['active'] = 'true' + self.settings[:custom_enterprise_fields][key]['signup'] = 'true' + end + if value['signup'] == 'true' + self.settings[:custom_enterprise_fields][key]['active'] = 'true' + end + end end def custom_enterprise_field(field, status) - if (custom_enterprise_fields[field] && custom_enterprise_fields[field][status] == 'true') + if (custom_enterprise_fields[field] && custom_enterprise_fields[field][status] == 'true') return true end false @@ -411,16 +431,32 @@ class Environment < ActiveRecord::Base required_fields end + def signup_enterprise_fields + signup_fields = [] + active_enterprise_fields.each do |field| + signup_fields << field if custom_enterprise_fields[field]['signup'] == 'true' + end + signup_fields + end + def custom_community_fields self.settings[:custom_community_fields].nil? ? {} : self.settings[:custom_community_fields] end - def custom_community_fields=(values) self.settings[:custom_community_fields] = values.delete_if { |key, value| ! Community.fields.include?(key) } + self.settings[:custom_community_fields].each_pair do |key, value| + if value['required'] == 'true' + self.settings[:custom_community_fields][key]['active'] = 'true' + self.settings[:custom_community_fields][key]['signup'] = 'true' + end + if value['signup'] == 'true' + self.settings[:custom_community_fields][key]['active'] = 'true' + end + end end def custom_community_field(field, status) - if (custom_community_fields[field] && custom_community_fields[field][status] == 'true') + if (custom_community_fields[field] && custom_community_fields[field][status] == 'true') return true end false @@ -438,6 +474,14 @@ class Environment < ActiveRecord::Base required_fields end + def signup_community_fields + signup_fields = [] + active_community_fields.each do |field| + signup_fields << field if custom_community_fields[field]['signup'] == 'true' + end + signup_fields + end + def category_types self.settings[:category_types].nil? ? ['Category'] : self.settings[:category_types] end @@ -483,7 +527,7 @@ class Environment < ActiveRecord::Base self.find(:first, :conditions => [ 'is_default = ?', true ] ) end - # returns an array with the top level categories for this environment. + # returns an array with the top level categories for this environment. def top_level_categories Category.top_level_for(self) end @@ -527,7 +571,7 @@ class Environment < ActiveRecord::Base self.articles.recent(limit) end - has_many :events, :through => :profiles, :source => :articles, :class_name => 'Event' + has_many :events, :through => :profiles, :source => :articles, :class_name => 'Event' has_many :tags, :through => :articles @@ -578,7 +622,7 @@ class Environment < ActiveRecord::Base def community_template=(value) settings[:community_template_id] = value.id end - + def person_template Person.find_by_id settings[:person_template_id] end diff --git a/app/models/organization.rb b/app/models/organization.rb index b3ab0cb..57d49b8 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -48,14 +48,20 @@ class Organization < Profile end FIELDS = %w[ + display_name + description contact_person - contact_phone contact_email - description + contact_phone legal_form economic_activity management_information address + zip_code + city + state + country + tag_list ] def self.fields @@ -70,8 +76,12 @@ class Organization < Profile [] end - N_('Contact person'); N_('Contact email'); N_('Acronym'); N_('Foundation year'); N_('Legal form'); N_('Economic activity'); N_('Management information'); N_('Validated') - settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated, :cnpj + def signup_fields + [] + end + + N_('Display name'); N_('Description'); N_('Contact person'); N_('Contact email'); N_('Acronym'); N_('Foundation year'); N_('Legal form'); N_('Economic activity'); N_('Management information'); N_('Validated'); N_('Tag list') + settings_items :display_name, :description, :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated, :cnpj validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml index aee8956..4fbceae 100644 --- a/app/views/cms/edit.rhtml +++ b/app/views/cms/edit.rhtml @@ -28,9 +28,6 @@ <%= select_categories(:article, _('Categorize your article')) %> - <%= f.text_field('tag_list', :size => 64) %> - <%= content_tag( 'small', _('Separate tags with commas') ) %> -
<%= options_for_article(@article) %>
diff --git a/app/views/enterprise_registration/basic_information.rhtml b/app/views/enterprise_registration/basic_information.rhtml index c56d28f..838a3cc 100644 --- a/app/views/enterprise_registration/basic_information.rhtml +++ b/app/views/enterprise_registration/basic_information.rhtml @@ -20,8 +20,8 @@ <% labelled_form_for(:create_enterprise, @create_enterprise) do |f| %> <%= required f.text_field 'name', :onchange => "updateUrlField(this, 'create_enterprise_identifier')", :size => 40 %> - <%= required labelled_form_field(_('Address'), content_tag('code', environment.top_url + "/" + text_field(:create_enterprise, 'identifier', :size => 25))) %> - <%= render :partial => 'shared/custom_fields', :locals => { :f => f, :object_name => :create_enterprise, :profile => @create_enterprise, :only_required => false } %> + <%= required labelled_form_field(_('Address'), content_tag('code', environment.top_url + "/" + text_field(:create_enterprise, 'identifier', :size => 26))) %> + <%= render :partial => 'shared/organization_custom_fields', :locals => { :f => f, :object_name => :create_enterprise, :profile => @create_enterprise } %> <%= required labelled_form_field(_('Region'), f.select('region_id', @regions)) if @validation == :region %> <% if @validation == :admin %> diff --git a/app/views/features/_manage_community_fields.rhtml b/app/views/features/_manage_community_fields.rhtml index 6eac4d7..f15dc53 100644 --- a/app/views/features/_manage_community_fields.rhtml +++ b/app/views/features/_manage_community_fields.rhtml @@ -7,18 +7,25 @@ <%= _('Field') %> <%= _('Active') %> <%= _('Required') %> + <%= _('Display on creation?') %> <% @community_fields.each do |field| %> + - <%= check_box_tag "community_fields[#{field}][active]", true, environment.custom_community_field(field, 'active'), :onclick => "$('community_fields[#{field}][required]').disabled=!this.checked" %> + <%= check_box_tag "community_fields[#{field}][active]", true, environment.custom_community_field(field, 'active'), :onclick => "$('community_fields[#{field}][required]').disabled=$('community_fields[#{field}][signup]').disabled=!this.checked;" %> <%= hidden_field_tag "community_fields[#{field}][active]", false %> - <%= check_box_tag "community_fields[#{field}][required]", true, environment.custom_community_field(field, 'required') %> + <%= check_box_tag "community_fields[#{field}][required]", true, environment.custom_community_field(field, 'required'), :onclick => "if(this.checked) $('community_fields[#{field}][signup]').checked = true;" %> <%= hidden_field_tag "community_fields[#{field}][required]", false %> + + <%= check_box_tag "community_fields[#{field}][signup]", true, environment.custom_community_field(field, 'signup'), :onclick => "if(!this.checked) $('community_fields[#{field}][required]').checked = false;" %> + <%= hidden_field_tag "community_fields[#{field}][signup]", false %> + + <% end %> diff --git a/app/views/features/_manage_enterprise_fields.rhtml b/app/views/features/_manage_enterprise_fields.rhtml index ea4435a..4e374b0 100644 --- a/app/views/features/_manage_enterprise_fields.rhtml +++ b/app/views/features/_manage_enterprise_fields.rhtml @@ -7,18 +7,25 @@ <%= _('Field') %> <%= _('Active') %> <%= _('Required') %> + <%= _('Display on registration?') %> <% @enterprise_fields.each do |field| %> + - <%= check_box_tag "enterprise_fields[#{field}][active]", true, environment.custom_enterprise_field(field, 'active'), :onclick => "$('enterprise_fields[#{field}][required]').disabled=!this.checked" %> + <%= check_box_tag "enterprise_fields[#{field}][active]", true, environment.custom_enterprise_field(field, 'active'), :onclick => "$('enterprise_fields[#{field}][required]').disabled=$('enterprise_fields[#{field}][signup]').disabled=!this.checked;" %> <%= hidden_field_tag "enterprise_fields[#{field}][active]", false %> - <%= check_box_tag "enterprise_fields[#{field}][required]", true, environment.custom_enterprise_field(field, 'required') %> + <%= check_box_tag "enterprise_fields[#{field}][required]", true, environment.custom_enterprise_field(field, 'required'), :onclick => "if(this.checked) $('enterprise_fields[#{field}][signup]').checked = true;" %> <%= hidden_field_tag "enterprise_fields[#{field}][required]", false %> + + <%= check_box_tag "enterprise_fields[#{field}][signup]", true, environment.custom_enterprise_field(field, 'signup'), :onclick => "if(!this.checked) $('enterprise_fields[#{field}][required]').checked = false;" %> + <%= hidden_field_tag "enterprise_fields[#{field}][signup]", false %> + + <% end %> diff --git a/app/views/features/_manage_person_fields.rhtml b/app/views/features/_manage_person_fields.rhtml index 272670d..06b9531 100644 --- a/app/views/features/_manage_person_fields.rhtml +++ b/app/views/features/_manage_person_fields.rhtml @@ -13,15 +13,15 @@ - <%= check_box_tag "person_fields[#{field}][active]", true, environment.custom_person_field(field, 'active'), :onclick => "$('person_fields[#{field}][required]').disabled=$('person_fields[#{field}][signup]').disabled=!this.checked" %> + <%= check_box_tag "person_fields[#{field}][active]", true, environment.custom_person_field(field, 'active'), :onclick => "$('person_fields[#{field}][required]').disabled=$('person_fields[#{field}][signup]').disabled=!this.checked;" %> <%= hidden_field_tag "person_fields[#{field}][active]", false %> - <%= check_box_tag "person_fields[#{field}][required]", true, environment.custom_person_field(field, 'required') %> + <%= check_box_tag "person_fields[#{field}][required]", true, environment.custom_person_field(field, 'required'), :onclick => "if(this.checked) $('person_fields[#{field}][signup]').checked = true;" %> <%= hidden_field_tag "person_fields[#{field}][required]", false %> - <%= check_box_tag "person_fields[#{field}][signup]", true, environment.custom_person_field(field, 'signup') %> + <%= check_box_tag "person_fields[#{field}][signup]", true, environment.custom_person_field(field, 'signup'), :onclick => "if(!this.checked) $('person_fields[#{field}][required]').checked = false;" %> <%= hidden_field_tag "person_fields[#{field}][signup]", false %> diff --git a/app/views/memberships/new_community.rhtml b/app/views/memberships/new_community.rhtml index 6aed0da..3492b79 100644 --- a/app/views/memberships/new_community.rhtml +++ b/app/views/memberships/new_community.rhtml @@ -22,10 +22,7 @@ <%= hidden_field_tag :wizard, params[:wizard] %> - <%= render :partial => 'shared/custom_fields', :locals => { :f => f, :object_name => 'community', :profile => @community, :only_required => true } %> - - <%= f.text_field('tag_list', :size => 64) %> - <%= content_tag( 'small', _('Separate tags with commas.') + '
' + __("Tags are important to new users, they'll be able to find your new community more easily.") ) %> + <%= render :partial => 'shared/organization_custom_fields', :locals => { :f => f, :object_name => 'community', :profile => @community } %> <% f.fields_for :image_builder, @community.image do |i| %> <%= file_field_or_thumbnail(_('Image:'), @community.image, i) %> diff --git a/app/views/profile_editor/_organization.rhtml b/app/views/profile_editor/_organization.rhtml index 371ac48..7e0a9a1 100644 --- a/app/views/profile_editor/_organization.rhtml +++ b/app/views/profile_editor/_organization.rhtml @@ -14,14 +14,6 @@ <% end %> -
- -
- <%= text_field_tag 'profile_data[nickname]', @profile_data.nickname, :id => 'profile_data_nickname', :size => 30, :maxlength => 16, :onchange => (@environment.enabled?('enable_organization_url_change') ? "updateUrlField(this, 'profile_data_identifier')" : "") %> - <%= _('A short name by which the organization is know.')%> -
-
- <% if @environment.enabled?('enable_organization_url_change') %>