diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index cce2b51..f31d673 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -4,6 +4,7 @@ class TasksController < MyProfileController protect [:perform_task, :view_tasks], :profile, :only => [:index] protect :perform_task, :profile, :except => [:index] + helper CustomFieldsHelper def index @filter_type = params[:filter_type].presence diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index fff9a2f..4972b3e 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -37,8 +37,15 @@ module CustomFieldsHelper end def display_custom_field_value(custom_field_value) - value = profile.custom_value(custom_field_value.custom_field.name) - case custom_field_value.custom_field.format + value_for_format custom_field_value.custom_field.format, custom_field_value.value + end + + def display_value_for_custom_field(custom_field, value) + value_for_format custom_field.format, value + end + + def value_for_format format, value + case format when 'text', 'list', 'numeric', 'date', 'string' value when 'checkbox' @@ -47,6 +54,7 @@ module CustomFieldsHelper url = value[/\Ahttps?:\/\//i] ? value : "http://#{value}" link_to(value, url, :target => '_blank') end + end private diff --git a/app/models/community.rb b/app/models/community.rb index e9a7191..aa45ea7 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -33,7 +33,7 @@ class Community < Organization community = Community.new(attributes) community.environment = environment if community.environment.enabled?('admin_must_approve_new_communities') - CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment).except(:custom_values)) + CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment)) else community.save! community.add_admin(requestor) diff --git a/app/models/create_community.rb b/app/models/create_community.rb index 21fc6f7..1720ddd 100644 --- a/app/models/create_community.rb +++ b/app/models/create_community.rb @@ -20,6 +20,9 @@ class CreateCommunity < Task attr_accessible field.to_sym end + settings_items :custom_values + attr_accessible :custom_values + def validate self.environment.required_community_fields.each do |field| if self.send(field).blank? @@ -36,6 +39,7 @@ class CreateCommunity < Task community.update(community_data) community.image = image if image + community.custom_values = custom_values community.environment = self.environment community.save! community.add_admin(self.requestor) @@ -67,6 +71,10 @@ class CreateCommunity < Task true end + def custom_fields_moderate + true + end + # tells if this request was rejected def rejected? self.status == Task::Status::CANCELLED diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 015d8d2..1e7635a 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -1,5 +1,5 @@ class CustomField < ActiveRecord::Base - attr_accessible :name, :default_value, :format, :extras, :customized_type, :active, :required, :signup, :environment + attr_accessible :name, :default_value, :format, :extras, :customized_type, :active, :required, :signup, :environment, :moderation_task serialize :customized_type serialize :extras has_many :custom_field_values, :dependent => :delete_all diff --git a/app/models/moderate_user_registration.rb b/app/models/moderate_user_registration.rb index a8a1bf9..99ea18b 100644 --- a/app/models/moderate_user_registration.rb +++ b/app/models/moderate_user_registration.rb @@ -22,6 +22,10 @@ class ModerateUserRegistration < Task "#{name} (#{email})" end + def custom_fields_moderate + true + end + def perform user=environment.users.find_by_id(user_id) user.activate @@ -58,4 +62,4 @@ class ModerateUserRegistration < Task _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name } end -end \ No newline at end of file +end diff --git a/app/models/task.rb b/app/models/task.rb index 6e1c2e4..49874f3 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -182,6 +182,10 @@ class Task < ActiveRecord::Base false end + def custom_fields_moderate + false + end + def icon {:type => :defined_image, :src => "/images/icons-app/user-minor.png", :name => requestor.name, :url => requestor.url} end diff --git a/app/views/features/custom_fields/_form.html.erb b/app/views/features/custom_fields/_form.html.erb index 56f0cba..cbadef7 100644 --- a/app/views/features/custom_fields/_form.html.erb +++ b/app/views/features/custom_fields/_form.html.erb @@ -16,6 +16,7 @@ <%= labelled_check_box _('Active'), "custom_fields[#{id}][active]", 1, field.active, :id => "active_checkbox", :onclick => "active_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> <%= labelled_check_box _('Required'), "custom_fields[#{id}][required]", 1, field.required, :id => "required_checkbox", :onclick => "required_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> <%= labelled_check_box _('Display on creation?'), "custom_fields[#{id}][signup]", 1, field.signup, :id => "signup_checkbox",:onclick => "signup_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> + <%= labelled_check_box _('Display on moderation?'), "custom_fields[#{id}][moderation_task]", 1, field.moderation_task %> <% if field.format == "list" %> diff --git a/app/views/tasks/_create_community_custom_fields.html.erb b/app/views/tasks/_create_community_custom_fields.html.erb new file mode 100644 index 0000000..73d0dfb --- /dev/null +++ b/app/views/tasks/_create_community_custom_fields.html.erb @@ -0,0 +1,10 @@ +<% if task.custom_values.present? %> + <% task.custom_values.each_pair do |name, value| %> + <% custom_field = CustomField.where(:name =>name, :environment => task.environment).first%> + <% if custom_field.moderation_task %> +
+ <%= name +": " + display_value_for_custom_field(custom_field, value['value']) %> +
+ <% end %> + <% end %> +<% end %> diff --git a/app/views/tasks/_moderate_user_registration_custom_fields.html.erb b/app/views/tasks/_moderate_user_registration_custom_fields.html.erb new file mode 100644 index 0000000..4015ce4 --- /dev/null +++ b/app/views/tasks/_moderate_user_registration_custom_fields.html.erb @@ -0,0 +1,7 @@ +<% task.requestor.custom_field_values.each do |custom_value| %> + <% if custom_value.custom_field.moderation_task %> +
+ <%= custom_value.custom_field.name + ": " + display_custom_field_value(custom_value) %> +
+ <% end %> +<% end %> diff --git a/app/views/tasks/_task.html.erb b/app/views/tasks/_task.html.erb index 6c3f1ed..cc7b7f2 100644 --- a/app/views/tasks/_task.html.erb +++ b/app/views/tasks/_task.html.erb @@ -51,6 +51,12 @@ <%= fields_for "tasks[#{task.id}][task]", task do |f| %> + <% if task.custom_fields_moderate %> + + <% end %> + <% if task.accept_details %>