Jquery FullCalendar - 根据ruby应用程序中的even_type更改事件颜色 [英] Jquery FullCalendar- Change event color according to even_type in ruby app

查看:111
本文介绍了Jquery FullCalendar - 根据ruby应用程序中的even_type更改事件颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Ruby应用程序中使用中的Jquery完整日历。我想为4种不同类型的事件显示不同的颜色,例如(假期,学校,工作,娱乐),这些事件保存在我的事件表中作为type_of_event

I'm using Jquery full calendar from http://arshaw.com/fullcalendar in my ruby apps. I wanna show different color for 4 different kind of events like (Holidays, School, Work, Fun) which were saved in my events table as type_of_event

现在我使用以下代码仅使用start_at和end_at获取事件:

Right now I'm fetching events only with start_at and end_at using below code:

scope :before, lambda {|end_time| {:conditions => ["ends_at < ?", Event.format_date(end_time)] }}
  scope :after, lambda {|start_time| {:conditions => ["starts_at > ?", Event.format_date(start_time)] }}


  # need to override the json view to return what full_calendar is expecting.
  # http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
  def as_json(options = {})
    {
      :id => self.id,
      :title => self.title,
      :description => self.description || "",
      :start => starts_at.rfc822,
      :end => ends_at.rfc822,
      :allDay => self.all_day,
      :recurring => false,
      :url => Rails.application.routes.url_helpers.event_path(id),
      #:color => "red"
    }

  end

  def self.format_date(date_time)
    Time.at(date_time.to_i).to_formatted_s(:db)
  end

是否有任何特定方式显示事件颜色根据它们的event_type意味着事件类型是学校,它会显示我的红色

Is there any specific way to show events color according to their event_type means if event type is school it will show me red color

推荐答案

你打算在模型外的其他地方使用这些颜色吗?

Are you going to use these colors somewhere else outside of your model?

大多数情况下,您不需要将其设置为全局可用,因此只需在模型中添加一个常量即可:

Most likely, you need not to make it globally available, so just add a constant to the model:

scope :before, ...
scope :after, ...

EVENT_COLORS = { "School" => "#ff0000", "Holidays" => "#00ff00", ... }
EVENT_COLORS.default = "#0000ff" #optional step, set default color for events

...
:url => Rails.application.routes.url_helpers.event_path(id),
:color => EVENT_COLORS[self.event_type]

这篇关于Jquery FullCalendar - 根据ruby应用程序中的even_type更改事件颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆