From 3ac2655d72c933ee660af52c8771bfb42e36ab48 Mon Sep 17 00:00:00 2001 From: chiu Date: Fri, 7 Aug 2020 21:53:55 +0800 Subject: [PATCH] fix style error and let other model can connect to event --- app/assets/javascripts/calendar.js | 16 +++++++----- app/models/event.rb | 39 +++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/calendar.js b/app/assets/javascripts/calendar.js index 7e5314f..41ac24c 100644 --- a/app/assets/javascripts/calendar.js +++ b/app/assets/javascripts/calendar.js @@ -58,12 +58,16 @@ var Calendar = function(dom){ }else{ c.event_create_space.css("top",top_pos + "px"); } - }else{ + }else if(c.mousePosition["y"]+c.event_create_space.height()<$(window).height()){ c.event_create_space.css("top",c.mousePosition["y"] + "px"); } if((create_space_width + c.mousePosition["x"]) >= $(window).width()){ - c.event_create_space.css("left",(c.mousePosition["x"] - create_space_width) + "px"); + if (c.mousePosition["x"] - create_space_width < 0){ + c.event_create_space.css("left",'0px') + }else{ + c.event_create_space.css("left",(c.mousePosition["x"] - create_space_width) + "px"); + } }else{ c.event_create_space.css("left",c.mousePosition["x"] + "px"); } @@ -388,14 +392,14 @@ var EventDialog = function(calendar,event){ } this.show = function(pos){ - if(pos){ - var pos = getPosition(pos); - event_quick_view.css({"left":pos.x+"px","top":pos.y+"px"}); - } event_quick_view.html(template).appendTo("body").show(); event_quick_view.find(".event-close-btn").one("click",function(){_t.dismiss();}); event_quick_view.find("a.delete").one("click",function(){calendar.deleteEvent(_this_event.delete_url,_this_event._id);return false;}); event_quick_view.find("a.edit").one("click",function(){calendar.editEvent(_this_event.edit_url,_this_event.allDay);return false;}); + if(pos){ + var pos = getPosition(pos); + event_quick_view.css({"left":pos.x+"px","top":pos.y+"px"}); + } } this.dismiss = function(){ diff --git a/app/models/event.rb b/app/models/event.rb index 15f2689..22947e4 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -9,6 +9,8 @@ class Event field :title field :note + field :title_translations,type: Hash,default: {} + field :note_translations,type: Hash,default: {} field :start, type: DateTime field :end, type: DateTime field :all_day, type: Boolean,default: false @@ -20,9 +22,40 @@ class Event field :bulletin_id belongs_to :calendar_type attr_accessor :agenda_start, :agenda_end, :get_agenda_events - - - validates_presence_of :title, :message => "Please fill the title of the Event" + + #let other model can connect to this model + field :key + field :model_class + field :model_id + before_destroy do + if !self.model_class.blank? + m = eval(self.model_class).where(id: self.model_id).first rescue nil + if !m.nil? + if self.key.nil? + m.event_id = nil + else + m.calendar_dict.delete(self.key) + if !m['calendar_data'].nil? + tmp = m['calendar_data'] + tmp['key'] = Array(tmp['key']) - [self.key] + m['calendar_data'] = tmp + end + end + m.save + end + end + end + ######################################## + validates_presence_of :title, :message => "Please fill the title of the Event", :unless => lambda { self.title_translations.blank? } + validates_presence_of :title_translations, :message => "Please fill the title of the Event", :unless => lambda { self.title.blank? } + def title + tp = self['title_translations'][I18n.locale] + tp.blank? ? self['title'] : tp + end + def note + tp = self['note_translations'][I18n.locale] + tp.blank? ? self['note'] : tp + end def self.with_categories(cat_ids=[]) if cat_ids.blank? self.all