Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to create a mini-calendar that is placed on the side my page. The user can switch the months by placing the left/right key. To initialize the mini calendar, I need to give it current day, month, year. The mini-calendar need to run through three for loops:

loop 1: preceding month
loop 2: current month
loop 3: next month

This is to fill the day of the week that are visible from previous and next month. I also want to shade the current day grey and draw a block around the selected day.

So all of this currently works for me with Laravel and the template blade. My controller passes the day, month, year, and inside the template view, I run the three loops and create what I need.

Question 1: Currently, I need to do some logic within my template view (that is to determine how many days in the previous month, and how many days in the next month, and if this day is current/selected day. Is this bad? Should I move everything into the controller, and then pass extra parameters (daysInPreviousMonth and daysInNextMonth) instead to the view?

Question 2: How do I go about having AngularJS use the same template when the user changes the month? I want to be able to use the same set of template code if possible.

share|improve this question
    
Sounds like you're doing double duty. You can just write an AngularJS directive for this and use it anywhere you need a calendar rather than trying to write templates on the server side then trying to use those with the client side framework, might as well just write it in a way that works regardless of the back end. I recommend keeping a clear separation between your server side (ideally setup a RESTful interface) and client side code. –  shaunhusain Mar 23 at 19:09
    
So do you mean the mini calendar to be created with AngularJS then? I should also say that later on, if a user has a specific task assigned to them for that day, the day needs to be bold. This was my initial reasoning for going to the backend to produce the calendar since it needs some data from the database. –  Kousha Mar 23 at 19:12
    
Even if it needs to get that data from the database you're better off writing the calendar component as you say just in AngularJS as a directive, this way it will be re-usable and isn't tied directly to your backend (despite depending on it to get some data, you could do this part in a service then use a controller to get the data from the service into the directive). My reasoning for taking this approach is that the front or back-end should be able to be replaced in case a better technology comes up or native apps are needed. –  shaunhusain Mar 23 at 19:14
    
Okay makes sense thanks! –  Kousha Mar 23 at 19:17
    
No problem. Also if you haven't seen it already check out the angular uiBootstrap project, not to be confused with AngularStrap, which also works but I've used bootstrap angular-ui.github.io/bootstrap it includes a directive for a calendar if you just need something basic, and can use it as an example. Minor addition I also do PHP development and recommend checking out Slim Framework, very easy to set up server side routing for a REST interface. –  shaunhusain Mar 23 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.