diff --git a/app/controllers/admin/features_controller.rb b/app/controllers/admin/features_controller.rb
index a50537d..fc48752 100644
--- a/app/controllers/admin/features_controller.rb
+++ b/app/controllers/admin/features_controller.rb
@@ -17,17 +17,18 @@ class FeaturesController < AdminController
def manage_fields
@person_fields = Person.fields
- @custom_person_fields = []
- @environment.settings[:custom_person_fields].each{|k,v| @custom_person_fields << k if k =~ /^custom_field/ && ! @custom_person_fields.include?(k) }
+ @custom_person_fields = (@environment.settings[:custom_person_fields] || {}).keys.reject {|key| ! (key =~ /^custom_field/) }
+
@enterprise_fields = Enterprise.fields
+ @custom_enterprise_fields = (@environment.settings[:custom_enterprise_fields] || {}).keys.reject {|key| ! (key =~ /^custom_field/) }
+
@community_fields = Community.fields
+ @custom_community_fields = (@environment.settings[:custom_community_fields] || {}).keys.reject {|key| ! (key =~ /^custom_field/) }
end
def manage_person_fields
environment.custom_person_fields = params[:person_fields]
- #raise params[:person_fields].inspect
-
if environment.save!
session[:notice] = _('Person fields updated successfully.')
else
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 9e8984c..23642ce 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -497,7 +497,7 @@ class Environment < ActiveRecord::Base
end
def custom_enterprise_fields=(values)
- self.settings[:custom_enterprise_fields] = values.delete_if { |key, value| ! Enterprise.fields.include?(key)}
+ self.settings[:custom_enterprise_fields] = values.delete_if { |key, value| ! ( Enterprise.fields.include?(key) || key =~ /^custom_field/ ) }
self.settings[:custom_enterprise_fields].each_pair do |key, value|
if value['required'] == 'true'
self.settings[:custom_enterprise_fields][key]['active'] = 'true'
@@ -509,6 +509,16 @@ class Environment < ActiveRecord::Base
end
end
+ def custom_enterprise_fields_customs()
+ custom_fields = []
+ self.settings[:custom_enterprise_fields].each{ |k,v| custom_fields << k if k =~ /^custom_field/ }
+ custom_fields
+ end
+
+ def custom_enterprise_field_name(field)
+ self.settings[:custom_enterprise_fields][field]['name']
+ end
+
def custom_enterprise_field(field, status)
if (custom_enterprise_fields[field] && custom_enterprise_fields[field][status] == 'true')
return true
@@ -539,8 +549,13 @@ class Environment < ActiveRecord::Base
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] = values.delete_if { |key, value|
+ ! ( Community.fields.include?(key) || key =~ /^custom_field/ )
+ }
+
+
self.settings[:custom_community_fields].each_pair do |key, value|
if value['required'] == 'true'
self.settings[:custom_community_fields][key]['active'] = 'true'
@@ -552,6 +567,16 @@ class Environment < ActiveRecord::Base
end
end
+ def custom_community_fields_customs()
+ custom_fields = []
+ self.settings[:custom_community_fields].each{ |k,v| custom_fields << k if k =~ /^custom_field/ }
+ custom_fields
+ end
+
+ def custom_community_field_name(field)
+ self.settings[:custom_community_fields][field]['name']
+ end
+
def custom_community_field(field, status)
if (custom_community_fields[field] && custom_community_fields[field][status] == 'true')
return true
diff --git a/app/models/organization.rb b/app/models/organization.rb
index e0a3eb1..d1d6558 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -1,7 +1,7 @@
# Represents any organization of the system
class Organization < Profile
- attr_accessible :moderated_articles, :foundation_year, :contact_person, :acronym, :legal_form, :economic_activity, :management_information, :cnpj, :display_name, :enable_contact_us
+ attr_accessible :moderated_articles, :foundation_year, :contact_person, :acronym, :legal_form, :economic_activity, :management_information, :cnpj, :display_name, :enable_contact_us #, :custom_fields
SEARCH_FILTERS += %w[
more_popular
@@ -13,6 +13,12 @@ class Organization < Profile
closed
end
+ #settings_items :custom_fields
+
+ #def custom_field_value(field)
+ # self.custom_fields[field]
+ #end
+
before_save do |organization|
organization.closed = true if !organization.public_profile?
end
diff --git a/app/models/person.rb b/app/models/person.rb
index 6e534d0..5851379 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -1,7 +1,7 @@
# A person is the profile of an user holding all relationships with the rest of the system
class Person < Profile
- attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website
+ attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website #, :custom_fields
SEARCH_FILTERS += %w[
more_popular
@@ -205,6 +205,12 @@ class Person < Profile
N_('Contact information'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code'); N_('District'); N_('Address reference')
settings_items :photo, :contact_information, :sex, :city, :state, :country, :zip_code, :district, :address_reference
+ #settings_items :custom_fields
+
+ #def custom_field_value(field)
+ # self.custom_fields[field]
+ #end
+
extend SetProfileRegionFromCityState::ClassMethods
set_profile_region_from_city_state
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 3482a52..54c67d4 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -3,7 +3,7 @@
# which by default is the one returned by Environment:default.
class Profile < ActiveRecord::Base
- attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, :redirection_after_login
+ attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, :redirection_after_login, :custom_fields
# use for internationalizable human type names in search facets
# reimplement on subclasses
@@ -23,6 +23,12 @@ class Profile < ActiveRecord::Base
SEARCH_DISPLAYS = %w[compact]
+ settings_items :custom_fields, :default => {}
+
+ def custom_field_value(key)
+ self.custom_fields[key]
+ end
+
def self.default_search_display
'compact'
end
diff --git a/app/views/features/_manage_community_fields.html.erb b/app/views/features/_manage_community_fields.html.erb
index 9cb0ebe..5c5d24f 100644
--- a/app/views/features/_manage_community_fields.html.erb
+++ b/app/views/features/_manage_community_fields.html.erb
@@ -12,46 +12,73 @@
<%= _("Check/Uncheck All")%>
|
-
+ |
|
-
+ |
|
-
+ |
|
+ |
<% @community_fields.each do |field| %>
|
-
-
+ |
<%= hidden_field_tag "community_fields[#{field}][active]", false %>
<%= check_box_tag "community_fields[#{field}][active]", true, environment.custom_community_field(field, 'active'), :onclick => "active_action(this, 'community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %>
|
-
+ |
<%= hidden_field_tag "community_fields[#{field}][required]", false %>
<%= check_box_tag "community_fields[#{field}][required]", true, environment.custom_community_field(field, 'required'), :onclick => "required_action('community_fields[#{field}][active]','community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %>
|
-
+ |
<%= hidden_field_tag "community_fields[#{field}][signup]", false %>
<%= check_box_tag "community_fields[#{field}][signup]", true, environment.custom_community_field(field, 'signup'), :onclick => "signup_action('community_fields[#{field}][active]','community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %>
|
+
+ <% end %>
+ <% @custom_community_fields.each do |field| %>
+
+ |
+ <%= text_field_tag "community_fields[#{field}][name]", environment.custom_community_field_name(field) %>
+ |
+
+ <%= hidden_field_tag "community_fields[#{field}][active]", false %>
+ <%= check_box_tag "community_fields[#{field}][active]", true, environment.custom_community_field(field, 'active'), :onclick => "active_action(this, 'community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %>
+ |
+
+ <%= hidden_field_tag "community_fields[#{field}][required]", false %>
+ <%= check_box_tag "community_fields[#{field}][required]", true, environment.custom_community_field(field, 'required'), :onclick => "required_action('community_fields[#{field}][active]','community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %>
+ |
+
+ <%= hidden_field_tag "community_fields[#{field}][signup]", false %>
+ <%= check_box_tag "community_fields[#{field}][signup]", true, environment.custom_community_field(field, 'signup'), :onclick => "required_action('community_fields[#{field}][active]','community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %>
+ |
+
+ Delete
+ |
<% end %>
+
+
+
+<%= link_to_function(_('Add field'), "add_new_field('community');", :class => 'button icon-add with-text') %>
+
diff --git a/app/views/features/_manage_enterprise_fields.html.erb b/app/views/features/_manage_enterprise_fields.html.erb
index a8840bb..93b963a 100644
--- a/app/views/features/_manage_enterprise_fields.html.erb
+++ b/app/views/features/_manage_enterprise_fields.html.erb
@@ -12,13 +12,13 @@
<%= _("Check/Uncheck All")%>
|
-
+ |
|
-
+ |
|
-
+ |
|
@@ -27,31 +27,59 @@
|
-
+ |
<%= hidden_field_tag "enterprise_fields[#{field}][active]", false %>
<%= check_box_tag "enterprise_fields[#{field}][active]", true, environment.custom_enterprise_field(field, 'active'), :onclick => "active_action(this, 'enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %>
|
-
+ |
<%= hidden_field_tag "enterprise_fields[#{field}][required]", false %>
<%= check_box_tag "enterprise_fields[#{field}][required]", true, environment.custom_enterprise_field(field, 'required'), :onclick => "required_action('enterprise_fields[#{field}][active]','enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %>
|
-
+ |
<%= hidden_field_tag "enterprise_fields[#{field}][signup]", false %>
<%= check_box_tag "enterprise_fields[#{field}][signup]", true, environment.custom_enterprise_field(field, 'signup'), :onclick => "signup_action('enterprise_fields[#{field}][active]','enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %>
|
<% end %>
+
+ <% @custom_enterprise_fields.each do |field| %>
+
+ |
+ <%= text_field_tag "enterprise_fields[#{field}][name]", environment.custom_enterprise_field_name(field) %>
+ |
+
+ <%= hidden_field_tag "enterprise_fields[#{field}][active]", false %>
+ <%= check_box_tag "enterprise_fields[#{field}][active]", true, environment.custom_enterprise_field(field, 'active'), :onclick => "active_action(this, 'enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %>
+ |
+
+ <%= hidden_field_tag "enterprise_fields[#{field}][required]", false %>
+ <%= check_box_tag "enterprise_fields[#{field}][required]", true, environment.custom_enterprise_field(field, 'required'), :onclick => "required_action('enterprise_fields[#{field}][active]','enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %>
+ |
+
+ <%= hidden_field_tag "enterprise_fields[#{field}][signup]", false %>
+ <%= check_box_tag "enterprise_fields[#{field}][signup]", true, environment.custom_enterprise_field(field, 'signup'), :onclick => "required_action('enterprise_fields[#{field}][active]','enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %>
+ |
+
+ Delete
+ |
+
+ <% end %>
+
+
+
+<%= link_to_function(_('Add field'), "add_new_field('enterprise');", :class => 'button icon-add with-text') %>
+
diff --git a/app/views/features/_manage_person_fields.html.erb b/app/views/features/_manage_person_fields.html.erb
index c9b85c8..8c5b43d 100644
--- a/app/views/features/_manage_person_fields.html.erb
+++ b/app/views/features/_manage_person_fields.html.erb
@@ -71,19 +71,18 @@
-<%= link_to_function(_('Add field'), 'add_new_field();', :class => 'button icon-add with-text') %>
-
-<%= javascript_include_tag 'edit-profile-fields.js' %>
-
-
diff --git a/app/views/profile_editor/_organization.html.erb b/app/views/profile_editor/_organization.html.erb
index bd5162e..7b47b3a 100644
--- a/app/views/profile_editor/_organization.html.erb
+++ b/app/views/profile_editor/_organization.html.erb
@@ -60,8 +60,12 @@
<% end %>
+
+
<%= render :partial => 'shared/organization_custom_fields', :locals => { :f => f, :object_name => 'profile_data', :profile => @profile } %>
+
+
<%= labelled_check_box(_('Enable "contact us"'), 'profile_data[enable_contact_us]', "1", @profile.enable_contact_us) if @profile.enterprise? %>
<%= render :partial => 'moderation', :locals => { :profile => @profile } %>
diff --git a/app/views/profile_editor/_person_form.html.erb b/app/views/profile_editor/_person_form.html.erb
index a26a059..fe3cc6e 100644
--- a/app/views/profile_editor/_person_form.html.erb
+++ b/app/views/profile_editor/_person_form.html.erb
@@ -7,6 +7,17 @@
<% end %>
+<% @environment.custom_person_fields_customs.each { |k| %>
+ <% optional_field(@person, k) do %>
+
+ <% end %>
+<% } %>
+
<%= optional_field(@person, 'description', f.text_area(:description, :rows => 5, :rel => _('Description'))) %>
<%= optional_field(@person, 'preferred_domain', select_preferred_domain(:profile_data)) %>
<%= optional_field(@person, 'contact_information', f.text_field(:contact_information, :rel => _('Contact information'))) %>
@@ -65,13 +76,3 @@
<%= optional_field(@person, 'organization', f.text_field(:organization, :rel => _('Organization'))) %>
<%= optional_field(@person, 'organization_website', f.text_field(:organization_website, :rel => _('Organization website'))) %>
-
-
-<% @environment.custom_person_fields_customs.each { |k| %>
-
- <%= label_tag environment.custom_person_field_name(k) %>
- <%= optional_field(@person, k, text_field_tag("profile_data[#{k}]")) %>
-
-<% } %>
-
-
diff --git a/app/views/shared/_organization_custom_fields.html.erb b/app/views/shared/_organization_custom_fields.html.erb
index 5b19eb8..40ee8e1 100644
--- a/app/views/shared/_organization_custom_fields.html.erb
+++ b/app/views/shared/_organization_custom_fields.html.erb
@@ -30,3 +30,22 @@
<%= optional_field(profile, 'foundation_year', f.text_field(:foundation_year)) %>
<% end %>
<%= javascript_include_tag('city_state_validation') %>
+
+
+
+<% if profile.community? %>
+
+ <% @environment.custom_community_fields_customs.each { |key| %>
+ <% #raise @environment.custom_community_fields_customs.inspect %>
+ <% optional_field(profile, key) do %>
+
+ <% end %>
+ <% } %>
+<% end %>
+
+
diff --git a/public/javascripts/edit-profile-fields.js b/public/javascripts/edit-profile-fields.js
deleted file mode 100644
index dd4b6d1..0000000
--- a/public/javascripts/edit-profile-fields.js
+++ /dev/null
@@ -1,105 +0,0 @@
-function send_ajax(source_url) {
- jQuery(".link-address").autocomplete({
- source : function(request, response){
- jQuery.ajax({
- type: "GET",
- url: source_url,
- data: {query: request.term},
- success: function(result){
- response(result);
- },
- error: function(ajax, stat, errorThrown) {
- console.log('Link not found : ' + errorThrown);
- }
- });
- },
-
- minLength: 3
- });
-}
-
-function new_field_action(){
- send_ajax(jQuery("#page_url").val());
-
- jQuery(".delete-link-list-row").click(function(){
- jQuery(this).parent().parent().remove();
- return false;
- });
-
- jQuery(document).scrollTop(jQuery('#dropable-link-list').scrollTop());
-}
-
-function remove_custom_field(element) {
- jQuery(element).parent().parent().remove();
- return false;
-}
-
-function add_new_field() {
-
- last_row = jQuery('#person_fields_conf > tbody:last tr:last');
-
- if ( last_row.find('label').length == 1 ) {
-
- var row = '' +
- '| ' +
- '' +
- ' | ' +
- ' ' +
- ' ' +
- ' ' +
- ' | ' +
- ' ' +
- ' ' +
- ' ' +
- ' | ' +
- ' ' +
- ' ' +
- ' ' +
- ' | ' +
- ' ' +
- 'Delete ' +
- ' | ' +
- '
';
-
- jQuery('#person_fields_conf > tbody:last').append(row);
-
- }
- else {
-
- var new_field = jQuery('#person_fields_conf > tbody:last tr:last').clone();
-
- var field = new_field.find('input');
- //var chkboxes = field.filter(':checkbox');
-
- var re = new RegExp( '\\d', 'g' );
- var id = field.attr('id').match(re);
- var next_id = parseInt(id) + 1;
-
- jQuery.each( field, function( k, v ) {
- v.id = v.id.replace(id, next_id);
- v.name = v.name.replace(id, next_id);
- if (v.type == 'text') { v.value = '' }
- if (v.type == 'checkbox') { v.value = true; }
- if (v.type == 'hidden') { v.value = false; }
-
- });
-
- //field.val('');
-
- //chkboxes.attr('onclick', chkboxes.attr('onclick').replace(id, next_id));
- //console.log( chkboxes );
-
- jQuery('#person_fields_conf > tbody').append(new_field);
-
- }
-
-}
-
-jQuery(document).ready(function(){
- new_field_action();
-
- //jQuery("#dropable-link-list").sortable({
- // revert: true,
- // axis: "y"
- //});
-});
diff --git a/public/javascripts/manage-fields.js b/public/javascripts/manage-fields.js
index 95e254b..2cfafe0 100644
--- a/public/javascripts/manage-fields.js
+++ b/public/javascripts/manage-fields.js
@@ -1,3 +1,4 @@
+/**
function update_active(name_active, name_required, name_signup) {
var required = jQuery("input[name='" + name_required + "']")[1]
var signup = jQuery("input[name='" + name_signup + "']")[1]
@@ -6,15 +7,16 @@ function update_active(name_active, name_required, name_signup) {
if(required.checked || signup.checked)
active.checked = true
}
-
function active_action(obj_active, name_required, name_signup) {
- var required = jQuery("input[name='" + name_required + "']")[0]
- var signup = jQuery("input[name='" + name_signup + "']")[0]
+ console.log( 'teste1' );
+ //var required = jQuery("input[name='" + name_required + "']")[0]
+ //var signup = jQuery("input[name='" + name_signup + "']")[0]
- required.disabled = signup.disabled = !obj_active.checked
+ //required.disabled = signup.disabled = !obj_active.checked
}
function required_action(name_active, name_required, name_signup) {
+ console.log( 'teste' );
var obj_required = jQuery("input[name='" + name_required + "']")[1]
if(obj_required.checked) {
@@ -36,7 +38,6 @@ function signup_action(name_active, name_required, name_signup) {
update_active(name_active, name_required, name_signup)
}
-
jQuery(document).ready(function(){
function check_fields(check, table_id, start) {
var checkboxes = jQuery("#" + table_id + " tbody tr td input[type='checkbox']")
@@ -81,3 +82,114 @@ jQuery(document).ready(function(){
}
})
})
+**/
+
+/** ##################################################################### **/
+
+function send_ajax(source_url) {
+ jQuery(".link-address").autocomplete({
+ source : function(request, response){
+ jQuery.ajax({
+ type: "GET",
+ url: source_url,
+ data: {query: request.term},
+ success: function(result){
+ response(result);
+ },
+ error: function(ajax, stat, errorThrown) {
+ console.log('Link not found : ' + errorThrown);
+ }
+ });
+ },
+
+ minLength: 3
+ });
+}
+
+function new_field_action(){
+ send_ajax(jQuery("#page_url").val());
+
+ jQuery(".delete-link-list-row").click(function(){
+ jQuery(this).parent().parent().remove();
+ return false;
+ });
+
+ jQuery(document).scrollTop(jQuery('#dropable-link-list').scrollTop());
+}
+
+function remove_custom_field(element) {
+ jQuery(element).parent().parent().remove();
+ return false;
+}
+
+function add_new_field(profile_type) {
+
+ console.log( profile_type );
+
+ last_row = jQuery('#' + profile_type + '_fields_conf > tbody:last tr:last');
+
+ if ( last_row.find('label').length == 1 ) {
+
+ var row = '' +
+ '| ' +
+ '' +
+ ' | ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' | ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' | ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' | ' +
+ ' ' +
+ 'Delete ' +
+ ' | ' +
+ '
';
+
+ jQuery('#' + profile_type + '_fields_conf > tbody:last').append(row);
+
+ }
+ else {
+
+ var new_field = jQuery('#' + profile_type + '_fields_conf > tbody:last tr:last').clone();
+
+ var field = new_field.find('input');
+ //var chkboxes = field.filter(':checkbox');
+
+ var re = new RegExp( '\\d', 'g' );
+ var id = field.attr('id').match(re);
+ var next_id = parseInt(id) + 1;
+
+ jQuery.each( field, function( k, v ) {
+ v.id = v.id.replace(id, next_id);
+ v.name = v.name.replace(id, next_id);
+ if (v.type == 'text') { v.value = '' }
+ if (v.type == 'checkbox') { v.value = true; }
+ if (v.type == 'hidden') { v.value = false; }
+
+ });
+
+ //field.val('');
+
+ //chkboxes.attr('onclick', chkboxes.attr('onclick').replace(id, next_id));
+ //console.log( chkboxes );
+
+ jQuery('#' + profile_type + '_fields_conf > tbody').append(new_field);
+
+ }
+
+}
+
+jQuery(document).ready(function(){
+ new_field_action();
+
+ //jQuery("#dropable-link-list").sortable({
+ // revert: true,
+ // axis: "y"
+ //});
+});
--
libgit2 0.21.2