Day Display by Month
by dfederighi
HTML
<form>
<select name="mon" id="monSel">
<option value="0">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="6">July</option>
<option value="9">October</option>
<option value="10">November</option>
</select>
</form>
<h4>Dates:</h4>
<div id="content"></div>
JavaScript
YUI().use('base', 'node', 'view', 'model', 'model-list', 'datatype', function(Y) {
Y.DateModel = Y.Base.create('dateModel', Y.Model, [], {
idAttribute: 'DateString'
},
{
ATTRS: {
'DateString': { value: '' },
'Date': { value: null }
}
});
Y.DateModelList = Y.Base.create('dateModelList', Y.ModelList, [], {
model: Y.DateModel,
getAll: function() {
this.each(function (model) {
console.log('model:', model.getAttrs());
});
}
},
{
ATTRS: {}
});
Y.DateView = Y.Base.create('dateView', Y.View, [], {
containerTemplate: '<div />',
events: {},
template: '<div style="height:40px;line-height:40px;background-color:#ccc;margin:10px;">{date}</div>',
initializer: function() {
var model = this.get('model');
},
render: function() {
//console.log('rendering model:', this.get('model').getAttrs());
this.get('container').append(Y.Node.create(Y.Lang.sub(this.template, {
'date': this.get('model').get('DateString')
})));
}
},
{
ATTRS: {}
});
var renderDates = function(month, year) {
var daysInMonth = 32 - new Date(year, month, 32).getDate(),
today = new Date().getDate();
Y.one('#content').setHTML('');
var dateModelList = new Y.DateModelList();
//for (var dIdx = daysInMonth; dIdx >= 1; dIdx--) {
for (var dIdx = 1; dIdx <= daysInMonth; dIdx++) {
var d = new Date(year, month, dIdx);
var dateModel = new Y.DateModel({
'DateString': Y.DataType.Date.format(d, {format: '%Y-%m-%d'}),
'Date': d.toString()
});
...