fixed authorizations and also can edit calendar names

This commit is contained in:
Harry Bomrah 2014-12-17 17:08:50 +08:00
parent e3aefb4879
commit 8f869c8e4d
8 changed files with 63 additions and 22 deletions

View File

@ -360,7 +360,10 @@ var EventDialog = function(calendar,event){
time_string = (start_time === end_time ? start_time + " " + stime + " - " + etime : start_time + " " + stime + " - " + end_time + " " +etime ); time_string = (start_time === end_time ? start_time + " " + stime + " - " + etime : start_time + " " + stime + " - " + end_time + " " +etime );
} }
event_quick_view = $('<div class="modal" style="width: 300px; display:none; margin:0 0 0 0;"></div>'); event_quick_view = $('<div class="modal" style="width: 300px; display:none; margin:0 0 0 0;"></div>');
template = '<div class="modal-header"><button type="button" class="close event-close-btn" data-dismiss="modal" aria-hidden="true">&times;</button><h3>'+ _event.title +'</h3></div><div class="modal-body"><div class="event_summary">'+ time_string +'</div>'+ _event.note +'</div><div class="modal-footer"><a href="'+ _event.delete_url +'" class="delete btn btn-primary">Delete</a><a href="'+ _event.edit_url +'" class="edit btn btn-primary" >Edit</a></div>'; template = '<div class="modal-header"><button type="button" class="close event-close-btn" data-dismiss="modal" aria-hidden="true">&times;</button><h3>'+ _event.title +'</h3></div><div class="modal-body"><div class="event_summary">'+ time_string +'</div>'+ _event.note +'</div>';
if(_event.can_edit){
template+='<div class="modal-footer"><a href="'+ _event.delete_url +'" class="delete btn btn-primary">Delete</a><a href="'+ _event.edit_url +'" class="edit btn btn-primary" >Edit</a></div>';
}
} }
this.show = function(pos){ this.show = function(pos){

View File

@ -0,0 +1,25 @@
$(function() {
$.pageslide.closeCallback(function(pageslide, item) {
$('.filter-item').removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
$('.filter-item').removeClass("active");
item.closest('li').addClass('active');
if(item.data('id') == 'new') {
resetForm();
pageslide.find('form').attr('method', 'post');
$("#update_patch").remove();
}
else {
$('.color-picker').miniColors("destroy");
setForm(item.data('form'));
pageslide.find('form').attr("action",item.data("href"));
if($("#update_patch").length == 0){
pageslide.find("form").append("<input type='hidden' id='update_patch' value='patch' name='_method' />");
}
pageslide.find('input[type="checkbox"]').prop( 'checked', item.data('disable') );
$('.color-picker').miniColors();
$('.miniColors-trigger').addClass('btn');
}
});
})

View File

@ -34,6 +34,19 @@ class Admin::CalendarTypesController < OrbitAdminController
redirect_to admin_calendar_types_path redirect_to admin_calendar_types_path
end end
def update
calendar = CalendarType.find(params[:id]) rescue nil
if !calendar.nil?
calendar.update_attributes(calendar_type_params)
calendar.save
category = calendar.category
category.title_translations = calendar_type_params["title_translations"]
category.save
end
redirect_to admin_calendar_types_path
end
def list def list
@module_app_id = @module_app.id rescue nil @module_app_id = @module_app.id rescue nil

View File

@ -3,17 +3,23 @@ class Admin::CalendarsController < OrbitAdminController
# GET /events.json # GET /events.json
def index def index
@events = []
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)
@re = Event.recurring_event(sdt,edt) @re = Event.recurring_event(sdt,edt)
events = @monthly_events.inject(@re, :<<) allevents = @monthly_events.inject(@re, :<<)
events = allevents.to_json
events = JSON.parse(events)
events.each_with_index do |e,i|
e["can_edit"] = can_edit_or_delete_event?(allevents[i])
@events << e
end
end end
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.json { render json: events.to_json } format.json { render json: @events.to_json }
end end
end end
@ -88,7 +94,10 @@ class Admin::CalendarsController < OrbitAdminController
# POST /events # POST /events
# POST /events.json # POST /events.json
def create def create
@event = Event.new(event_page_params) p = event_page_params
p["create_user_id"] = current_user.id
p["update_user_id"] = current_user.id
@event = Event.new(p)
if @event.present? && @event.save if @event.present? && @event.save
render json: @event.to_json render json: @event.to_json
@ -104,7 +113,9 @@ class Admin::CalendarsController < OrbitAdminController
# PUT /events/1.json # PUT /events/1.json
def update def update
@event = Event.find(params[:id]) @event = Event.find(params[:id])
if @event.update_attributes(event_page_params) p = event_page_params
p["update_user_id"] = current_user.id
if @event.update_attributes(p)
render json: @event.to_json render json: @event.to_json
else else
respond_to do |format| respond_to do |format|

View File

@ -15,6 +15,8 @@ class Event
field :recurring, type: Boolean field :recurring, type: Boolean
field :frequency field :frequency
field :period field :period
field :create_user_id
field :update_user_id
belongs_to :calendar_type belongs_to :calendar_type
attr_accessor :agenda_start, :agenda_end, :get_agenda_events attr_accessor :agenda_start, :agenda_end, :get_agenda_events

View File

@ -4,7 +4,7 @@
<div class="quick-edit"> <div class="quick-edit">
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<% if is_admin?%> <% if is_admin?%>
<li><%= link_to t(:edit), '#', class: "open-slide", data: {title: t(:edit_category), id: calendar_type.id.to_s, form: calendar_type.title_translations.merge(color: calendar_type.color)} %></li> <li><%= link_to t(:edit),"#", class: "open-slide", onclick: "return false;", data: {title: t(:edit_category), id: calendar_type.id.to_s, form: calendar_type.title_translations.merge(color: calendar_type.color), href: admin_calendar_type_path(calendar_type)} %></li>
<% end %> <% end %>
</ul> </ul>
</div> </div>

View File

@ -1,6 +1,7 @@
<%= stylesheet_link_tag "jquery.miniColors" %> <%= stylesheet_link_tag "jquery.miniColors" %>
<%= javascript_include_tag "jquery.miniColors.min" %> <%= javascript_include_tag "jquery.miniColors.min" %>
<%= javascript_include_tag "category_type" %>
<div id="categories_index"> <div id="categories_index">
<table class="table main-list"> <table class="table main-list">

View File

@ -1,15 +1 @@
$("#event_create").empty().hide(); $.pageslide.close();
$("#create_event_btn").removeClass("active");
$(".destroy").remove();
$("#create_event_btn").show();
switch (c.view){
case "week":
c.loadWeekView(c.cur_week,c.cur_year);
break;
case "month":
c.loadMonthView(c.cur_month,c.cur_year);
break;
case "day":
c.loadDayView(c.cur_date,c.cur_month,c.cur_year);
break;
}