How to keep choice of user view in fullcalendar

1

I have a system that uses fullcalendar , depending on what the user is currently using, he prefers a type of view, month for example , depending on what he is doing prefers another type of visualization, week for example, and this he does by clicking the buttons that fullcalendar creates. What creates a lot of annoyance is that the user has to go through multiple calendars and always have to be clicking on the buttons, is there any way to get that choice he made and leave it as default for the next few times he accesses the system. As soon as it accesses I already left the week option default, so I have something like that today:

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    defaultDate: '2015-12-23',
    defaultView: 'agendaWeek'
});
    
asked by anonymous 23.12.2015 / 13:12

1 answer

2

Friend, you can do this in several ways.

To save user preferences, I advise you to do via ajax, save to the database and load every time the user logs in, but you can also do it with localstorage and save your user preferences in the user's own browser.

How would you look with localstorage:

You can create an object with user preferences, for example:

//Setando preferencias
var prefRef = { 'id':321, 'tipo':'Mensal', 'cor':665533, 'itensPage':15};
localStorage.setItem('preferences', JSON.stringify(prefRef));

//Recuperando preferencias salva
var prefRef = json.parse(localStorage.getItem('preferences'));
alert('O usuario prefere a cor:' prefRef.cor );
    
23.12.2015 / 13:59