This article is a continuation of Implement the Dojo DateTextBox Control In an HTML5 Web Application Using the Maqetta Editor .
In that tutorial, we learned how to work with Dojo DateTextBox control
properties to change the date display format, wrote validation code, and
got better aquainted with the Palette and Property tabs of the Maqetta
editor. In today's follow up, we'll be adding the code to calculate the
years of service based on the start and end dates, as well as how to
control the visual aspects of our web app, including the form layout and
theme.
Calculating the Years, Months, and Days
In the last instalment, we were left with a call to
calcYearsMonthsAndDays() that was not fleshed out. Now it's time to
delve into that, starting with the calcYearsMonthsAndDays() method:
1
2
3
4
5
6
| function calcYearsMonthsAndDays(startDate, endDate) { var yearsOfService = dateDifference(startDate, endDate); dojo.byId( "lblYears" ).innerHTML = yearsOfService[0]; dojo.byId( "lblMonths" ).innerHTML = yearsOfService[1]; dojo.byId( "lblDays" ).innerHTML = yearsOfService[2]; } |
CalcYearsMonthsAndDays() calls a function called dateDifference() that
returns a three element array consisting of the years, months, and days.
Each of these date parts are then displayed in their respective labels.
That part is simple enough. The real work takes place in the
dateDifference() function, which I adapted from a Java method. Luckily,
very few changes were required to convert it to JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| function dateDifference(d1, d2) { var fromDate, toDate, year, month, day; if (d1 > d2) { fromDate = d2; toDate = d1; } else { fromDate = d1; toDate = d2; } var increment = 0; if (fromDate.getDate() > toDate.getDate()) { increment = fromDate.getLastDayOfMonth(); } if (increment != 0) { day = (toDate.getDate() + increment) - fromDate.getDate(); increment = 1; } else { day = toDate.getDate() - fromDate.getDate(); } //month Calculation if ((fromDate.getMonth() + increment) > toDate.getMonth()) { month = (toDate.getMonth() + 12) - (fromDate.getMonth() + increment); increment = 1; } else { month = toDate.getMonth() - (fromDate.getMonth() + increment); increment = 0; } //Year Calculation year = toDate.getFullYear() - (fromDate.getFullYear() + increment); return [year, month, day]; } |
The last date function is getLastDayOfMonth(), which I included to
take advantage of JavaScript Rollovers. In a nutshell, whenever you set a
date component - such as the year, month, or day - to a value that
exceeds the maximum for that field type, overflowing causes the entire
date to change accordingly rather than throw an error. For instance,
setting a month of 12 (months are zero based) will set the date to
January of the following year. Even more advantageous, is the effect
triggered by setting the day to zero. It rolls back the date to the last
day of the previous month, allowing us to easily determine the length
of a given month:
1
2
3
4
5
6
| Date.prototype.getLastDayOfMonth = function () { var dt = new Date( this ); dt.setMonth(dt.getMonth() + 1); dt.setDate(0); return dt.getDate(); }; |
Tweaking the Form Layout
The form is fully functional at this point, but we can make it look
more professional through a combination of layout and CSS styling.
Dojo, always known for their impressive array of widgets, offers a
control called a Border Container. Ostensibly used for page layouts that
contains sidebars and/or headers, it's comprised of a center panel and
four optional borders along its sides:
If we drag it into an form on the design pane, we can then place the
title in the top border, the start and end date labels in the left
border, the start, end date, and Calculate button controls in the center
area, the Weekday info in the right panel, and the Years, Months, Days,
and messages output in the bottom border. Now our form has a more
esthetically pleasing layout:
Now that image of the final layout took a bit of maneuvering to
arrive at. A general sizing can be arrived at by clicking on individual
sections of the layout and then dragging the borders. For more
fine-grained tuning, you can enter exact numbers in the layout section
on the right. You can always edit the HTML markup directly by choosing
the Source layout instead of Design. Alternatively, the Split-H and
Split-V design layouts show both the WYSIWYG Editor and Markup panes
simultaneously. In either of those modes, clicking on source code will
highlight the page element that it pertains to in the Design Editor.
Likewise, selecting a page element will highlight the relevant code in
the Markup pane:
That can be really useful for getting a look at all of an element's properties at a glance.
Overriding a Theme
When you create a new project, Maqetta defines a CSS Theme that best
suits the project type. Web Applications for instance, implement the
Claro Theme (There is also a Sketch Theme). We are free to change parts
of the default themes or even create a new one from scratch. Personally,
I like to use the original theme as a basis for my own. To do that:
- Click the Create button at the top-center of the screen and select Theme... from the menu.
- In the New Theme dialog, select a theme to clone. For Web apps, the usual starting point is claro or claro2.
- Give your theme a name, and click Create to save it.
- To configure your theme, click the Open button, located beside Create, and choose Theme Editor... from the list.
- On the Open Theme dialog, select your new theme from the list and click Open.
All of the supported widgets are displayed and divided into three
sections: Global Styling, Primitive Widgets and Container Widgets.
Clicking on any widget selects it so that its properties can be
configured in the Properties palette.
Let's change the font color for all document elements.
- Select the Generic text widget at the top of the editor, under Global Styling.
- Open the Fonts and Text section of the Properties palette.
- Set the font color to blue. Notice how the text for all the widgets in the editor turns blue.
- Click on the Save button on the toolbar to commit your changes.
Now we'll change the Selected Date color for the Calendar control.
- Click on a date in the Calendar widget. That will display its subwidget panel.
- Open the Background section of the Properties palette.
- Select the Color picker... from the background-color dropdown and change the color (I chose #6fc7dd [aqua]). After clicking OK, the selected date in the calendar will be updated to reflect your changes:
4. Once again, click on the Save button on the toolbar to commit your changes.
Try It Out
Hit the Preview in Browser button in the top-right corner to view the
app in the browser. Go ahead and pick a start and end date, then press
the Calculate button to see the results:
Success! Retirement is just around the corner...sort of...
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru JavaScript Online Training in India. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai
ReplyDeleteGreat Article
DeleteIEEE Final Year Projects for CSE
IEEE Project Centers in Chennai
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteArkon Web Solutions is the top & best website design company in usa . We create attractive UX and UI design as well as superb responsive web design services.
I created a website a few years ago, and I was willing to provide a new look to it, so I sought Planet Web Design for seeking professional assistance. They helped me by designing an extremely beautiful website.
ReplyDeleteI would like to say this is a well-informed article as we have seen here. Your way of writing is very impressive and also it is a beneficial article for us. Thanks for sharing an article like this.Maine web design company
ReplyDeleteThe article was up to the point and described the information very effectively. Thanks to blog author for sharing an informative post. Melbourne App development
ReplyDeleteThanks for the best blog. it was very useful for me.keep sharing such ideas in the future as well.
ReplyDeleteReference: V8web Faribault Website Design
You have done a good job by publishing this article about Web. I appreciate your efforts which you have put into this article, It is a beneficial article for us. Thanks for sharing such informative thoughts. web design portland
ReplyDeleteYour blog is really good. This information is really useful for those who have searched for this and you have great knowledge about this. I’m really impressed with your post.trance mediumship courses online
ReplyDeleteNice information, You have provided excellent data for us. It is valuable and informative for everyone. Keep posting always. I am very thankful to you. freelancer React Js developer
ReplyDeleteThanks for sharing this article here about the website design. Your article is very informative and I will share it with my other friends as the information is really very useful. Keep sharing your excellent work.Mobile Apps Development Saas In India
ReplyDeleteYour blog is very valuable which you have shared here about Hire professional Web app developer online. I appreciate your efforts which you have put into this article and also it is a gainful article for us. Thank you for sharing this article here.
ReplyDeleteI would like to thank you for sharing such great post about HTML5 Web Application. I got some great knowledge from this post. Keep posting. Website Designer San Antonio.
ReplyDeleteI am attracted by the info which you have provided in the above post. It is genuinely good and beneficial info for us. Continue posting, Thank you. Web Design Company
ReplyDeleteI generally check this kind of article and I found your article which is related to my interest. Genuinely it is good and instructive information. Thankful to you for sharing an article like this. Web Design Company Lahore
ReplyDeleteI read the above article and I got some knowledge from your article. It's actually great and useful data for us. Thanks for share it. dedicated server malaysia
ReplyDeleteI am attracted by the info which you have provided in the above post. It is genuinely good and beneficial info for us. Continue posting, Thank you. IT Solutions Company India
ReplyDeleteYour blog is very valuable which you have shared here about.web design agency dublin I appreciate your efforts which you have put into this article and also it is a gainful article for us. Thank you for sharing this article here.
ReplyDeleteI found decent information in your article. I am impressed with how nicely you described this subject, It is a gainful article for us. cloudsuite distribution electronic data interchange edi service Thanks for share it.
ReplyDeleteVery well written article. It was an awesome article to read. Complete rich content and fully informative. I totally Loved it. Read more info about website agency jakarta
ReplyDeleteI am attracted by the info which you have provided in the above post. It is genuinely good and beneficial info for us. Continue posting, Thank you. Graphics Design Services in India
ReplyDeleteI admire this article for the well-researched content and excellent wording. web application dubai. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
ReplyDeleteExcellent job, this is great information which is shared by you. This info is meaningful and factual for us to increase our knowledge about it. about Web Designers in Tampa So please always keep sharing this type of information.
ReplyDeleteI appreciate your efforts which you have put into this article about website design toledo. Genuinely it is a useful article to increase our knowledge. Thanks for share an article like this.
ReplyDeleteI just need to say this is a well-informed article which you have shared here about miami web services. It is an engaging and gainful article for us. Continue imparting this sort of info, Thanks to you.
ReplyDeleteThanks for nice and informative post. This article is really contains lot more information about this topic.
ReplyDeleteGraphics Design Services India
You'll be able to make intelligent decisions to get your sites ranked higher, drive in more traffic, capture more leads and make more sales. www-d0 fnal gov
ReplyDeleteReconciliation is the process by which Insurance companies and the federally run Insurance exchange iron out any discrepancies in enrollment information — making sure, for example, that the same person isn't accidentally enrolled in two policies, and that the consumer and the Insurance company got the same information about the size of any subsidies. What Is Public Indemnity Insurance
ReplyDeleteGreat job for publishing such a nice article. Your article isn’t only useful but it is additionally really informative. Read more info aboutweb design portlandThank you because you have been willing to share information with us.
ReplyDeleteYour post is very informative for me about Web Development Services. excellent post, I really like this post, thanks for sharing.
ReplyDelete