From 6f667a865ba49a896620c41657764c4b83b6987f Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Sun, 3 Apr 2016 22:08:46 +0530 Subject: [PATCH] create_venue_commercial added --- .../venue_commercials_controller.rb} | 4 +-- app/models/venue.rb | 1 + app/views/admin/venues/_form.html.haml | 27 +++++++++++++++++++ config/routes.rb | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) rename app/controllers/{venue_commercial_controller.rb => admin/venue_commercials_controller.rb} (92%) diff --git a/app/controllers/venue_commercial_controller.rb b/app/controllers/admin/venue_commercials_controller.rb similarity index 92% rename from app/controllers/venue_commercial_controller.rb rename to app/controllers/admin/venue_commercials_controller.rb index 87777f3b..d46b858b 100644 --- a/app/controllers/venue_commercial_controller.rb +++ b/app/controllers/admin/venue_commercials_controller.rb @@ -1,11 +1,11 @@ module Admin - class CommercialsController < Admin::BaseController + class VenueCommercialsController < Admin::BaseController load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :venue ,through: :conference, singelton: true before_action :set_venue def create - @commercial = @venue.commercial.build(commercial_params) + @commercial = @venue.build_commercial(commercial_params) authorize! :create, @commercial #FIXME redirect to tab#commercial diff --git a/app/models/venue.rb b/app/models/venue.rb index 914c7c0a..4642a3ce 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -4,6 +4,7 @@ class Venue < ActiveRecord::Base 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..639008ea 100644 --- a/app/views/admin/venues/_form.html.haml +++ b/app/views/admin/venues/_form.html.haml @@ -12,3 +12,30 @@ = image_tag @venue.photo(:thumb) = f.input :photo = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } + + .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(@venue.create_commercial,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 +- @venue.commercial do |commercial| + - if commercial.persisted? + .col-md-4 + .thumbnail + .flexvideo{ id: "resource-content-#{commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: commercial } + .caption + - if can? :update, commercial + = semantic_form_for commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: commercial) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{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, commercial + = link_to 'Delete', admin_conference_venue_venue_commercial_path(@conference.short_title, commercial.id), + method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' + %hr diff --git a/config/routes.rb b/config/routes.rb index e0c7150c..28b5884f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,7 +43,7 @@ Osem::Application.routes.draw do # Singletons resource :splashpage resource :venue do - get 'venue_commercial/render_commercial' => 'venue_commercial#render_commercial' + get 'venue_commercial/render_commercial' => 'venue_commercials#render_commercial' resource :venue_commercial, only: [:create, :update, :destroy] resources :rooms, except: [:show] end