From 946bc87afa5643d702fa996304c9aee0592fe740 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Thu, 16 Apr 2015 12:46:08 +0000 Subject: [PATCH] Fix institution dialog JS --- controllers/gov_user_plugin_controller.rb | 1 + lib/ext/communities_block.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ public/views/create-institution.js | 4 ++-- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 lib/ext/communities_block.rb diff --git a/controllers/gov_user_plugin_controller.rb b/controllers/gov_user_plugin_controller.rb index a85a6df..592dcb8 100644 --- a/controllers/gov_user_plugin_controller.rb +++ b/controllers/gov_user_plugin_controller.rb @@ -67,6 +67,7 @@ class GovUserPluginController < ApplicationController response_message = save_institution @institutions if request.xhr? #User create institution + puts "-"*80, response_message render :json => response_message.to_json else #Admin create institution session[:notice] = response_message[:message] # consume the notice diff --git a/lib/ext/communities_block.rb b/lib/ext/communities_block.rb new file mode 100644 index 0000000..25a968d --- /dev/null +++ b/lib/ext/communities_block.rb @@ -0,0 +1,49 @@ +require_dependency 'communities_block' + +class CommunitiesBlock + + def profile_list + result = get_visible_profiles + + list_without_institution = [] + + result.each do |profile| + if profile.class == Community && !profile.institution? + list_without_institution << profile + end + end + + result = list_without_institution + + result.slice(0..get_limit-1) + end + + def profile_count + profile_list.count + end + + private + + def get_visible_profiles + visible_profiles = profiles.visible.includes( + [:image,:domains,:preferred_domain,:environment] + ) + if !prioritize_profiles_with_image + return visible_profiles.all( + :limit => get_limit, + :order => 'profiles.updated_at DESC' + ).sort_by {rand} + elsif profiles.visible.with_image.count >= get_limit + return visible_profiles.with_image.all( + :limit => get_limit * 5, + :order => 'profiles.updated_at DESC' + ).sort_by {rand} + else + return visible_profiles.with_image.sort_by {rand} + + visible_profiles.without_image.all( + :limit => get_limit * 5, :order => 'profiles.updated_at DESC' + ).sort_by {rand} + end + end + +end diff --git a/public/views/create-institution.js b/public/views/create-institution.js index b40226c..e2b3188 100644 --- a/public/views/create-institution.js +++ b/public/views/create-institution.js @@ -53,7 +53,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] name : $("#community_name").val(), country : $("#community_country").val(), state : $("#community_state").val(), - city : $("#community_city").val() + city : $("#city_field").val() } } @@ -102,7 +102,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] errors += "
  • "+response.errors[i]+"
  • "; } errors += ""; - if($('#institution_dialog') != []){ + if($('#institution_dialog') == 0){ $('#create_institution_errors').switchClass("show-field", "hide-field"); $('#errorExplanation').html("

    "+response.message+"

    "+errors); }else{ -- libgit2 0.21.2