diff --git a/app/controllers/admin/venue_commercials_controller.rb b/app/controllers/admin/venue_commercials_controller.rb new file mode 100644 index 00000000..20117e15 --- /dev/null +++ b/app/controllers/admin/venue_commercials_controller.rb @@ -0,0 +1,53 @@ +module Admin + class VenueCommercialsController < Admin::BaseController + load_and_authorize_resource :conference, find_by: :short_title + load_and_authorize_resource :venue, through: :conference, singleton: true + load_and_authorize_resource :commercial, through: :venue, singleton: true + + def create + @commercial = @venue.build_commercial(commercial_params) + authorize! :create, @commercial + + if @commercial.save + redirect_to admin_conference_venue_path, + notice: 'Commercial was successfully created.' + else + redirect_to admin_conference_venue_path, + error: 'An error prohibited this Commercial from being saved: '\ + "#{@commercial.errors.full_messages.join('. ')}." + + end + end + + def update + if @commercial.update(commercial_params) + redirect_to admin_conference_venue_path, + notice: 'Commercial was successfully updated.' + else + redirect_to admin_conference_venue_path, + error: 'An error prohibited this Commercial from being saved: '\ + "#{@commercial.errors.full_messages.join('. ')}." + end + end + + def destroy + @commercial.destroy + redirect_to admin_conference_venue_path, notice: 'Commercial was successfully destroyed.' + end + + def render_commercial + result = Commercial.render_from_url(params[:url]) + if result[:error] + render text: result[:error], status: 400 + else + render text: result[:html] + end + end + + private + + def commercial_params + params.require(:commercial).permit(:url) + end + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index b54f8ab0..e3d34ec8 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -151,6 +151,8 @@ class Ability can :manage, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id) can :manage, Venue, conference_id: conf_ids_for_organizer + can :manage, Commercial, commercialable_type: 'Venue', + commercialable_id: Venue.where(conference_id: conf_ids_for_organizer).pluck(:id) can :manage, Lodging, conference_id: conf_ids_for_organizer can :manage, Room, venue: { conference_id: conf_ids_for_organizer} can :manage, Sponsor, conference_id: conf_ids_for_organizer @@ -177,6 +179,7 @@ class Ability can :manage, EmailSettings, conference_id: conf_ids_for_cfp can :manage, Room, venue: { conference_id: conf_ids_for_cfp } can :show, Venue, conference_id: conf_ids_for_cfp + can :show, Commercial, commercialable_type: 'Venue', commercialable_id: Venue.where(conference_id: conf_ids_for_cfp).pluck(:id) can :manage, Cfp, program: { conference_id: conf_ids_for_cfp } can :manage, Program, conference_id: conf_ids_for_cfp can :manage, Commercial, commercialable_type: 'Event', diff --git a/app/models/venue.rb b/app/models/venue.rb index 25d3b8cd..4642a3ce 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -1,8 +1,10 @@ class Venue < ActiveRecord::Base belongs_to :conference + has_one :commercial, as: :commercialable, dependent: :destroy has_many :rooms, dependent: :destroy before_create :generate_guid + accepts_nested_attributes_for :commercial, allow_destroy: true validates :name, :street, :city, :country, presence: true validates :conference_id, presence: true, uniqueness: true diff --git a/app/views/admin/venues/_form.html.haml b/app/views/admin/venues/_form.html.haml index f63d34cc..00f3e501 100644 --- a/app/views/admin/venues/_form.html.haml +++ b/app/views/admin/venues/_form.html.haml @@ -2,13 +2,55 @@ .col-md-12 .page-header %h1 Venue -.row - .col-md-8 - = semantic_form_for(@venue, url: admin_conference_venue_path(@conference.short_title)) do |f| - = f.inputs :name, :website - = f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint - = f.inputs :street, :postalcode, :city, :country, :latitude, :longitude - - unless @venue.photo.blank? - = image_tag @venue.photo(:thumb) - = f.input :photo - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } +.tabbable + %ul.nav.nav-tabs + %li.active + = link_to 'Details', '#details-content', 'data-toggle' => 'tab' + %li + = link_to 'Commercials', '#commercials-content', 'data-toggle' => 'tab' + + .tab-content + #details-content.tab-pane.active + .col-md-8 + = semantic_form_for(@venue, url: admin_conference_venue_path(@conference.short_title)) do |f| + = f.inputs :name, :website + = f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint + = f.inputs :street, :postalcode, :city, :country, :latitude, :longitude + - unless @venue.photo.blank? + = image_tag @venue.photo(:thumb) + = f.input :photo + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } + + #commercials-content.tab-pane + - if can? :create, @venue.commercial and @venue.id + - if @venue.commercial.nil? + .row + .col-md-6 + #resource-content + #resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' } + + .row + .col-md-6 + = semantic_form_for(Commercial.new,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' }, + hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.' + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true } + %hr + - else + - if @venue.commercial.persisted? + .col-md-4 + .thumbnail + .flexvideo{ id: "resource-content-#{@venue.commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: @venue.commercial } + .caption + - if can? :update, @venue.commercial + = semantic_form_for @venue.commercial, as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: @venue.commercial.id) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{@venue.commercial.id}", required: 'required' }, hint: 'Just paste the url of your video/photo provider' + = f.action :submit, as: :button, button_html: { class: 'btn btn-success' }, label: 'Update' + - if can? :destroy, @venue.commercial + = link_to 'Delete', admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: @venue.commercial.id), + method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' + %hr + + - else + First Create Venue, then update commercial diff --git a/app/views/admin/venues/show.html.haml b/app/views/admin/venues/show.html.haml index 18266ede..48fe9bcd 100644 --- a/app/views/admin/venues/show.html.haml +++ b/app/views/admin/venues/show.html.haml @@ -9,10 +9,16 @@ .col-md-6 - if @conference.venue.location? = render 'conference/venue_map' - - elsif @conference.venue.photo.blank? - %img{ "data-src" => "holder.js/300x200?text=No Image Set", class: 'img-responsive img-rounded' } - - elsif !@conference.venue.photo.blank? - =image_tag(@conference.venue.photo, class: 'img-responsive img-rounded') + -else + - if @venue.commercial.nil? + .row + %img{ "data-src" => "holder.js/500x300?text=No Commercial Set", class: 'img-responsive img-rounded' } + - else + - if @venue.commercial.persisted? + .thumbnail + .flexvideo{ id: "resource-content-#{@venue.commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: @venue.commercial } + .col-md-6 %address %strong diff --git a/app/views/conference/_venue.html.haml b/app/views/conference/_venue.html.haml index b2b7874b..74dad5a7 100644 --- a/app/views/conference/_venue.html.haml +++ b/app/views/conference/_venue.html.haml @@ -6,12 +6,17 @@ -else .container .row - .col-md-12 + - if @conference.venue.commercial.present? and @conference.venue.commercial.persisted? + .col-md-5 + .thumbnail + .flexvideo{ id: "resource-content-#{@conference.venue.commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: @conference.venue.commercial } + + .col-md-6 %h2.text-center = "#{@conference.venue.city} / #{@conference.venue.country_name}" .col-md-6 .thumbnail - =image_tag(@conference.venue.photo, class: 'img-responsive img-rounded') unless @conference.venue.photo.blank? .caption - unless @conference.venue.description.blank? = markdown(@conference.venue.description) diff --git a/config/routes.rb b/config/routes.rb index c416f3b0..60c6565d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,6 +41,8 @@ Osem::Application.routes.draw do # Singletons resource :splashpage resource :venue do + get 'venue_commercial/render_commercial' => 'venue_commercials#render_commercial' + resource :venue_commercial, only: [:create, :update, :destroy] resources :rooms, except: [:show] end resource :registration_period