From 3a2bf49f9722c69f4e7a901a176032db3a810c64 Mon Sep 17 00:00:00 2001 From: Ancor Gonzalez Sosa Date: Wed, 10 Jul 2013 16:13:53 +0200 Subject: [PATCH] Adding and removing people --- app/controllers/admin/people_controller.rb | 17 +++++- app/models/person.rb | 1 + app/views/admin/people/_form.html.haml | 10 ++++ app/views/admin/people/index.html.haml | 62 +++++++++++++--------- app/views/application/edit.html.haml | 1 + app/views/application/new.html.haml | 1 + 6 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 app/views/admin/people/_form.html.haml create mode 100644 app/views/application/edit.html.haml create mode 100644 app/views/application/new.html.haml diff --git a/app/controllers/admin/people_controller.rb b/app/controllers/admin/people_controller.rb index b1ceeafb..4b25c683 100644 --- a/app/controllers/admin/people_controller.rb +++ b/app/controllers/admin/people_controller.rb @@ -1,5 +1,6 @@ class Admin::PeopleController < ApplicationController before_filter :verify_organizer + respond_to :html def index @people = Person.all @@ -15,16 +16,28 @@ class Admin::PeopleController < ApplicationController end end - def create + def new + @person = Person.new + end + def create + @person = Person.new(params[:person]) + flash[:notice] = 'Person was successfully created.' if @person.save + respond_with @person, :location => admin_people_path end def show @person = Person.find(params[:id]) end - def update + def edit + @person = Person.find(params[:id]) + end + def update + @person = Person.find(params[:id]) + flash[:notice] = 'Person was successfully updated' if @person.update_attributes(params[:person]) + respond_with @person, :location => admin_people_path end def delete diff --git a/app/models/person.rb b/app/models/person.rb index 05470c6a..5d7fb5fa 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -10,6 +10,7 @@ class Person < ActiveRecord::Base validates :first_name, :presence => true validates :last_name, :presence => true + validates :email, :presence => true validate :biography_limit before_create :generate_guid diff --git a/app/views/admin/people/_form.html.haml b/app/views/admin/people/_form.html.haml new file mode 100644 index 00000000..a4c5d045 --- /dev/null +++ b/app/views/admin/people/_form.html.haml @@ -0,0 +1,10 @@ += semantic_form_for [:admin, @person] do |f| + = f.inputs "Basic Information" do + = f.input :first_name, :as => :string + = f.input :last_name, :as => :string + = f.input :public_name, :as => :string + = f.input :email + = f.input :company, :as => :string + = f.input :biography, :input_html => {:rows => 10} + = f.actions do + = f.action :submit, :button_html => {:class => "btn primary"} diff --git a/app/views/admin/people/index.html.haml b/app/views/admin/people/index.html.haml index 5b62382e..b98df39e 100644 --- a/app/views/admin/people/index.html.haml +++ b/app/views/admin/people/index.html.haml @@ -1,29 +1,39 @@ -%h2 - People - - if @people - = "(#{@people.length})" -.well - %table.table.table-striped.table-bordered.table-hover#people - %thead - %th - %b Email - %th - %b Last Name - %th - %b First Name - %th - %b Public Name - %th - %b # of Conference Registrations - %th - - @people.each do |person| - %tr - %td= person.email - %td= person.last_name - %td= person.first_name - %td= person.public_name - %td= person.registrations.count - %td= link_to "View", admin_person_path(person) +.row-fluid + .span6 + %h2 + People + - if @people + = "(#{@people.length})" + .span6 + .pull-right{:style=>"margin-top:20px; margin-bottom:20px;"} + = link_to "New person", new_admin_person_path, :class => "btn btn-success" + +.row-fluid + .span12 + .well + %table.table.table-striped.table-bordered.table-hover#people + %thead + %th + %b Email + %th + %b Last Name + %th + %b First Name + %th + %b Public Name + %th + %b # of Conference Registrations + %th + %th + - @people.each do |person| + %tr + %td= person.email + %td= person.last_name + %td= person.first_name + %td= person.public_name + %td= person.registrations.count + %td= link_to "Edit", edit_admin_person_path(person) + %td= link_to "View", admin_person_path(person) :javascript $(document).ready(function() { diff --git a/app/views/application/edit.html.haml b/app/views/application/edit.html.haml new file mode 100644 index 00000000..f3a2592b --- /dev/null +++ b/app/views/application/edit.html.haml @@ -0,0 +1 @@ += render :partial => "form" diff --git a/app/views/application/new.html.haml b/app/views/application/new.html.haml new file mode 100644 index 00000000..f3a2592b --- /dev/null +++ b/app/views/application/new.html.haml @@ -0,0 +1 @@ += render :partial => "form"