Skip to content

Commit

Permalink
tilføjede modal form til jobbere for email + styling af index på jobb…
Browse files Browse the repository at this point in the history
…ere og jobs
  • Loading branch information
wdiechmann committed Feb 25, 2015
1 parent 83e902f commit 375f04f
Show file tree
Hide file tree
Showing 28 changed files with 292 additions and 32 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -21,6 +21,7 @@ gem 'simple_form'
gem 'upmin-admin'
gem 'dotenv-rails'
gem 'masonry-rails'
gem 'ancestry'
group :production do
gem "unicorn"
end
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -35,6 +35,8 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.3.6)
ancestry (2.1.0)
activerecord (>= 3.0.0)
arel (5.0.1.20140414130214)
bcrypt (3.1.9)
bcrypt-ruby (3.1.5)
Expand Down Expand Up @@ -295,6 +297,7 @@ PLATFORMS
ruby

DEPENDENCIES
ancestry
bcrypt-ruby
better_errors
binding_of_caller
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/delivery_teams.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/delivery_teams.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the delivery_teams controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
47 changes: 47 additions & 0 deletions app/controllers/delivery_teams_controller.rb
@@ -0,0 +1,47 @@
class DeliveryTeamsController < ApplicationController
before_action :set_delivery_team, only: [:show, :edit, :update, :destroy]

respond_to :html

def index
@delivery_teams = DeliveryTeam.all
respond_with(@delivery_teams)
end

def show
respond_with(@delivery_team)
end

def new
@delivery_team = DeliveryTeam.new(parent_id: params[:parent_id])
respond_with(@delivery_team)
end

def edit
end

def create
@delivery_team = DeliveryTeam.new(delivery_team_params)
@delivery_team.save
respond_with(@delivery_team)
end

def update
@delivery_team.update(delivery_team_params)
respond_with(@delivery_team)
end

def destroy
@delivery_team.destroy
respond_with(@delivery_team)
end

private
def set_delivery_team
@delivery_team = DeliveryTeam.find(params[:id])
end

def delivery_team_params
params.require(:delivery_team).permit(:title, :ancestry, :description, :parent_id)
end
end
21 changes: 20 additions & 1 deletion app/controllers/jobs_controller.rb
@@ -1,6 +1,7 @@
class JobsController < ApplicationController
before_action :set_job, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!, except: :create
before_filter :collection_for_parent_select, :except => [:index, :show]
after_action :verify_authorized

# GET /jobs
Expand All @@ -17,6 +18,7 @@ def show

# GET /jobs/new
def new
@delivery_teams = ancestry_options(DeliveryTeam.scoped.arrange(:order => 'title')) {|i| "#{'-' * i.depth} #{i.title}" }
@job = Job.new
authorize @job
end
Expand Down Expand Up @@ -67,6 +69,23 @@ def destroy
end

private


def collection_for_parent_select
@delivery_teams = ancestry_options(DeliveryTeam.unscoped.arrange(:order => 'title')) {|i| "#{'-' * i.depth} #{i.title}" }
end


def ancestry_options(items)
result = []
items.map do |item, sub_items|
result << [yield(item), item.id]
#this is a recursive call:
result += ancestry_options(sub_items) {|i| "#{'-' * i.depth} #{i.title}" }
end
result
end

# Use callbacks to share common setup or constraints between actions.
def set_job
@job = Job.find(params[:id])
Expand All @@ -75,6 +94,6 @@ def set_job

# Never trust parameters from the scary internet, only allow the white list through.
def job_params
params.require(:job).permit(:name, :location, :schedule, :priority, :delegated_at, :jobbers_min, :jobbers_wanted, :jobbers_max, :vacancies, :description, :promote_job_at)
params.require(:job).permit(:name, :location, :schedule, :priority, :delegated_at, :jobbers_min, :jobbers_wanted, :jobbers_max, :vacancies, :description, :promote_job_at, :delivery_team_id)
end
end
2 changes: 2 additions & 0 deletions app/helpers/delivery_teams_helper.rb
@@ -0,0 +1,2 @@
module DeliveryTeamsHelper
end
3 changes: 3 additions & 0 deletions app/models/delivery_team.rb
@@ -0,0 +1,3 @@
class DeliveryTeam < ActiveRecord::Base
has_ancestry
end
11 changes: 11 additions & 0 deletions app/views/delivery_teams/_form.html.haml
@@ -0,0 +1,11 @@
= simple_form_for(@delivery_team) do |f|
= f.error_notification

.form-inputs
= f.input :title
/ = f.input :ancestry
= f.hidden_field :parent_id
= f.input :description

.form-actions
= f.button :submit, class: 'btn btn-primary'
7 changes: 7 additions & 0 deletions app/views/delivery_teams/edit.html.haml
@@ -0,0 +1,7 @@
%h1 Editing delivery_team

= render 'form'

= link_to 'Show', @delivery_team
\|
= link_to 'Back', delivery_teams_path
29 changes: 29 additions & 0 deletions app/views/delivery_teams/index.html.haml
@@ -0,0 +1,29 @@
:css
a.sub_delivery_team { text-transform: lowercase !important}
.container-fluid
.row
.col-md-12
%h1 Oversigt over udvalg

.row
.col-md-12
%table.table.table-striped
%tr
%th Navn
%th Hører under
%th.hidden-xs Beskrivelse
%th

- @delivery_teams.each do |delivery_team|
%tr
%td= link_to delivery_team.title, delivery_team
%td= link_to delivery_team.parent.title, delivery_team.parent rescue ''
%td.hidden-xs= delivery_team.description
%td= link_to 'Nyt underudvalg', new_delivery_team_path(parent_id: delivery_team ), class: 'sub_delivery_team btn btn-primary'
%td
= link_to(delivery_team, :method => :delete, class: ' btn btn-danger btn-small', :data => { :confirm => 'Er du sikker?' }) do
%span.glyphicon.glyphicon-trash{:"aria-hidden"=>"true"}
%br
= link_to 'Nyt hoved udvalg', new_delivery_team_path, class: 'btn btn-success'
4 changes: 4 additions & 0 deletions app/views/delivery_teams/index.json.jbuilder
@@ -0,0 +1,4 @@
json.array!(@delivery_teams) do |delivery_team|
json.extract! delivery_team, :id, :title, :ancestry, :description
json.url delivery_team_url(delivery_team, format: :json)
end
5 changes: 5 additions & 0 deletions app/views/delivery_teams/new.html.haml
@@ -0,0 +1,5 @@
%h1 New delivery_team

= render 'form'

= link_to 'Oversigt', delivery_teams_path, class: 'btn btn-default'
14 changes: 14 additions & 0 deletions app/views/delivery_teams/show.html.haml
@@ -0,0 +1,14 @@
%p#notice= notice

%p
%b Navn:
= @delivery_team.title
%p
%b Hører under:
= @delivery_team.parent.title rescue ''
%p
%b Beskrivelse:
= @delivery_team.description

= link_to 'Ret', edit_delivery_team_path(@delivery_team), class: 'btn btn-primary'
= link_to 'Back', delivery_teams_path, class: 'btn btn-default'
1 change: 1 addition & 0 deletions app/views/delivery_teams/show.json.jbuilder
@@ -0,0 +1 @@
json.extract! @delivery_team, :id, :title, :ancestry, :description, :created_at, :updated_at
69 changes: 61 additions & 8 deletions app/views/jobbers/index.html.haml
@@ -1,3 +1,6 @@
:css
span.email { text-transform: lowercase !important }

.container-fluid
.row
.col-md-12
Expand All @@ -7,24 +10,74 @@
.col-md-12
%table.table.table-striped
%tr
%th Name
%th Navn
/ %th Street
/ %th Zip city
%th Phone number
%th Tlf
%th Email
%th Confirmed at
%th Bekræftet
%th

- @jobbers.each do |jobber|
%tr
%td= link_to jobber.name, jobber
/ %td= jobber.street
/ %td= jobber.zip_city
%td= jobber.phone_number
%td= jobber.email
%td= jobber.confirmed_at
%td= link_to 'Destroy', jobber, :method => :delete, :data => { :confirm => 'Are you sure?' }
%td
%button.btn.btn-default
%span.glyphicon.glyphicon-phone-alt{ :"aria-hidden"=>"true", title: "#{jobber.phone_number}"}
%span.hidden-xs= jobber.phone_number

%td
%button{ title: "#{jobber.email}", type:"button", class:"btn btn-primary btn-small", :"data-toggle"=> "modal", :"data-target"=> "#newMessage", :"data-recipient"=>"#{jobber.email}" }
%span.glyphicon.glyphicon-envelope{ :"aria-hidden"=>"true"}
%span.email.visible-md-inline.visible-lg-inline
=jobber.email.downcase
%td
- unless jobber.confirmed_at.nil?
%button.btn.btn-default
%span.glyphicon.glyphicon-ok{}
%span.hidden-xs= jobber.confirmed_at.strftime "%d/%m/%Y"
%td
= link_to(jobber, :method => :delete, class: ' btn btn-danger btn-small', :data => { :confirm => 'Er du sikker?' }) do
%span.glyphicon.glyphicon-trash{:"aria-hidden"=>"true"}
%br
= link_to 'Ny jobber', new_jobber_path, class: 'btn btn-success'
#newMessage.modal.fade{ tabindex:"-1", role:"dialog", :"aria-labelledby"=>"exampleModalLabel", :"aria-hidden"=>"true" }
.modal-dialog
.modal-content
.modal-header
%button{ type:"button", class:"close", :"data-dismiss"=>"modal", :"aria-label"=>"Close"}
%span{ :"aria-hidden"=>"true"} &times;
%h4.modal-title{ id: "exampleModalLabel"} Ny besked
.modal-body
%form
.form-group
%label{ for:"recipient-name", class:"control-label"} Til:
%input{ type:"text", class:"form-control", id:"recipient-name"}
.form-group
%label{ for:"subject", class:"control-label"} Emne:
%input{ type:"text", class:"form-control", id:"subject"}
.form-group
%label{ for:"message-text", class:"control-label"} Besked
%textarea{ class:"form-control", id:"message-text"}
.modal-footer
%button.btn.btn-default{ type:"button", :"data-dismiss"=>"modal"} Fortryd
%button.btn.btn-primary{ type:"button"} Send
:coffeescript
$('#newMessage').on 'show.bs.modal', (event) ->
button = $(event.relatedTarget)
recipient = button.data('recipient')
modal = $(this)
modal.find('.modal-title').text('Ny besked til ' + recipient)
modal.find('.modal-body input').val(recipient)
6 changes: 4 additions & 2 deletions app/views/jobs/_form.html.haml
@@ -1,7 +1,7 @@

:css
#job_description { min-height: 100px; }


%h3
- if @job.new_record?
Expand Down Expand Up @@ -46,6 +46,9 @@
= f.date_field :promote_job_at, :autofocus => true, class: 'form-control floating-label', placeholder: 'Fra hvilken dato må jobbet blive vist på job portalen? (angiv ingen dato, hvis jobbet er "internt")'
= f.error :promote_job_at

.form-group
= f.input :delivery_team_id, as: :select, collection: @delivery_teams

/ .form-group
/ = f.number_field :vacancies, :autofocus => true, class: 'form-control floating-label', placeholder: 'Hvordan'
/ = f.error :vacancies
Expand All @@ -72,4 +75,3 @@
# done=true
#
# $('[data-toggle="popover"]').popover()

7 changes: 5 additions & 2 deletions app/views/jobs/index.html.haml
Expand Up @@ -12,14 +12,17 @@
%th Hvornår
%th Hvem
%th

- @jobs.each do |job|
%tr
%td= link_to job.name, job
%td= job.location
%td= job.schedule
%td mgl
%td= link_to 'Destroy', job, :method => :delete, :data => { :confirm => 'Are you sure?' }
%td
/ = link_to 'Destroy', job, :method => :delete, :data => { :confirm => 'Are you sure?' }
= link_to(job, :method => :delete, class: ' btn btn-danger btn-small', :data => { :confirm => 'Er du sikker?' }) do
%span.glyphicon.glyphicon-trash{:"aria-hidden"=>"true"}
%br
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/_navigation_links.html.haml
@@ -1,6 +1,7 @@
- if user_signed_in?
%li= link_to 'Jobs', jobs_path
/ %li= link_to 'Jobbere', jobbers_path
%li= link_to 'Jobbere', jobbers_path
%li= link_to 'Udvalg', delivery_teams_path
%li= link_to t('devise.navigation.edit_account'), edit_user_registration_path
%li= link_to t('devise.navigation.sign_out'), destroy_user_session_path, :method=>'delete'

Expand Down
5 changes: 4 additions & 1 deletion config/locales/da.yml
Expand Up @@ -21,7 +21,7 @@

da:
visitor:
be_a_jobber: 'Sæt dit eget frillige spor'
be_a_jobber: 'Sæt dit eget frivillige spor'
current_jobs: 'Aktuelle jobs'
jobbers: 'Frivillige'
jobs: 'Jobs'
Expand Down Expand Up @@ -77,6 +77,9 @@ da:

simple_form:
labels:
delivery_team:
title: 'Navn'
description: 'Beskrivelse'
jobber:
job_name: 'Det job jeg er lidt lun på'
name: 'Navn (for- og efternavn)'
Expand Down
3 changes: 2 additions & 1 deletion config/locales/simple_form.da.yml
Expand Up @@ -2,6 +2,7 @@ en:
simple_form:
"yes": 'Yes'
"no": 'No'

required:
text: 'required'
mark: '*'
Expand All @@ -10,6 +11,7 @@ en:
# html: '<abbr title="required">*</abbr>'
error_notification:
default_message: "Please review the problems below:"

# Labels and hints examples
# labels:
# defaults:
Expand All @@ -23,4 +25,3 @@ en:
# defaults:
# username: 'User name to sign in.'
# password: 'No special characters, please.'

0 comments on commit 375f04f

Please sign in to comment.