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

create orgas from extranet

parent e5d4ca3a
No related branches found
No related tags found
No related merge requests found
class Extranet::OrganizationsController < Extranet::ApplicationController
before_action :load_organization, only: [:show, :edit, :update]
def search
@term = params[:term].to_s
......@@ -7,5 +8,67 @@ class Extranet::OrganizationsController < Extranet::ApplicationController
.ordered
end
def show
breadcrumb
end
def new
@organization = current_university.organizations.new
@organization.name = params[:name] if params.has_key?(:name)
breadcrumb
add_breadcrumb t('create')
end
def create
@organization = current_university.organizations.new(organization_params)
if @organization.save
redirect_to organization_path(@organization),
notice: t('admin.successfully_created_html', model: @organization.to_s)
else
breadcrumb
add_breadcrumb t('create')
render :new, status: :unprocessable_entity
end
end
def edit
breadcrumb
add_breadcrumb t('edit')
end
def update
if @organization.update(organization_params)
redirect_to organization_path(@organization),
notice: t('admin.successfully_updated_html', model: @organization.to_s)
else
breadcrumb
add_breadcrumb t('edit')
render :new, status: :unprocessable_entity
end
end
private
def breadcrumb
super
add_breadcrumb University::Organization.model_name.human(count: 2)
add_breadcrumb @organization, organization_path(@organization) if @organization.persisted?
end
def load_organization
# this is an "experience" organization so it can be not connected to the extranet
@organization = current_university.organizations.find_by!(id: params[:id])
end
def organization_params
params.require(:university_organization)
.permit(
:name, :long_name, :summary, :siren, :kind,
:address, :address_name, :address_additional, :zipcode, :city, :country, :text,
:url, :phone, :email, :linkedin, :twitter, :mastodon,
:logo, :logo_delete, :logo_infos,
:logo_on_dark_background, :logo_on_dark_background_delete, :logo_on_dark_background_infos,
)
end
end
<% url = organization.persisted? ? organization_path(organization) : organizations_path %>
<%= simple_form_for organization, url: url do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<div class="row">
<div class="col-xl-6">
<%= f.input :name %>
<%= render 'admin/application/summary/form', f: f, about: organization %>
<%= f.input :text,
as: :summernote,
input_html: {
data: { 'summernote-config' => 'mini-list' }
} %>
<h2><%= University::Organization.human_attribute_name('legal') %></h2>
<div class="row">
<div class="col-xl-6">
<%= f.input :long_name %>
</div>
<div class="col-xl-6">
<%= f.input :kind, include_blank: false %>
</div>
<div class="col-xl-6">
<%= f.input :siren %>
</div>
</div>
</div>
<div class="col-xl-6">
<h2><%= University::Organization.human_attribute_name('physical') %></h2>
<div class="row">
<div class="col-xl-6">
<%= f.input :address_name %>
</div>
<div class="col-xl-6">
<%= f.input :address %>
</div>
<div class="col-xl-6">
<%= f.input :address_additional %>
</div>
<div class="col-xl-6">
<%= f.input :zipcode %>
</div>
<div class="col-xl-6">
<%= f.input :city %>
</div>
<div class="col-xl-6">
<%= f.input :country, input_html: { class: 'form-select' } %>
</div>
</div>
<h2><%= University::Organization.human_attribute_name('digital') %></h2>
<div class="row">
<div class="col-xl-6">
<%= f.input :url %>
</div>
<div class="col-xl-6">
<%= f.input :phone %>
</div>
<div class="col-xl-6">
<%= f.input :email %>
</div>
<div class="col-xl-6">
<%= f.input :linkedin %>
</div>
<div class="col-xl-6">
<%= f.input :twitter %>
</div>
<div class="col-xl-6">
<%= f.input :mastodon %>
</div>
</div>
<h2><%= University::Organization.human_attribute_name('logos') %></h2>
<%= f.input :logo,
as: :single_deletable_file,
input_html: { accept: '.jpg,.jpeg,.png,.svg' },
preview: 200,
resize: false,
direct_upload: true %>
<%= f.input :logo_on_dark_background,
as: :single_deletable_file,
input_html: { accept: '.jpg,.jpeg,.png,.svg' },
preview: 200,
resize: false,
direct_upload: true %>
</div>
</div>
<%= submit f %>
<% end %>
<% content_for :title, @organization %>
<%= render 'form', organization: @organization %>
<% content_for :title, University::Organization.model_name.human %>
<%= render 'form', organization: @organization %>
<% content_for :title, @organization %>
<div class="row">
<div class="col-md-8">
<%= render 'admin/application/summary/show', about: @organization %>
<%= osuny_panel University::Organization.human_attribute_name('text') do %>
<%= @organization.text.to_s.html_safe %>
<% end if strip_tags(@organization.text.to_s).present? %>
<%= osuny_panel University::Organization.human_attribute_name('physical') do %>
<div class="row pure__row--small">
<% [
:address_name,
:address,
:address_additional,
:zipcode,
:city,
].each do |property| %>
<% value = @organization.send property %>
<% next if value.blank? %>
<div class="col-xxl-6">
<%= osuny_label University::Organization.human_attribute_name(property) %>
<p><%= value %></p>
</div>
<% end %>
<% if @organization.country.present? %>
<div class="col-xxl-6">
<%= osuny_label University::Organization.human_attribute_name('country') %>
<p><%= ISO3166::Country[@organization.country].common_name %></p>
</div>
<% end %>
<% if @organization.geolocated? %>
<div class="col-xxl-6">
<%= osuny_label University::Organization.human_attribute_name('geolocation') %>
<p><%= @organization.geo_point.to_s %></p>
</div>
<% end %>
</div>
<% end %>
<%= osuny_panel University::Organization.human_attribute_name('digital') do %>
<div class="row pure__row--small">
<% unless @organization.url.blank? %>
<div class="col-xxl-6">
<%= osuny_label University::Organization.human_attribute_name('url') %>
<p><%= link_to @organization.url,
@organization.url,
target: :_blank %></p>
</div>
<% end %>
<% [
:phone,
:email,
:linkedin,
:twitter,
:mastodon
].each do |property| %>
<% value = @organization.send property %>
<% next if value.blank? %>
<div class="col-xxl-6">
<%= osuny_label University::Organization.human_attribute_name(property) %>
<p><%= value %></p>
</div>
<% end %>
</div>
<% end %>
<%= osuny_panel University::Organization.human_attribute_name('legal') do %>
<div class="row pure__row--small">
<div class="col-xxl-6">
<%= osuny_label University::Organization.human_attribute_name('long_name') %>
<p><%= @organization.long_name %></p>
</div>
<div class="col-xxl-6">
<%= osuny_label University::Organization.human_attribute_name('kind') %>
<p><%= @organization.kind_i18n %></p>
</div>
<div class="col-xxl-6">
<%= osuny_label University::Organization.human_attribute_name('siren') %>
<p><%= @organization.siren %></p>
</div>
</div>
<% end %>
<%= render 'admin/communication/blocks/list', about: @organization %>
</div>
<div class="col-md-4">
<%= osuny_panel t('metadata') do %>
<%= osuny_label University::Organization.human_attribute_name('slug') %>
<p><%= @organization.slug %></p>
<%= osuny_label University::Organization.human_attribute_name('active') %>
<p><%= t @organization.active %></>
<% end %>
<%= osuny_panel t('university.organization.logo') do %>
<% if @organization.logo.attached? %>
<%= osuny_label University::Organization.human_attribute_name('logo') %><br>
<%= kamifusen_tag @organization.logo, class: 'img-fluid img-fill bg-light img-thumbnail p-5 mb-3' %>
<% end %>
<% if @organization.logo_on_dark_background.attached? %>
<%= osuny_label University::Organization.human_attribute_name('logo_on_dark_background') %><br>
<%= kamifusen_tag @organization.logo_on_dark_background, class: 'img-fluid img-fill bg-dark img-thumbnail p-5' %>
<% end %>
<% end if @organization.logo.attached? || @organization.logo_on_dark_background.attached? %>
<%= render 'admin/application/meta_description/show', about: @organization %>
</div>
</div>
<% if @organization.experiences.any? %>
<h2><%= t('university.organization.employees') %></h2>
<div class="table-responsive">
<table class="<%= table_classes %>">
<thead>
<tr>
<th><%= University::Person.human_attribute_name('last_name') %></th>
<th><%= University::Person.human_attribute_name('first_name') %></th>
<th><%= t('university.person.experience.period') %></th>
</tr>
</thead>
<tbody>
<% @organization.experiences.ordered.each do |experience| %>
<%
alumnus = experience.person
path = admin_university_alumnus_path(alumnus)
%>
<tr>
<td><%= link_to_if can?(:read, alumnus), alumnus.last_name, path %></td>
<td><%= link_to_if can?(:read, alumnus), alumnus.first_name, path %></td>
<td>
<%= "#{experience.from_year} - #{experience.to_year.present? ? experience.to_year : t('today')}" %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
<% content_for :action_bar_left do %>
<%= destroy_link @organization %>
<%= static_link static_admin_university_organization_path(@organization) %>
<% end %>
<% content_for :action_bar_right do %>
<%= edit_link @organization %>
<% end %>
......@@ -18,7 +18,7 @@ namespace :alumni do
get 'years/:id' => 'academic_years#show', as: :education_academic_year
root to: 'persons#index'
end
resources :organizations, except: :destroy do
resources :organizations, except: [:index, :destroy] do
collection do
get 'search' => 'organizations#search', as: :search, defaults: { format: 'json' }
end
......
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