fix style error and let other model can connect to event

This commit is contained in:
chiu 2020-08-07 21:53:55 +08:00
parent aa6df3a1bd
commit 3ac2655d72
2 changed files with 46 additions and 9 deletions

View File

@ -58,12 +58,16 @@ var Calendar = function(dom){
}else{ }else{
c.event_create_space.css("top",top_pos + "px"); 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"); c.event_create_space.css("top",c.mousePosition["y"] + "px");
} }
if((create_space_width + c.mousePosition["x"]) >= $(window).width()){ 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{ }else{
c.event_create_space.css("left",c.mousePosition["x"] + "px"); c.event_create_space.css("left",c.mousePosition["x"] + "px");
} }
@ -388,14 +392,14 @@ var EventDialog = function(calendar,event){
} }
this.show = function(pos){ 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.html(template).appendTo("body").show();
event_quick_view.find(".event-close-btn").one("click",function(){_t.dismiss();}); 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.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;}); 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(){ this.dismiss = function(){

View File

@ -9,6 +9,8 @@ class Event
field :title field :title
field :note field :note
field :title_translations,type: Hash,default: {}
field :note_translations,type: Hash,default: {}
field :start, type: DateTime field :start, type: DateTime
field :end, type: DateTime field :end, type: DateTime
field :all_day, type: Boolean,default: false field :all_day, type: Boolean,default: false
@ -20,9 +22,40 @@ class Event
field :bulletin_id field :bulletin_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
#let other model can connect to this model
validates_presence_of :title, :message => "Please fill the title of the Event" 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=[]) def self.with_categories(cat_ids=[])
if cat_ids.blank? if cat_ids.blank?
self.all self.all