diff --git a/app/controllers/admin/calendars_controller.rb b/app/controllers/admin/calendars_controller.rb index c41adb3..3792799 100644 --- a/app/controllers/admin/calendars_controller.rb +++ b/app/controllers/admin/calendars_controller.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 7d6d0a5..15d70bd 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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) diff --git a/app/views/admin/calendars/_form.html.erb b/app/views/admin/calendars/_form.html.erb index eb92edb..8c05c6f 100644 --- a/app/views/admin/calendars/_form.html.erb +++ b/app/views/admin/calendars/_form.html.erb @@ -1,3 +1,4 @@ +<%= javascript_include_tag 'jquery.base64' %> <% if @event.errors.any? %>
@@ -27,13 +54,15 @@
<%= f.label t("title"), :class=>"control-label" %>
- <%= f.text_field :title %> +
<%= @event.title.to_s.html_safe %>
+ <%= f.hidden_field :title %>
<%= f.label t("calendar.note"), :class=>"control-label" %>
- <%= f.text_area :note, :rows => 3 %> +
<%= @event.note.to_s.html_safe %>
+ <%= f.hidden_field :note %>
@@ -55,14 +84,14 @@ <%= f.label t("start_date"), :class=>"control-label" %> <%#= f.datetime_select :start %>
- <%= 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 %>
<%= f.label t("end_date"), :class=>"control-label" %> <%#= f.datetime_select :end %>
- <%= 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 %>
@@ -103,14 +132,34 @@
<% 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 %> Cancel