fix error

This commit is contained in:
chiu 2020-08-16 14:38:09 +08:00
parent 12e68a6b3b
commit 53ab1b77bd
5 changed files with 69 additions and 13 deletions

View File

@ -60,7 +60,7 @@ class Admin::CalendarsController < OrbitAdminController
# GET /events/new
# GET /events/new.json
def new
@event = Event.new
@event = Event.new(start: params[:startDate],end: params[:endDate])
categories = user_authenticated_categories rescue []
if categories.first == "all"
@categories = CalendarType.all
@ -130,13 +130,13 @@ class Admin::CalendarsController < OrbitAdminController
# PUT /events/1.json
def update
@event = Event.find(params[:id])
p = event_page_params
p["update_user_id"] = current_user.id
p1 = event_page_params
p1["update_user_id"] = current_user.id
bulletin = @event.bulletin
if !bulletin.nil?
bulletin.update_attributes(calendar_start_date: p[:start],calendar_end_date: p[:end],calendar_all_day: p[:all_day],calendar_type_id: p[:calendar_type_id])
bulletin.update_attributes(calendar_start_date: p1[:start],calendar_end_date: p1[:end],calendar_all_day: p1[:all_day],calendar_type_id: p1[:calendar_type_id])
end
if @event.update_attributes!(p)
if @event.update_attributes(p1)
e = @event.to_json
e = JSON.parse(e)
e["can_edit"] = true

View File

@ -44,6 +44,7 @@ class Event
if !m.nil?
if self.key.nil?
m.event_id = nil
m.add_to_calendar = false
else
m.calendar_dict.delete(self.key)
if !m['calendar_data'].nil?
@ -56,11 +57,15 @@ class Event
end
end
end
before_save do
self['title_translations'] = self['title_translations'].merge({I18n.locale.to_s =>self['title']})
self['note_translations'] = self['title_translations'].merge({I18n.locale.to_s =>self['note']})
end
########################################
validates_presence_of :title, :message => "Please fill the title of the Event", :if => lambda { self['title_translations'].blank? }
validates_presence_of :title_translations, :message => "Please fill the title of the Event", :if => lambda { self['title'].blank? }
def title
tp = self['title_translations'][I18n.locale]
tp = self['title_translations'][I18n.locale] rescue nil
tp.blank? ? self['title'] : tp
end
def note
@ -76,7 +81,7 @@ class Event
end
end
def bulletin
Bulletin.find(self.bulletin_id) rescue nil
model_class=='Bulletin' ? (Bulletin.find(self.model_id) rescue nil) : nil
end
def self.format_date(date_time)
Time.at(date_time.to_i).to_formatted_s(:db)

View File

@ -1,3 +1,4 @@
<%= javascript_include_tag 'jquery.base64' %>
<style type="text/css">
.controls[data-toggle^="buttons-"] input[type="checkbox"] {
margin-left: 0;
@ -13,6 +14,32 @@
.controls[data-toggle^="buttons-"] .checkbox.inline.btn{
position: relative;
}
div[contentEditable=true]:empty:before{
content: attr(data-ph);
color: grey;
padding-left: 3%;
font-weight: bold;
font-family: serif;
}
div[contentEditable=true] {
background: white;
color: black;
border: 0.1em solid #cccccc;
font-size: 1.15em;
padding: 0.3em 0 0.3em 3%;
border-radius: 0.3em;
display: block;
width: 100%;
outline: 0;
}
div[contentEditable=true]:focus {
border-color: rgba(82, 168, 236, 0.8);
outline: 0;
outline: thin dotted \9;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
}
</style>
<% if @event.errors.any? %>
<div id="error_explanation">
@ -27,13 +54,15 @@
<div class="control-group">
<%= f.label t("title"), :class=>"control-label" %>
<div class="controls">
<%= f.text_field :title %>
<div data-ph="<%= t('calendar.press_enter') %>" contenteditable="true" class="calendar-comment"><%= @event.title.to_s.html_safe %></div>
<%= f.hidden_field :title %>
</div>
</div>
<div class="control-group">
<%= f.label t("calendar.note"), :class=>"control-label" %>
<div class="controls">
<%= f.text_area :note, :rows => 3 %>
<div data-ph="<%= t('calendar.press_enter') %>" contenteditable="true" class="calendar-comment"><%= @event.note.to_s.html_safe %></div>
<%= f.hidden_field :note %>
</div>
</div>
<div class="control-group">
@ -55,14 +84,14 @@
<%= f.label t("start_date"), :class=>"control-label" %>
<%#= f.datetime_select :start %>
<div class="controls">
<%= f.datetime_picker :start, :class => "input-large", data: {"fv-validation" => "required;","fv-messages" => "Cannot be empty;"}, :placeholder => data_format, :new_record => @event.new_record?, :format => data_format %>
<%= f.datetime_picker :start, :class => "input-large", data: {"fv-validation" => "required;","fv-messages" => "Cannot be empty;"}, :placeholder => data_format, :new_record => false, :format => data_format %>
</div>
</div>
<div class="control-group">
<%= f.label t("end_date"), :class=>"control-label" %>
<%#= f.datetime_select :end %>
<div class="controls">
<%= f.datetime_picker :end, :class => "input-large", :placeholder => data_format, :new_record => @event.new_record?, :format=> data_format %>
<%= f.datetime_picker :end, :class => "input-large", :placeholder => data_format, :new_record => false, :format=> data_format %>
</div>
</div>
<div class="control-group">
@ -103,14 +132,34 @@
<div class="control-group last">
<div class="controls">
<% if action_name == "edit" %>
<%= f.submit t("calendar.save"), :class=>"btn btn-primary" %>
<%= f.button t("calendar.save"),:type=> 'button', :class=>"btn btn-primary", :onclick => 'before_submit(this)' %>
<% else %>
<%= f.submit t(:create_), :class=>"btn btn-primary" %>
<%= f.button t(:create_),:type=> 'button', :class=>"btn btn-primary", :onclick => 'before_submit(this)' %>
<% end %>
<a href="" class="btn btn-close">Cancel</a>
</div>
</div>
<script type="text/javascript">
function getFormData($form){
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function(n, i){
indexed_array[n['name']] = n['value'];
});
return indexed_array;
}
function before_submit(ele){
var self = $(ele).parents('form')
var length = self.find('*[contenteditable="true"]').length
for (var i=0;i<length;i++){
var tp1 = self.find('*[contenteditable="true"]').eq(i)
var tp2 = tp1.parents('.controls').eq(0).find('input[type="hidden"]')
tp2.val(tp1.html())
}
self.submit()
}
$('body').ready(function(){
if ($('.default_picker,.time_picker,.date_picker').find('input').length!=0){
$('.default_picker,.time_picker,.date_picker').find('.iconbtn').css('display','none')

View File

@ -1,5 +1,6 @@
en:
calendar:
press_enter: Press enter to add a newline
all: All
calendar: Calendar
calendars: Calendars

View File

@ -1,5 +1,6 @@
zh_tw:
calendar:
press_enter: 按下enter可以換行
calendar: 行事曆
calendars: 我的行事曆
color: 顏色