1

月ビューで日付をクリックすると、ビューが日ビューに変わります。新しいイベントのリンクをクリックしたときに、開始日をデフォルトの今日の日付ではなく、選択した日付にしたいと考えています。

今日が 2013 年 3 月 12 日で、2013 年 3 月 28 日にイベントを作成したい場合、月ビューで 3 月 28 日の日のセルをクリックします。3 月 28 日の日表示が表示されます。新しいイベントをクリックすると、イベントの開始時刻は 2013 年 3 月 12 日 (現在の日付が表示されていても) になり、手動で 2013 年 3 月 28 日 (または必要な日付) を選択する必要があります。

ハードコードする方法を見つけましたが、これは本番環境では機能しません。選択した日の開始日を動的に渡す方法はありますか?

dayClick コードは次のとおりです。

        dayClick: (date, allDay, jsEvent, view) ->
          if (allDay)
          # clicked entire day
            $('#calendar')
              .fullCalendar('changeView', 'agendaDay')
              .fullCalendar('gotoDate', date.getFullYear(), date.getMonth(), date.getDate())

select メソッドを使用しますか? もしそうならどのように?ドキュメントがわかりませんhttp://arshaw.com/fullcalendar/docs/selection/select_method/ http://arshaw.com/fullcalendar/docs/selection/select_callback/

events.js.coffee で、次の場所に新しいイベント リンクを動的に作成しようとしています。

     $('#new-event').append("<a>custom link built thru js</a>").attr('href', 'events/new?starts_at=2013-03-28') <-- How to set starts_at by obtaining the date from day selected dynamically? Use calendar's select method to obtain the date parameters? 

dayClick から選択された日付のパラメータはどのように渡されますか? それとも、gotoDate からこの情報を取得しますか?

EventsController.rb:

     # GET /events/new
     # GET /events/new.json
     def new
       @event = Event.new
       @event.starts_at = (params[:starts_at]) # sets the date
       respond_to do |format|
         format.html # new.html.erb
         format.json { render :json => @event }
       end
     end

Event.rb モデル:

      def as_json(options = {})
        {
         :id => self.id,
         :title => self.title,
         :description => self.description || "",
         :start => starts_at,
         :end => ends_at,
         :allDay => self.all_day,
         :recurring => false,
         :url => Rails.application.routes.url_helpers.event_path(id),
         :type_of => self.type_of
        }
      end

ビュー/カレンダー/show.html.erb:

    <%= link_to "new event", controller: "events", 
                     action: "new",
                     starts_at: "28-03-2013" %> This will set the starts_at param manually via Rails. How do I obtain this dynamically? Using jQuery see code above in  to create link that has the starts_at parameter (see code above).
4

1 に答える 1

0

これが最善の解決策かどうかはわかりませんが、これを機能させる方法を次に示します。events.js.coffee で:

    $('#calendar').fullCalendar
      dayClick:  (date, allDay, jsEvent, view) ->
        if (allDay)
        # clicked entire day
        $('#calendar')
          .fullCalendar('changeView', 'agendaDay')
          .fullCalendar('gotoDate', date.getFullYear(), date.getMonth(), date.getDate())
          $('#new-event').append("<a>custom link built thru js</a>").attr( 'href', 'events/new?starts_at=' + date )
于 2013-03-13T18:35:04.953 に答える