Skip to content

Instantly share code, notes, and snippets.

@dobleuber
Created July 7, 2014 15:22
Show Gist options
  • Save dobleuber/5ba214487bec8ab2dec4 to your computer and use it in GitHub Desktop.
Save dobleuber/5ba214487bec8ab2dec4 to your computer and use it in GitHub Desktop.
module Refinery
module Locations
class Event < Refinery::Core::BaseModel
validates :title, :presence => true, :uniqueness => true
belongs_to :poster, :class_name => '::Refinery::Image'
belongs_to :event_category
belongs_to :state
belongs_to :city
belongs_to :location
has_and_belongs_to_many :locations,
:join_table => :refinery_locations_refinery_locations_events,
:foreign_key => "refinery_locations_event_id",
:association_foreign_key => "refinery_location_id",
:class_name => "Refinery::Locations::Location"
accepts_nested_attributes_for :locations
# To enable admin searching, add acts_as_indexed on searchable fields, for example:
#
# acts_as_indexed :fields => [:title]
end
end
end
<div class="container">
<%= form_for [refinery, :locations_admin, @event], html: {role:'form'} do |f| -%>
<%= render '/refinery/admin/error_messages',
:object => @event,
:include_object_name => true %>
<div class='form-group'>
<%= f.label :title -%>
<%= f.text_field :title, :class => 'form-control' -%>
</div>
<div class='form-group'>
<%= render '/refinery/admin/wysiwyg',
:f => f,
:fields => [:description, :short_description],
:object => "locations/event" -%>
</div>
<div class="row">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#event_details">Edit Event Details</a></li>
<li><a data-toggle="tab" href="#sectionB">Sign-Up Editor</a></li>
</ul>
<div class="container location-details">
<div class="col-md-6 location">
<div class="tab-content">
<div id="event_details" class="tab-pane fade in active">
<div id="custom-location">
<div class="form-group">
<h2>Custom Location<a href="javascript:setNativeLocation('t');" class="btn btn-default pull-right">Native Foods Location?</a></h2>
</div>
<div class="form-group">
<%= f.label :street_address -%>
<%= f.text_field :street_address, :class => 'form-control' -%>
</div>
<div class="form-group hidden">
<%= f.label :country -%>
<%= f.text_field :country, :class => 'form-control', :value => 'US' -%>
</div>
<div class="form-group">
<%= f.label :state -%>
<%= f.select(:state_id, @states.collect {|d| [d.name, d.id] }, {include_blank: true}, {:class => 'form-control'})%>
</div>
<div class="form-group">
<%= f.label :city -%>
<%= f.select(:city_id, @cities.collect {|d| [d.name, d.id] }, {include_blank: true}, {:class => 'form-control'})%>
</div>
<div class="form-group">
<%= f.label :zip -%>
<%= f.text_field :zip, :class => 'form-control' -%>
</div>
</div>
<div id="native-location">
<div class="form-group">
<h2>Location<a href="javascript:setNativeLocation('f');" class="btn btn-default pull-right">Custom Location?</a></h2>
</div>
<div class="form-group">
<%= f.label 'Native Foods Location' -%>
<%= f.select(:location_id, @locations.collect {|d| [d.name, d.id] }, {include_blank: true}, {:class => 'form-control'})%>
</div>
</div>
<div class='field hidden'>
<%= f.label :directionslink -%>
<%= f.text_field :directionslink -%>
</div>
<div class='field hidden'>
<%= f.label :is_native_location -%>
<%= f.text_field :is_native_location -%>
</div>
<br/>
<div class="form-group">
<h2>Contact</h2>
</div>
<div class="form-group">
<%= f.label :telephone -%>
<%= f.text_field :telephone, :class => 'form-control' -%>
</div>
<div class="form-group">
<%= f.label :fax -%>
<%= f.text_field :fax, :class => 'form-control' -%>
</div>
<div class="form-group">
<%= f.label :email -%>
<%= f.text_field :email, :class => 'form-control' -%>
</div>
<br/>
<div class="form-group">
<h2>When</h2>
</div>
<div class='form-group'>
<%= f.label :time_start -%>
<%= f.time_select :time_start, {}, {:class => 'form-control select'} -%>
</div>
<div class='form-group'>
<%= f.label :time_end -%>
<%= f.time_select :time_end, {}, {:class => 'form-control select'} -%>
</div>
<div class='form-group'>
<%= f.label :date -%>
<%= f.date_select :date, {}, {:class => 'form-control select'} -%>
</div>
<div class='form-group'>
<%= f.label :posting_date -%>
<%= f.date_select :posting_date, {}, {:class => 'form-control select'} -%>
</div>
</div>
<div id="sectionB" class="tab-pane fade">
<p>Section B content…</p>
</div>
</div>
</div>
<div class="col-md-6 previewMap">
<div class="form-group"><h2>Preview Map</h2></div>
<div class="form-group">
<%= image_tag(@event.directionslink, :id => "event_mappreview", :alt => "map preview", :width => 400, :height => 300)-%>
</div>
<div class='form-group'>
<%= f.label :poster -%>
<%= render '/refinery/admin/image_picker',
:f => f,
:field => :poster_id,
:image => @event.poster,
:toggle_image_display => false -%>
</div>
<div class="form-group">
<%= f.label "Associated Locations" -%>
<%= select_tag "related_locations", options_from_collection_for_select(@locations, :id, :name), prompt: "Select location" , class: 'form-control'-%>
</div>
<div class="form-group">
<%= f.fields_for :locations do |ff| %>
<%= ff.check_box :name %>
<%= ff.label :name, ff.object.name %>
<% end %>
</div>
</div>
</div>
</div>
<%= render '/refinery/admin/form_actions', :f => f,
:continue_editing => false,
:delete_title => t('delete', :scope => 'refinery.events.admin.events.event'),
:delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @event.title) -%>
<% end -%>
</div>
<% content_for :javascripts do -%>
<script>
$(document).ready(function(){
page_options.init(false, '', '');
});
$(function(){
window.fields = {
addressInput : $('#event_street_address'),
countryInput : $('#event_country'),
stateInput : $('#event_state_id'),
cityInput : $('#event_city_id'),
zipInput : $('#event_zip'),
mapPreview : $('#event_mappreview'),
addressField : $('#event_directionslink')
};
$.each(fields, function(index, item) {
item.on('change', previewMapManager.setMapPreview);
});
window.setNativeLocation= function (isNative){
if(isNative == 't'){
$('#custom-location').hide();
$('#native-location').show();
} else {
$('#native-location').hide();
$('#custom-location').show();
}
$('#event_is_native_location').val(isNative);
}
setNativeLocation($('#event_is_native_location').val());
});
</script>
<% end -%>
module Refinery
module Locations
class Location < Refinery::Core::BaseModel
self.table_name = 'refinery_locations'
validates :name, :presence => true, :uniqueness => true
belongs_to :picture, :class_name => '::Refinery::Image'
belongs_to :state
belongs_to :city
has_and_belongs_to_many :events,
:join_table => :refinery_locations_refinery_locations_events,
:foreign_key => "refinery_location_id",
:association_foreign_key => "refinery_locations_event_id",
:class_name => "Refinery::Locations::Event"
# To enable admin searching, add acts_as_indexed on searchable fields, for example:
#
# acts_as_indexed :fields => [:title]
end
end
end
create_table "refinery_locations", force: true do |t|
t.string "name"
t.integer "position"
t.datetime "created_at"
t.datetime "updated_at"
t.text "description"
t.integer "picture_id"
t.string "country"
t.string "address"
t.string "zip"
t.string "hours"
t.string "telephone"
t.string "fax"
t.string "email"
t.string "directionslink"
t.text "about"
t.integer "state_id"
t.integer "city_id"
end
create_table "refinery_locations_events", force: true do |t|
t.string "title"
t.text "description"
t.time "time_start"
t.time "time_end"
t.date "date"
t.integer "poster_id"
t.date "posting_date"
t.integer "event_category_id"
t.integer "position"
t.datetime "created_at"
t.datetime "updated_at"
t.string "location_name"
t.string "street_address"
t.string "country"
t.integer "state_id"
t.integer "city_id"
t.string "zip"
t.string "telephone"
t.string "fax"
t.string "email"
t.integer "location_id"
t.string "directionslink"
t.boolean "is_native_location"
t.text "short_description"
end
create_table "refinery_locations_refinery_locations_events", id: false, force: true do |t|
t.integer "refinery_location_id", null: false
t.integer "refinery_locations_event_id", null: false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment