Serhioromano / bootstrap-calendar

Full view calendar with year, month, week and day views based on templates with Twitter Bootstrap.
http://bootstrap-calendar.eivissapp.com/
MIT License
3.02k stars 1.29k forks source link

Need flexibility in ways in which events can be added to the calender #51

Closed jaseemabid closed 11 years ago

jaseemabid commented 11 years ago
  1. Ajax call should be optional Loading events from a local variable might be a better option in certain scenarios.
  2. Need a parse function before ajax to tweak the parameters for this particular plugin. Refer: http://backbonejs.org/#Collection-parse
Serhioromano commented 11 years ago
  1. Tell me more.
jaseemabid commented 11 years ago

@Serhioromano I should be able to just give it an array of events from a local variable than make a ajax call. What if i already have the events on the page?

Serhioromano commented 11 years ago

This is 1. I asked about 2.

jaseemabid commented 11 years ago

There should be no reason to tweak an existing API server just to make it work with this plugin. If your plugin needs a property called title, and if the server provides eventTitle, there should be a parse function to tweak the response object, fix the structure and names etc. Refer backbone doc for more info.

Serhioromano commented 11 years ago

May be you try to make a code example?

Refer backbone doc for more info.

We do not use backbone.

jaseemabid commented 11 years ago

You don't have to use backbone, they documented the need for a parse function properly. Say the plugin needs a title and server gives eventTitle in the array of events, you need a function like this

function(response) {
    response.forEach(function(event) {
        event.title = event.eventTitle;
        delete event.eventTitle;
    });

    return response;
}

If plugin needs a array of events and the server is sending it in another top level json like this,

{
    events: [the array you want]
}

you can deal that with a parse function like this

function(response) {
    return response.events;
}
Serhioromano commented 11 years ago

We have onAfterEventsLoad callback.

var calendar = $('#calendar').calendar({
    onAfterEventsLoad: function(events) {
        $.each(events, function(key, val) {
            val.title = val.eventTitle;
            delete val.eventTitle;
        }
    }
});
Ashwin2488 commented 11 years ago

@Serhioromano Hi any update on loading events from a local variable...??

Serhioromano commented 11 years ago

@Ashwin2488 no :)

mlocati commented 11 years ago

I'm going to implement this

mlocati commented 11 years ago

Here it is: https://github.com/Serhioromano/bootstrap-calendar/pull/111

mlocati commented 11 years ago

Now Bootstrap Calendar accepts the events_source option: it can be an URL (same as previous events_url option), or it can be a function. That function can do what you want, including events taken from a local variable.