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') ) %> -