diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb new file mode 100644 index 00000000..3eb26b4d --- /dev/null +++ b/app/controllers/admin/contacts_controller.rb @@ -0,0 +1,43 @@ +class Admin::ContactsController < ApplicationController + before_action :set_conference + before_action :set_contact, only: [:show, :edit, :update, :destroy] + + # GET /:conference/contact + def show + end + + # GET /:conference/contact/edit + def edit + end + + # PATCH/PUT /:conference/contact + def update + if @contact.update(contact_params) + redirect_to admin_conference_contact_path, notice: 'Contact details were successfully updated.' + else + render :edit + end + end + + # DELETE /:conference/contact + def destroy + @contact.destroy + redirect_to admin_conference_contacts_url, notice: 'Contact details were successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_contact + @contact = @conference.contact + end + + def set_conference + @conference = Conference.find_by(short_title: params[:conference_id]) + end + + # Only allow a trusted parameter "white list" through. + def contact_params + # params.require(:contact).permit(:social_tag, :email, :facebook, :googleplus, :twitter, :instagram, :public) + params[:contact] + end +end diff --git a/app/models/conference.rb b/app/models/conference.rb index 68b9aad0..2e5cbce8 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -27,6 +27,8 @@ class Conference < ActiveRecord::Base has_and_belongs_to_many :questions + has_one :contact, dependent: :destroy + has_one :email_settings, dependent: :destroy has_one :call_for_papers, dependent: :destroy has_many :social_events, dependent: :destroy @@ -523,6 +525,10 @@ class Conference < ActiveRecord::Base private + after_create do + self.create_contact + end + ## # Calculates the weeks from a start and a end week. # diff --git a/app/models/contact.rb b/app/models/contact.rb new file mode 100644 index 00000000..c108d989 --- /dev/null +++ b/app/models/contact.rb @@ -0,0 +1,8 @@ +class Contact < ActiveRecord::Base + attr_accessible :conference, :social_tag, :email, :facebook, :googleplus, :twitter, :instagram, :public + belongs_to :conference + + validates :conference, presence: true + # Conferences only have one contact + validates :conference_id, :uniqueness => {:message => "has already contact details"} +end diff --git a/app/views/admin/contacts/_form.html.haml b/app/views/admin/contacts/_form.html.haml new file mode 100644 index 00000000..8113ebd3 --- /dev/null +++ b/app/views/admin/contacts/_form.html.haml @@ -0,0 +1,31 @@ += form_for @contact, url: admin_conference_contact_path do |f| + - if @contact.errors.any? + #error_explanation + %h2= "#{pluralize(@contact.errors.count, "error")} prohibited this contact from being saved:" + %ul + - @contact.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label :social_tag + = f.text_field :social_tag + .field + = f.label :email + = f.text_field :email + .field + = f.label :facebook + = f.text_field :facebook + .field + = f.label :googleplus + = f.text_field :googleplus + .field + = f.label :twitter + = f.text_field :twitter + .field + = f.label :instagram + = f.text_field :instagram + .field + = f.label :public + = f.check_box :public + .actions + = f.submit 'Save' diff --git a/app/views/admin/contacts/edit.html.haml b/app/views/admin/contacts/edit.html.haml new file mode 100644 index 00000000..f3dc61f9 --- /dev/null +++ b/app/views/admin/contacts/edit.html.haml @@ -0,0 +1,5 @@ +%h1 Editing contact + += render 'form' + += link_to 'Back', admin_conference_contact_path diff --git a/app/views/admin/contacts/show.html.haml b/app/views/admin/contacts/show.html.haml new file mode 100644 index 00000000..d73f904f --- /dev/null +++ b/app/views/admin/contacts/show.html.haml @@ -0,0 +1,26 @@ +%p#notice= notice + +%p + %b Social tag: + = @contact.social_tag +%p + %b Email: + = @contact.email +%p + %b Facebook: + = @contact.facebook +%p + %b Googleplus: + = @contact.googleplus +%p + %b Twitter: + = @contact.twitter +%p + %b Instagram: + = @contact.instagram +%p + %b Public: + = @contact.public + += link_to 'Edit', edit_admin_conference_contact_path + diff --git a/config/routes.rb b/config/routes.rb index 20c43a75..53071950 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Osem::Application.routes.draw do + devise_for :users, controllers: { registrations: :registrations, omniauth_callbacks: 'users/omniauth_callbacks' }, path: 'accounts' @@ -8,6 +9,7 @@ Osem::Application.routes.draw do resources :users resources :people resources :conference do + resource :contact, except: [:index, :new, :create] resource :schedule, only: [:show, :update] get '/stats' => 'stats#index' get '/venue' => 'venue#show', as: 'venue_info' diff --git a/db/migrate/20140731153332_create_contacts.rb b/db/migrate/20140731153332_create_contacts.rb new file mode 100644 index 00000000..df1b3ce7 --- /dev/null +++ b/db/migrate/20140731153332_create_contacts.rb @@ -0,0 +1,17 @@ +class CreateContacts < ActiveRecord::Migration + def change + create_table :contacts do |t| + t.string :social_tag + t.string :email + t.string :facebook + t.string :googleplus + t.string :twitter + t.string :instagram + + t.boolean :public + t.integer :conference_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4f112525..71054b79 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140724113107) do +ActiveRecord::Schema.define(version: 20140731153332) do create_table "ahoy_events", force: true do |t| t.uuid "visit_id" @@ -133,6 +133,19 @@ ActiveRecord::Schema.define(version: 20140724113107) do t.integer "question_id" end + create_table "contacts", force: true do |t| + t.string "social_tag" + t.string "email" + t.string "facebook" + t.string "googleplus" + t.string "twitter" + t.string "instagram" + t.boolean "public" + t.integer "conference_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "delayed_jobs", force: true do |t| t.integer "priority", default: 0, null: false t.integer "attempts", default: 0, null: false @@ -487,8 +500,8 @@ ActiveRecord::Schema.define(version: 20140724113107) do create_table "venues", force: true do |t| t.string "guid" - t.text "name", limit: 255 - t.text "address", limit: 255 + t.text "name" + t.text "address" t.string "website" t.text "description" t.string "offline_map_url" @@ -499,8 +512,8 @@ ActiveRecord::Schema.define(version: 20140724113107) do t.string "photo_content_type" t.integer "photo_file_size" t.datetime "photo_updated_at" - t.boolean "include_venue_in_splash", default: false - t.boolean "include_lodgings_in_splash", default: false + t.boolean "include_venue_in_splash", default: false + t.boolean "include_lodgings_in_splash", default: false end create_table "versions", force: true do |t|