Commit 93e21cdc authored by Hussain Kashef's avatar Hussain Kashef

Reservation workflow client

parent 3652d72e
Pipeline #63943 passed with stage
in 34 minutes and 34 seconds
......@@ -7,4 +7,5 @@ $(() => {
groupOfferForm();
emailTemplate();
inplaceFields();
clientForm()
});
function clientForm() {
$('.reserve-client-action-cell').on('click', ({ target }) => {
const cell = $(target).closest('td')
console.log(cell)
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)
})
});
}
......@@ -85,9 +85,12 @@ class ClientsController < ApplicationController
end
def reserve
@client.update(reserved_by: current_user.id, reserved_at: Time.now)
respond_to do |format|
format.js
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
......
......@@ -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'
......
......@@ -6,7 +6,14 @@
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= button_link t('reserve_client'), reserve_client_path(client_id: client, volunteer_id: @volunteer), id: "reserve_client#{client.id}", remote: true, method: :put
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= button_link t('reserve_client'), reserve_client_path(client_id: client, volunteer_id: @volunteer), id: "reserve_client#{client.id}", remote: true, method: :put
td= t("salutation.#{client.salutation}") if client.salutation?
td= link_to client.contact.full_name, edit_client_path(client)
td= client.contact.city
......@@ -17,7 +24,7 @@
= relative
br
td= nationality_name(client.nationality)
td.language-skill-index
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
......
......@@ -228,6 +228,7 @@ de:
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}'
......
class AddReservedToClient < ActiveRecord::Migration[5.1]
def change
add_column :clients, :reserved_by, :bigint, index: true
add_column :clients, :reserved_at, :datetime
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,7 +218,7 @@ ActiveRecord::Schema.define(version: 20191024143050) do
t.bigint "reactivated_by_id"
t.datetime "reactivated_at"
t.text "other_authorities"
t.bigint "reserved_by"
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"
......
This diff is collapsed.
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