diff --git a/src/noosfero-spb/gov_user/codeclimate.yml b/src/noosfero-spb/gov_user/codeclimate.yml new file mode 100644 index 0000000..2887f37 --- /dev/null +++ b/src/noosfero-spb/gov_user/codeclimate.yml @@ -0,0 +1,54 @@ +# This is a sample .codeclimate.yml configured for Engine analysis on Code +# Climate Platform. For an overview of the Code Climate Platform, see here: +# http://docs.codeclimate.com/article/300-the-codeclimate-platform + +# Under the engines key, you can configure which engines will analyze your repo. +# Each key is an engine name. For each value, you need to specify enabled: true +# to enable the engine as well as any other engines-specific configuration. + +# For more details, see here: +# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform + +# For a list of all available engines, see here: +# http://docs.codeclimate.com/article/296-engines-available-engines + +engines: +# to turn on an engine, add it here and set enabled to `true` +# to turn off an engine, set enabled to `false` or remove it + rubocop: + enabled: true + golint: + enabled: true + gofmt: + enabled: true + eslint: + enabled: true + csslint: + enabled: true + +# Engines can analyze files and report issues on them, but you can separately +# decide which files will receive ratings based on those issues. This is +# specified by path patterns under the ratings key. + +# For more details see here: +# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform + +# Note: If the ratings key is not specified, this will result in a 0.0 GPA on your dashboard. + +ratings: + paths: + - **.rb + - **.js + - **.css +# - lib/** +# - "**.rb" +# - "**.go" + +# You can globally exclude files from being analyzed by any engine using the +# exclude_paths key. + +exclude_paths: + - public/vendor/* + - features/**/* +#- spec/**/* +#- vendor/**/* diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb index 80a41db..d0f14dc 100644 --- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb +++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb @@ -1,5 +1,9 @@ #aqui deve ter so usuario e instituicao class GovUserPluginController < ApplicationController + VERIFY_ERRORS_IN = [ + :name, :country, :state, :city, :corporate_name, :cnpj, + :governmental_sphere, :governmental_power, :juridical_nature, :sisp + ] def hide_registration_incomplete_percentage response = false @@ -13,15 +17,7 @@ class GovUserPluginController < ApplicationController end def create_institution - @show_sisp_field = environment.admins.include?(current_user.person) - @state_list = get_state_list() - @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} - @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} - @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} - @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]} - - params[:community] ||= {} - params[:institutions] ||= {} + create_institution_view_variables if request.xhr? render :layout=>false @@ -30,26 +26,10 @@ class GovUserPluginController < ApplicationController end end - def split_http_referer http_referer - split_list = [] - split_list = http_referer.split("/") - @url_token = split_list.last - return @url_token - end - def create_institution_admin - @show_sisp_field = environment.admins.include?(current_user.person) - @state_list = get_state_list() - @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]} - @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]} - @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]} - @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]} + create_institution_view_variables @url_token = split_http_referer request.original_url() - - params[:community] ||= {} - params[:institutions] ||= {} - end def new_institution @@ -77,7 +57,7 @@ class GovUserPluginController < ApplicationController def institution_already_exists redirect_to "/" if !request.xhr? || params[:name].blank? - already_exists = !Community.where(:name=>params[:name]).empty? + already_exists = !Institution.find_by_name(params[:name]).nil? render :json=>already_exists.to_json end @@ -85,18 +65,18 @@ class GovUserPluginController < ApplicationController def get_institutions redirect_to "/" if !request.xhr? || params[:query].blank? - list = Institution.search_institution(params[:query]).map{ |institution| + institutions = Institution.search_institution(params[:query]).select([:id, :name]) + institutions_list = institutions.map { |institution| {:value=>institution.name, :id=>institution.id} } - render :json => list.to_json + render :json => institutions_list.to_json end def get_brazil_states redirect_to "/" unless request.xhr? - state_list = get_state_list() - render :json=>state_list.collect {|state| state.name }.to_json + render :json=>get_state_list().to_json end def get_field_data @@ -122,6 +102,24 @@ class GovUserPluginController < ApplicationController protected + def split_http_referer http_referer="" + split_list = http_referer.split("/") + split_list.last + end + + def create_institution_view_variables + params[:community] ||= {} + params[:institutions] ||= {} + + @show_sisp_field = environment.admins.include?(current_user.person) + @governmental_sphere = get_governmental_spheres() + @governmental_power = get_governmental_powers() + @juridical_nature = get_juridical_natures() + + state_list = get_state_list() + @state_options = state_list.zip(state_list).prepend([_('Select a state'), '-1']) + end + def get_model_by_params_field case params[:field] when "software_language" @@ -132,11 +130,26 @@ class GovUserPluginController < ApplicationController end def get_state_list - NationalRegion.find( - :all, - :conditions=>["national_region_type_id = ?", 2], - :order=>"name" - ) + NationalRegion.select(:name).where(:national_region_type_id => 2).order(:name).map &:name + end + + def get_governmental_spheres + spheres = [[_("Select a Governmental Sphere"), 0]] + spheres.concat get_model_as_option_list(GovernmentalSphere) + end + + def get_governmental_powers + powers = [[_("Select a Governmental Power"), 0]] + powers.concat get_model_as_option_list(GovernmentalPower) + end + + def get_juridical_natures + natures = [[_("Select a Juridical Nature"), 0]] + natures.concat get_model_as_option_list(JuridicalNature) + end + + def get_model_as_option_list model + model.select([:id, :name]).map {|m| [m.name, m.id]} end def set_institution_type @@ -236,16 +249,20 @@ class GovUserPluginController < ApplicationController institution.valid? if institution institution.community.valid? if institution.community - flash[:error_community_name] = institution.community.errors.include?(:name) ? "highlight-error" : "" - flash[:error_community_country] = institution.errors.include?(:country) ? "highlight-error" : "" - flash[:error_community_state] = institution.errors.include?(:state) ? "highlight-error" : "" - flash[:error_community_city] = institution.errors.include?(:city) ? "highlight-error" : "" - flash[:error_institution_corporate_name] = institution.errors.include?(:corporate_name) ? "highlight-error" : "" - flash[:error_institution_cnpj] = institution.errors.include?(:cnpj) ? "highlight-error" : "" - flash[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : "" - flash[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : "" - flash[:error_institution_juridical_nature] = institution.errors.include?(:juridical_nature) ? "highlight-error" : "" - flash[:error_institution_sisp] = institution.errors.include?(:sisp) ? "highlight-error" : "" + dispatch_flash_errors institution, "institution" + dispatch_flash_errors institution.community, "community" + end + + def dispatch_flash_errors model, flash_key_base + model.errors.messages.keys.each do |error_key| + flash_key = "error_#{flash_key_base}_#{error_key}".to_sym + + if VERIFY_ERRORS_IN.include? error_key + flash[flash_key] = "highlight-error" + else + flash[flash_key] = "" + end + end end end diff --git a/src/noosfero-spb/gov_user/public/app.js b/src/noosfero-spb/gov_user/public/app.js index 7e98375..c21cf21 100644 --- a/src/noosfero-spb/gov_user/public/app.js +++ b/src/noosfero-spb/gov_user/public/app.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + (function() { 'use strict'; diff --git a/src/noosfero-spb/gov_user/public/initializer.js b/src/noosfero-spb/gov_user/public/initializer.js index 395f20c..aaf8c9f 100644 --- a/src/noosfero-spb/gov_user/public/initializer.js +++ b/src/noosfero-spb/gov_user/public/initializer.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + (function() { 'use strict'; diff --git a/src/noosfero-spb/gov_user/public/lib/noosfero-root.js b/src/noosfero-spb/gov_user/public/lib/noosfero-root.js index cd3c8bf..3280f1c 100644 --- a/src/noosfero-spb/gov_user/public/lib/noosfero-root.js +++ b/src/noosfero-spb/gov_user/public/lib/noosfero-root.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define('NoosferoRoot', function() { 'use strict'; diff --git a/src/noosfero-spb/gov_user/public/lib/select-element.js b/src/noosfero-spb/gov_user/public/lib/select-element.js index 26880ae..f342a2b 100644 --- a/src/noosfero-spb/gov_user/public/lib/select-element.js +++ b/src/noosfero-spb/gov_user/public/lib/select-element.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define('SelectElement', function() { 'use strict'; diff --git a/src/noosfero-spb/gov_user/public/lib/select-field-choices.js b/src/noosfero-spb/gov_user/public/lib/select-field-choices.js index 095d4e1..21711c5 100644 --- a/src/noosfero-spb/gov_user/public/lib/select-field-choices.js +++ b/src/noosfero-spb/gov_user/public/lib/select-field-choices.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define('SelectFieldChoices', ['jquery', 'SelectElement'], function($, SelectElement) { 'use strict'; diff --git a/src/noosfero-spb/gov_user/public/views/complete-registration.js b/src/noosfero-spb/gov_user/public/views/complete-registration.js index 81dd745..541260c 100644 --- a/src/noosfero-spb/gov_user/public/views/complete-registration.js +++ b/src/noosfero-spb/gov_user/public/views/complete-registration.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define('CompleteRegistration', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) { 'use strict'; diff --git a/src/noosfero-spb/gov_user/public/views/control-panel.js b/src/noosfero-spb/gov_user/public/views/control-panel.js index d89a588..f0aecb6 100644 --- a/src/noosfero-spb/gov_user/public/views/control-panel.js +++ b/src/noosfero-spb/gov_user/public/views/control-panel.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define('ControlPanel', ['jquery'], function($) { 'use strict'; diff --git a/src/noosfero-spb/gov_user/public/views/create-institution.js b/src/noosfero-spb/gov_user/public/views/create-institution.js index 354295c..2da1926 100644 --- a/src/noosfero-spb/gov_user/public/views/create-institution.js +++ b/src/noosfero-spb/gov_user/public/views/create-institution.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'], function($, NoosferoRoot, SelectElement) { 'use strict'; @@ -221,6 +223,11 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] select : function (event, selected) { $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); + + // +("") -> 0; +("1") -> 1... + if (+($("#institution_selected").val()) !== 0) { + add_new_institution(); + } } }); } @@ -234,27 +241,27 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] } - function add_new_institution(evt) { - evt.preventDefault(); + function add_new_institution() { var selected = $("#institution_selected"); - var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length; + var already_added_to_list = is_institution_already_added_to_list(selected.val()); - if(selected.val().length > 0 && institution_already_added === 0) { + if(selected.val().length > 0 && !already_added_to_list) { //field that send the institutions to the server $(".institution_container").append(get_clone_institution_data(selected.val())); // Visualy add the selected institution to the list add_selected_institution_to_list(selected.val(), selected.attr("data-name")); - // clean the institution flag - selected.val("").attr("data-name", ""); - $("#input_institution").val(""); - $(".remove-institution").click(remove_institution); } } + function is_institution_already_added_to_list(institution_id) { + return $(".institutions_added li[data-institution='"+institution_id+"']").length !== 0; + } + + function remove_institution(evt) { evt.preventDefault(); var code = $(this).parent().attr("data-institution"); @@ -369,8 +376,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] $("#community_name").keyup(institution_already_exists); - $("#add_new_institution").click(add_new_institution); - $(".remove-institution").click(remove_institution); $("#community_country").change(function(){ diff --git a/src/noosfero-spb/gov_user/public/views/gov-user-comments-extra-fields.js b/src/noosfero-spb/gov_user/public/views/gov-user-comments-extra-fields.js index d302437..4521aff 100644 --- a/src/noosfero-spb/gov_user/public/views/gov-user-comments-extra-fields.js +++ b/src/noosfero-spb/gov_user/public/views/gov-user-comments-extra-fields.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define("GovUserCommentsExtraFields", ['jquery','CreateInstitution'], function($,CreateInstitution) { function set_events() { diff --git a/src/noosfero-spb/gov_user/public/views/new-community.js b/src/noosfero-spb/gov_user/public/views/new-community.js index b665e8f..0de70c7 100644 --- a/src/noosfero-spb/gov_user/public/views/new-community.js +++ b/src/noosfero-spb/gov_user/public/views/new-community.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define("NewCommunity", ['jquery'], function($) { function replace_mandatory_message() { @@ -8,7 +10,7 @@ modulejs.define("NewCommunity", ['jquery'], function($) { function remove_image_builder_text() { $("label:contains('Image builder')").hide(); } - + function hide_organization_template_fields(){ $('#template-options').hide(); } diff --git a/src/noosfero-spb/gov_user/public/views/user-edit-profile.js b/src/noosfero-spb/gov_user/public/views/user-edit-profile.js index c92c987..049647d 100644 --- a/src/noosfero-spb/gov_user/public/views/user-edit-profile.js +++ b/src/noosfero-spb/gov_user/public/views/user-edit-profile.js @@ -1,3 +1,5 @@ +/* globals modulejs */ + modulejs.define('UserEditProfile', ['jquery', 'SelectElement', 'SelectFieldChoices', 'CreateInstitution'], function($, SelectElement, SelectFieldChoices, CreateInstitution) { 'use strict'; diff --git a/src/noosfero-spb/gov_user/views/person_editor_extras.html.erb b/src/noosfero-spb/gov_user/views/person_editor_extras.html.erb index a3a11fc..163bf21 100644 --- a/src/noosfero-spb/gov_user/views/person_editor_extras.html.erb +++ b/src/noosfero-spb/gov_user/views/person_editor_extras.html.erb @@ -19,8 +19,7 @@ <%= content_tag(:div, _("No institution found"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field") %> - <%= link_to(_("Add new institution"), "#", :class=>'button with-text icon-add', :id => 'add_new_institution') %> - <%= link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add') %> + <%= link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add') %> <%= content_tag(:div, "", :id=>"institution_dialog") %> <%= hidden_field_tag("user[institution_ids][]", "", :class => 'user_institutions') %> -- libgit2 0.21.2