Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update issue #41

Closed
BigG opened this issue Jan 25, 2016 · 10 comments
Closed

Update issue #41

BigG opened this issue Jan 25, 2016 · 10 comments

Comments

@BigG
Copy link

BigG commented Jan 25, 2016

Hi there,

there is something strange that happen when I try to refresh the list of events.
So my situation is this one:

  • user explore the calendar and let's say an event is showed into listview
  • now the user come back to another view and add some events
  • users can now check if the event just created is the calendar view

How can I trigger the refresh of the listview?
$("#calendar").trigger("refresh"); seems not working as well as $("#calendar").trigger('refresh', date); where date is today.

Can you help me, please?

Thanks!

@BigG BigG closed this as completed Jan 25, 2016
@BigG BigG reopened this Jan 25, 2016
@jwgmeligmeyling
Copy link
Owner

I think you end up having two calendar instances and updating the wrong one. Please provide a JSfiddle or something so we can see the problem in the context of your application.

@BigG
Copy link
Author

BigG commented Jan 25, 2016

Hey, thank you for your quick answer.
In short this is the action related to the click on "Check Calendar View". All the event come out from a db.

$('#checkCalendarView').on('click', function (e) {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var arr = [];

    database.transaction(function(tx) {
             tx.executeSql('SELECT * FROM eventLog', [], function(tx, results) {
                var len = results.rows.length;
                for (var i = 0; i < len; i++) {
                var begin = createDate(results.rows.item(i).data+ " " +results.rows.item(i).hour);

                     arr.push({
                        "summary": results.rows.item(i).type,
                        "begin": begin,
                        "end": begin
                    });

                }



                 $("#calendar").jqmCalendar({
                    events : arr,
                    months: ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
                    days: ["Do","Lu", "Ma", "Me", "Gi", "Ve", "Sa"],
                    startOfWeek: 1
                }, []);



        }, function(err) {
                console.log('ERROR Events: ' + JSON.stringify(err));
            });
                });

        });

In addition I checked this on your .js

$.fn.jqmCalendar = function(options) {
      return this.each(function() {
         if (!$(this).data('jqmCalendar')) {
             $(this).data('jqmCalendar', new $.jqmCalendar(this, options));
         }

      });

And if I create a new istance the old one is of course showed and the new one is correctly populated.

Where I am doing wrong?

Thanks!

@jwgmeligmeyling
Copy link
Owner

Currently, a new events array can't be passed as options parameter for the update call. That should have been implemented but we never got to it. Have a look at this comment to see how to work around: #12 (comment)

@jwgmeligmeyling
Copy link
Owner

You can't do this this way.

You should have something like this:

var arr = [];

$('#view').on('pageinit', function() {
             $("#calendar").jqmCalendar({
                events : arr,
                months: ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
                days: ["Do","Lu", "Ma", "Me", "Gi", "Ve", "Sa"],
                startOfWeek: 1
            });
});

$('#checkCalendarView').on('click', function (e) {
database.transaction(function(tx) {
         tx.executeSql('SELECT * FROM eventLog', [], function(tx, results) {
            var len = results.rows.length;
            for (var i = 0; i < len; i++) {
            var begin = createDate(results.rows.item(i).data+ " " +results.rows.item(i).hour);

                 arr.push({
                    "summary": results.rows.item(i).type,
                    "begin": begin,
                    "end": begin
                });

            }



             $("#calendar").trigger('update');
    })
})

@BigG
Copy link
Author

BigG commented Jan 25, 2016

Ahhh I see the point. Nice solution!
Have you any idea how to manage doubled entry?

@jwgmeligmeyling
Copy link
Owner

Clear the array first. http://stackoverflow.com/a/1232046/2104280

@BigG
Copy link
Author

BigG commented Jan 25, 2016

Peerfeect!!
Sometimes I forget the basics... ;)

Btw great plugin, really!

@jwgmeligmeyling
Copy link
Owner

Life would have been so much easier if they just added a clear() function to the array 😉 Glad you like it and the plugin is still being used! (It's from 2013 😊 )

@BigG
Copy link
Author

BigG commented Jan 28, 2016

Hi there, all works as expected but there is a strange behaviour when users change day in calendar view. So basically even if events are already there (and the dot is showed just under the number) if a tap on the previous day and then I tap again on the fully populated day, no event is showed. It is seems like all is cleaned up. Do you think I need to listen to every change? I mean if my array is already populated do I need to repopulate again at every change?

Let me know..
BigG

@jwgmeligmeyling
Copy link
Owner

jwgmeligmeyling commented Jan 28, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants