Commit 236a0119 authored by Beat Seeliger's avatar Beat Seeliger

Merge branch 'add/field_reserved_to_client' into 'develop'

Add/field reserved to client

See merge request !1006
parents 0b6c3974 e1cc62f3
Pipeline #65043 passed with stage
in 36 minutes and 29 seconds
......@@ -7,4 +7,5 @@ $(() => {
groupOfferForm();
emailTemplate();
inplaceFields();
clientForm()
});
function clientForm() {
$('.reserve-client-action-cell').on('click', ({ target }) => {
const cell = $(target).closest('td')
const { clientId } = cell.data()
$.ajax({
url: `/clients/${clientId}/reserve`,
type: 'PUT',
}).done(({user_name, btn_text}) => {
if (user_name) {
cell.find('button').remove()
cell.append($(`<span>${user_name}</span>`))
cell.append($(`<button class="btn btn-default">${btn_text}</button>`))
} else {
cell.find('span').remove()
cell.find('button').remove()
cell.append($(`<button class="btn btn-default">${btn_text}</button>`))
}
}).fail(error => {
console.log(error)
})
});
}
......@@ -4,7 +4,7 @@ class ClientsController < ApplicationController
include ContactAttributes
rescue_from Client::NotDestroyableError, with: :user_not_authorized
before_action :set_client, only: [:show, :edit, :update, :destroy, :set_terminated, :reactivate]
before_action :set_client, only: [:show, :edit, :update, :destroy, :set_terminated, :reactivate, :reserve]
before_action :set_social_worker_collection, only: [:new, :create, :edit, :update]
before_action :set_assignments, only: [:show, :edit]
......@@ -84,6 +84,16 @@ class ClientsController < ApplicationController
redirect_to edit_client_path(@client), notice: t("clients.notices.reactivation.#{state}")
end
def reserve
if @client.reserved_by
@client.update(reserved_by: nil, reserved_at: nil)
render json: { btn_text: I18n.t('reserve_client'), user_name: nil }
else
@client.update(reserved_by_id: current_user.id, reserved_at: Time.now)
render json: { user_name: current_user.full_name, btn_text: I18n.t('unreserve_client') }
end
end
private
def create_success_notice
......@@ -134,4 +144,5 @@ class ClientsController < ApplicationController
contact_attributes, availability_attributes
)
end
end
......@@ -22,6 +22,7 @@ class Client < ApplicationRecord
optional: true
belongs_to :involved_authority, -> { with_deleted }, class_name: 'User',
inverse_of: 'involved_authorities', optional: true
belongs_to :reserved_by, class_name: 'User', inverse_of: :reserved_clients, optional: true
has_many :manager_departments, through: :user, source: :departments
has_many :assignments, dependent: :destroy
......
......@@ -15,6 +15,7 @@ class User < ApplicationRecord
has_many :event_volunteers, inverse_of: 'creator', foreign_key: 'creator_id'
has_many :certificates
has_many :clients, inverse_of: 'user', foreign_key: 'user_id'
has_many :reserved_clients, inverse_of: :reserved_by, class_name: 'Client', foreign_key: 'reserved_by_id'
has_many :volunteers, inverse_of: 'registrar', foreign_key: 'registrar_id'
has_many :involved_authorities, class_name: 'Client', foreign_key: 'involved_authority_id',
inverse_of: 'involved_authority'
......
......@@ -31,6 +31,7 @@ class ClientPolicy < ApplicationPolicy
alias_method :edit?, :superadmin_or_client_responsible?
alias_method :update?, :superadmin_or_client_responsible?
alias_method :set_terminated?, :superadmin_or_department_managers_record?
alias_method :reserve?, :superadmin_or_department_managers_record?
# suplementary policies
alias_method :superadmin_privileges?, :superadmin?
......
tr
td.index-action-cell.hidden-print
= button_link icon_span(:show), client, title: 'Anzeigen'
= button_link t('reserve'), new_assignment_url(client_id: client, volunteer_id: @volunteer)
- if policy(Client).superadmin_privileges?
td.button-acceptance = link_to t("acceptance.#{client.acceptance}"), '#',
class: "btn btn-xs btn-acceptance-#{client.acceptance} btn-acceptance-client"
td.button-acceptance= assignment_status_badge(client)
td.reserve-client-action-cell*{ data: { client_id: client.id } }
- if client.reserved_by
span= client.reserved_by.full_name
button.btn.btn-default= t('unreserve_client')
- else
button.btn.btn-default= t('reserve_client')
td= t("salutation.#{client.salutation}") if client.salutation?
td= link_to client.contact.full_name, edit_client_path(client)
td= client.contact.city
td= client.contact.postal_code
td= client.birth_year&.year
td
- client.relatives.each do |relative|
= relative
br
td= nationality_name(client.nationality)
td.language-skill-indexπ
- [client.language_skills.german, client.language_skills.native_languages].flatten.each do |language|
span= language.full_language_skills
td= client.goals
td= client.interests
- if policy(Client).superadmin_privileges?
td= link_to client.involved_authority.full_name, profile_url_path(client.involved_authority) if client.involved_authority
td= client.competent_authority
td= client.other_authorities
td.no-wrap= l(client.created_at.to_date)
- if policy(Client).show_comments?
= td_truncate_content_modal(client.comments, 'Bemerkungen')
\ No newline at end of file
......@@ -29,6 +29,7 @@ nav.navbar.section-navigation
- if policy(Client).superadmin_privileges?
th= sort_link @q, :acceptance, t_attr(:acceptance, Client)
th= sort_link @q, :active, 'Status'
th= sort_link @q, :reserved_by, t_attr(:reserved_by, Client)
th= sort_link @q, :salutation, t_attr(:salutation, Client)
th= sort_link @q, :contact_last_name, t_attr(:full_name, Contact)
th= sort_link @q, :contact_city, t_attr(:city, Contact)
......@@ -52,35 +53,6 @@ nav.navbar.section-navigation
th= t_attr(:comments, Client)
tbody
- @need_accompanying.each do |client|
tr
td.index-action-cell.hidden-print
= button_link icon_span(:show), client, title: 'Anzeigen'
= button_link t('reserve'), new_assignment_url(client_id: client, volunteer_id: @volunteer)
- if policy(Client).superadmin_privileges?
td.button-acceptance = link_to t("acceptance.#{client.acceptance}"), '#',
class: "btn btn-xs btn-acceptance-#{client.acceptance} btn-acceptance-client"
td.button-acceptance= assignment_status_badge(client)
td= t("salutation.#{client.salutation}") if client.salutation?
td= link_to client.contact.full_name, edit_client_path(client)
td= client.contact.city
td= client.contact.postal_code
td= client.birth_year&.year
td
- client.relatives.each do |relative|
= relative
br
td= nationality_name(client.nationality)
td.language-skill-index
- [client.language_skills.german, client.language_skills.native_languages].flatten.each do |language|
span= language.full_language_skills
td= client.goals
td= client.interests
- if policy(Client).superadmin_privileges?
td= link_to client.involved_authority.full_name, profile_url_path(client.involved_authority) if client.involved_authority
td= client.competent_authority
td= client.other_authorities
td.no-wrap= l(client.created_at.to_date)
- if policy(Client).show_comments?
= td_truncate_content_modal(client.comments, 'Bemerkungen')
= render 'need_accompanying', client: client
= bootstrap_paginate(@need_accompanying)
......@@ -231,6 +231,8 @@ de:
relatives: Familienangehörige im Haushalt
remember_me: Angemeldet bleiben
reserve: Begleitung erstellen
reserve_client: Reservieren
unreserve_client: Reservation aufheben
seeking_clients: Klient/in suchen
semester_long: '%{number}. Semester %{year} (%{begin} - %{end})'
semester_period: '%{begin} - %{end}'
......@@ -353,6 +355,7 @@ de:
permit: Bewilligung
relatives: Verwandte/r
user: User
reserved_by: Reserviert
contact:
<<: *id-generic_keys
extended: Adresszusatz
......
......@@ -65,6 +65,7 @@ Rails.application.routes.draw do
resources :clients, concerns: [:search, :reactivate] do
resources :journals, except: [:show]
patch :set_terminated, on: :member
put :reserve, on: :member
end
resources :events do
......
class AddReservedToClient < ActiveRecord::Migration[5.1]
def change
change_table :clients do |t|
t.bigint :reserved_by_id, index: true
t.datetime :reserved_at
end
end
end
\ No newline at end of file
......@@ -218,6 +218,8 @@ ActiveRecord::Schema.define(version: 20191122135842) do
t.bigint "reactivated_by_id"
t.datetime "reactivated_at"
t.text "other_authorities"
t.bigint "reserved_by_id"
t.datetime "reserved_at"
t.index ["acceptance"], name: "index_clients_on_acceptance"
t.index ["accepted_at"], name: "index_clients_on_accepted_at"
t.index ["birth_year"], name: "index_clients_on_birth_year"
......@@ -888,5 +890,6 @@ ActiveRecord::Schema.define(version: 20191122135842) do
add_foreign_key "semester_process_volunteers", "volunteers"
add_foreign_key "trial_feedbacks", "users", column: "author_id"
add_foreign_key "volunteers", "departments"
add_foreign_key "volunteers", "departments", column: "secondary_department_id"
add_foreign_key "volunteers", "users"
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment