Skip to content
Snippets Groups Projects
Commit c33e2e04 authored by pabois's avatar pabois
Browse files

wip organizations

parent f795beaf
No related branches found
No related tags found
No related merge requests found
/*global $ */
$(function () {
'use strict';
var setAutocompleteTargetValue = function (targetId, value) {
var setAutocompleteTargetValue,
setAutocompleteNothingFound;
setAutocompleteTargetValue = function (targetId, value) {
var targetInput = document.querySelector(targetId);
if (targetInput) {
targetInput.value = value;
}
};
setAutocompleteNothingFound = function (target, search) {
var defaultText,
text;
if (target) {
defaultText = target.dataset.defaultText;
text = defaultText.replaceAll('CHANGEME', search);
target.innerHTML = text;
target.classList.remove('d-none');
}
};
$('input.autocomplete')
.on('input', function ($event) {
setAutocompleteTargetValue($event.target.dataset.autocompleteTarget, '');
})
.on('railsAutocomplete.select', function ($event, data) {
var noResultTarget = document.querySelector($event.target.dataset.autocompleteNoResultTarget);
setAutocompleteTargetValue($event.target.dataset.autocompleteTarget, data.item.id);
noResultTarget.classList.add('d-none');
})
.on('railsAutocomplete.source', function ($event, data) {
var noResultTarget = document.querySelector($event.target.dataset.autocompleteNoResultTarget);
if (data.length === 0) {
setAutocompleteNothingFound(noResultTarget, $event.target.value);
} else {
noResultTarget.classList.add('d-none');
}
});
});
......@@ -12,13 +12,6 @@ class Extranet::Alumni::OrganizationsController < Extranet::Alumni::ApplicationC
breadcrumb
end
def search
@term = params[:term].to_s
@organizations = current_university.organizations
.search_by_siren_or_name(@term)
.ordered
end
def show
@organization = about.university_person_alumni_organizations.find(params[:id])
breadcrumb
......
......@@ -19,6 +19,23 @@ class Extranet::ApplicationController < ApplicationController
end
def authorize_extranet_access!
raise CanCan::AccessDenied if current_user.visitor? && about.alumni.find_by(id: current_user.person&.id).nil?
raise CanCan::AccessDenied unless user_is_authorized?
end
def user_is_authorized?
user_is_more_than_visitor || user_is_alumnus || user_is_contact
end
def user_is_more_than_visitor
!current_user.visitor?
end
def user_is_alumnus
about.alumni.find_by(id: current_user.person&.id).present?
end
def user_is_contact
current_extranet.connected_persons.find_by(id: current_user.person&.id).present?
end
end
......@@ -42,4 +42,4 @@ class Extranet::ExperiencesController < Extranet::ApplicationController
add_breadcrumb t('extranet.account.my'), account_path
add_breadcrumb @experience
end
end
\ No newline at end of file
end
class Extranet::OrganizationsController < Extranet::ApplicationController
def search
@term = params[:term].to_s
@organizations = current_university.organizations
.search_by_siren_or_name(@term)
.ordered
end
end
......@@ -39,8 +39,6 @@ class University::Person::Experience < ApplicationRecord
# validates_numericality_of :to_year, { greater_than_or_equal_to: :from_year }, allow_nil: true
validate :to_year, :not_before_from_year
before_validation :create_organization_if_needed
scope :ordered, -> { order('university_person_experiences.to_year DESC NULLS FIRST, university_person_experiences.from_year') }
scope :recent, -> {
where.not(from_year: nil)
......@@ -65,13 +63,4 @@ class University::Person::Experience < ApplicationRecord
end
end
def create_organization_if_needed
if organization.nil? && organization_name.present?
self.organization_name = self.organization_name.strip
orga = university.organizations.find_by("name ILIKE ?", organization_name)
orga ||= university.organizations.find_by(siren: organization_name)
orga ||= university.organizations.create(name: organization_name, created_from_extranet: true)
self.organization = orga if orga.persisted?
end
end
end
......@@ -26,18 +26,24 @@
<%= f.input :organization_name,
label: University::Organization.model_name.human,
as: :autocomplete,
url: alumni_search_university_organizations_path,
url: search_organizations_path,
placeholder: t("extranet.experiences.search_organization"),
input_html: {
data: {
"showNoMatches": "false",
"autocomplete-target": "#university_person_experience_organization_id"
"autocomplete-target": "#university_person_experience_organization_id",
"autocomplete-no-result-target": "#university_person_experience_organization_not_found"
},
autocomplete: 'off',
role: 'presentation'
} %>
<%= f.hidden_field :organization_id %>
<div class="<%= 'd-none' unless experience.organization_id.nil? && experience.organization_name.present? %>" id="university_person_experience_organization_not_found" data-default-text="<%= t('extranet.account.experiences.create_new_html', name: 'CHANGEME', url: new_organization_path(name: 'CHANGEME')) %>">
<% if experience.organization_id.nil? && experience.organization_name.present? %>
<%= t('extranet.account.experiences.create_new_html', name: experience.organization_name, url: new_organization_path(name: experience.organization_name)) %>
<% end %>
</div>
</div>
</div>
<%= submit f %>
<% end %>
\ No newline at end of file
<% end %>
......@@ -2,9 +2,11 @@ en:
extranet:
features: Features
account:
my: My account
edit: Edit account
edit_personal_data: Edit profile
experiences:
create_new_html: The organization *** doesn't exist, do you want to <a class='btn btn-primary' href='%{url}'>create it</a>?
my: My account
updated: Updated
logout: Log out
contacts:
......@@ -38,4 +40,4 @@ en:
updated: Your personal data has been updated!
posts:
home: Recent posts
read_post: Read post
\ No newline at end of file
read_post: Read post
......@@ -2,9 +2,11 @@ fr:
extranet:
features: Fonctionnalités
account:
my: Mon compte
edit: Modifier mon compte
edit_personal_data: Modifier mon profil
experiences:
create_new_html: L'organisation <b>%{name}</b> n'existe pas, souhaitez-vous <a class='btn btn-primary' href='%{url}'>la créer</a> ?
my: Mon compte
updated: Mise à jour effectuée
logout: Déconnexion
contacts:
......@@ -38,4 +40,4 @@ fr:
updated: Mise à jour des donnes personnelles effectuée !
posts:
home: Actualités récentes
read_post: Lire l'article
\ No newline at end of file
read_post: Lire l'article
......@@ -7,18 +7,22 @@ namespace :contacts do
get 'search' => 'search#index', as: :search
root to: 'persons#index'
end
namespace :alumni do
namespace :alumni do
get 'cohorts' => 'cohorts#index', as: :education_cohorts
get 'cohorts/:id' => 'cohorts#show', as: :education_cohort
get 'organizations' => 'organizations#index', as: :university_organizations
get 'organizations/search' => 'organizations#search', as: :search_university_organizations, defaults: { format: 'json' }
get 'organizations/:id' => 'organizations#show', as: :university_organization
get 'organization/:id' => 'organizations#show', as: :university_organization
get 'persons' => 'persons#index', as: :university_persons
get 'persons/:id' => 'persons#show', as: :university_person
get 'years' => 'academic_years#index', as: :education_academic_years
get 'years/:id' => 'academic_years#show', as: :education_academic_year
root to: 'persons#index'
end
resources :organizations, except: :destroy do
collection do
get 'search' => 'organizations#search', as: :search, defaults: { format: 'json' }
end
end
namespace :posts do
get ':slug' => 'posts#show', as: :communication_extranet_post
root to: 'posts#index'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment