Closed jmsherry closed 9 years ago
On your on-event-times-changed
expression pass in a function which checks if calendarNewEventStart
or calendarNewEventEnd
is in the past and shows a modal or something similar alerting the user that the event is in the past (and then don't change the event times)
Yes, I did that, but it leaves the dot where the user left it, so the UI is then in an incorrect state. I even took note of the pre-drag position and after the check tried to revert it but the drag puts it back in the wrong place.
Oh that might be a bug then, it should snap back to where it was originally whether you change the dates or not.
Best I've come up with at the moment is blocking the server-side save and then reloading the view in UI-Router (or you could do it with $window.location.reload()) - but that's a temporary fix, obviously.
I can't seem to replicate the issue you're having, can you reproduce it in a plunker or something similar?
Hey Matt, Do you want to close the issue whilst I rig up a plunkr and we can have a look (only because it might take me a few days atm)?? If it is an issue you can always re-open it...
Sure, no problem :smile:
Matt, I've just cloned the project demo and I can move things into the past and they don't get put back...?? Just before I go make plunkrs can you confirm whether this happens for you?
Thanks Matt :)
Yeah that's the expected behaviour - you need to implement the business logic yourself as I explained here: https://github.com/mattlewis92/angular-bootstrap-calendar/issues/175#issuecomment-143659639
e.g.
on-event-times-changed="vm.eventTimesChanged(calendarEvent, calendarNewEventStart, calendarNewEventEnd)"
In your controller:
vm.eventTimesChanged = function(event, newStart, newEnd) {
if (moment(newStart).isAfter(moment())) {
event.startsAt = newStart;
event.endsAt = newEnd;
} else {
//Show modal etc saying the event is in the past
}
}
Hope this helps :smile:
Geezas!! Sorry Matt! I've got my mother visiting - I could just stop there. I may have even less hair than my avatar by the end of this... :D
Yes, you're absolutely right. That's OBVIOUSLY the case. :D SO, I've set up a plunkr:
http://plnkr.co/edit/cpzJUE4MwuT0WoT94Xg7
I'll edit the eventTimesChanged
method appropriately...
//if date is in the past return and error toast.
if (moment(newStartTime).isBefore(now, 'day')) {
toastr.warning('That date is in the past and will be disregarded; Resetting calendar...');
return scheduledMeal;
}
...that was what I had in my code, just to prove I'm not a total numpty!
OK, plunkr is ready.
Sorry about the late reply on this, been a really busy few days. If you look at the expression you're passing to on-event-times-changed
you left in the bit from the demo which changes the calendar dates. So it was:
on-event-times-changed="vm.eventTimesChanged(calendarEvent, calendarNewEventStart); calendarEvent.startsAt = calendarNewEventStart; calendarEvent.endsAt = calendarNewEventEnd"
and it should be
on-event-times-changed="vm.eventTimesChanged(calendarEvent, calendarNewEventStart);"
:smile:
Hi Matt, No need to apologise - I'm very grateful you've taken the time - very kind of you. :)
That seems to have fixed it, which is great news.
I wondered, before I go, if I might ask your opinion on a quick matter?
I've forked the calendar for my own purposes (I can always solidify it later and offer it as a PR, should you wish) to give it a date-picking ability and I'm stumped by a binding issue...
You pass vm.events through the calendar controller and its child controllers using the '=' two way bind. I've matched what you've done with events with another collection (vm.meals, in my case) but it comes up as undefined by the time it reaches the child controller.
Repo is: https://github.com/jmsherry/angular-bootstrap-calendar
I wondered if you could take a quick look? The only thing I can think is that something is executing with the watch statements and a race condition is occurring...
Thanks Matt.
Sorry I couldn't work out quite what you meant, could you highlight whereabouts in the code you're getting the undefined variable.
AH! Got it! I didn't see that the cells were sub directives - I thought it just passed down the scope chain!
Thanks for your help and patience, Matt. :+1:
Hi Matt, I know this isn't a bug, more an enhancement (to be able to specify the option), but it'd be a handy option to be able to put in (although I'm not sure how atm!)
Thanks
James