add category and tag filter
This commit is contained in:
parent
3b6d3480ed
commit
d47b14d2e1
|
@ -154,7 +154,7 @@ var Calendar = function(dom){
|
||||||
c.calendar.fullCalendar({
|
c.calendar.fullCalendar({
|
||||||
editable: true,
|
editable: true,
|
||||||
selectable: true,
|
selectable: true,
|
||||||
events: "/admin/calendars/",
|
events: window.location.href,
|
||||||
eventResize: change_event,
|
eventResize: change_event,
|
||||||
eventDrop: change_event ,
|
eventDrop: change_event ,
|
||||||
header: false,
|
header: false,
|
||||||
|
|
|
@ -4,11 +4,18 @@ class Admin::CalendarsController < OrbitAdminController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@events = []
|
@events = []
|
||||||
|
tags = @module_app.tags
|
||||||
|
categories = @module_app.categories
|
||||||
|
@filter_fields = {
|
||||||
|
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}},
|
||||||
|
:tags=>tags.map{|tag| {:title=>(tag.name.blank? ? " " : tag.name), :id=>tag.id}}
|
||||||
|
}
|
||||||
if params[:start].present? && params[:end].present?
|
if params[:start].present? && params[:end].present?
|
||||||
sdt = Time.at(params[:start].to_i)
|
sdt = Time.at(params[:start].to_i)
|
||||||
edt = Time.at(params[:end].to_i)
|
edt = Time.at(params[:end].to_i)
|
||||||
@monthly_events = Event.monthly_event(sdt,edt)
|
@monthly_events = Event.monthly_event(sdt,edt).with_categories(filters("category"))
|
||||||
@re = Event.recurring_event(sdt,edt)
|
.with_tags(filters("tag"))
|
||||||
|
@re = Event.with_categories(filters("category")).with_tags(filters("tag")).recurring_event(sdt,edt)
|
||||||
allevents = @monthly_events.inject(@re, :<<)
|
allevents = @monthly_events.inject(@re, :<<)
|
||||||
events = allevents.to_json
|
events = allevents.to_json
|
||||||
events = JSON.parse(events)
|
events = JSON.parse(events)
|
||||||
|
@ -17,10 +24,17 @@ class Admin::CalendarsController < OrbitAdminController
|
||||||
@events << e
|
@events << e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if request.xhr?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html { render :partial => "index" }
|
||||||
format.json { render json: @events.to_json }
|
format.json { render json: @events.to_json }
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render "index" }
|
||||||
|
format.json { render json: @events.to_json }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /events/1
|
# GET /events/1
|
||||||
|
|
|
@ -23,6 +23,14 @@ class Event
|
||||||
|
|
||||||
|
|
||||||
validates_presence_of :title, :message => "Please fill the title of the Event"
|
validates_presence_of :title, :message => "Please fill the title of the Event"
|
||||||
|
def self.with_categories(cat_ids=[])
|
||||||
|
if cat_ids.blank?
|
||||||
|
self.all
|
||||||
|
else
|
||||||
|
type_ids = CalendarType.where(:category_id.in=>cat_ids).pluck(:id)
|
||||||
|
self.where(:calendar_type_id.in => type_ids)
|
||||||
|
end
|
||||||
|
end
|
||||||
def bulletin
|
def bulletin
|
||||||
Bulletin.find(self.bulletin_id) rescue nil
|
Bulletin.find(self.bulletin_id) rescue nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,16 @@
|
||||||
|
<style type="text/css">
|
||||||
|
.controls[data-toggle^="buttons-"] input[type="checkbox"] {
|
||||||
|
margin-left: 0;
|
||||||
|
margin-top: 0;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<% if @event.errors.any? %>
|
<% if @event.errors.any? %>
|
||||||
<div id="error_explanation">
|
<div id="error_explanation">
|
||||||
<h2><%= pluralize(@event.errors.count, "error") %> prohibited this event from being saved:</h2>
|
<h2><%= pluralize(@event.errors.count, "error") %> prohibited this event from being saved:</h2>
|
||||||
|
@ -65,6 +78,12 @@
|
||||||
<%= f.select :calendar_type_id, @categories.collect{|t| [ t.title, t.id ]} %>
|
<%= f.select :calendar_type_id, @categories.collect{|t| [ t.title, t.id ]} %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Tag Module -->
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label"><%= t(:tags) %></label>
|
||||||
|
<%= select_tags(f, @module_app) %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label"></label>
|
<label class="control-label"></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<div id="calendar"></div>
|
||||||
|
<div id="calendar_agenda"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var calendar
|
||||||
|
$(document).ready(function(){
|
||||||
|
calendar = new Calendar("#calendar");
|
||||||
|
})
|
||||||
|
</script>
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
<%= stylesheet_link_tag "fullcalendar"%>
|
<%= stylesheet_link_tag "fullcalendar"%>
|
||||||
<%= stylesheet_link_tag "calendar"%>
|
<%= stylesheet_link_tag "calendar"%>
|
||||||
|
<%= render_filter @filter_fields, "orbit_calendar" %>
|
||||||
<div id="orbit_calendar" class="month_view">
|
<div id="orbit_calendar" class="month_view">
|
||||||
<div class="clearfix cal-fn">
|
<div class="clearfix cal-fn">
|
||||||
<div id='sec2'>
|
<div id='sec2'>
|
||||||
|
@ -46,8 +47,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="view_holder">
|
<div id="view_holder">
|
||||||
<div id="calendar"></div>
|
<%= render partial: 'index' %>
|
||||||
<div id="calendar_agenda"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="event_create_space"></div>
|
<div id="event_create_space"></div>
|
||||||
|
@ -55,7 +55,3 @@
|
||||||
<div class="calendar-form-actions form-actions text-right">
|
<div class="calendar-form-actions form-actions text-right">
|
||||||
<%= link_to "Add", new_admin_calendar_path, :class => "btn btn-primary", :id=>"create_event_btn", :ref=>"add-btn" %>
|
<%= link_to "Add", new_admin_calendar_path, :class => "btn btn-primary", :id=>"create_event_btn", :ref=>"add-btn" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
var calendar = new Calendar("#calendar");
|
|
||||||
</script>
|
|
Loading…
Reference in New Issue