// ****************************************************************
// Calendar Cell Template.
// ****************************************************************
Sonner.Templates.Calendar = AW.Templates.Text.subclass();
Sonner.Templates.Calendar.create = function()
{
var obj = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new AW.UI.Input;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
editor.setAttribute("value", function(){
return template.getItemProperty("text");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template;
function switchToEditMode(){
if (template) {
switchToTextMode()
}
template = this;
template.element().style.padding = 0;
template.element().innerHTML = editor;
editor.element().focus();
// pop-up calendar now
var onSelect = function(calendar, date){
if(calendar.dateClicked){
editor.element().value = date;
calendar.callCloseHandler();
editor.element().blur();
}
}
var onClose = function(calendar){calendar.hide();calendar.destroy();}
var cal = new Calendar(1, null, onSelect, onClose);
cal.weekNumbers = false;
cal.setDateFormat("%m/%d/%Y");
cal.create();
cal.parseDate(editor.element().value);
cal.showAtElement(editor.element());
}
obj.setEvent("onfocus", switchToEditMode);
function switchToTextMode(){
var originalVal = template.getItemProperty("text");
var value = editor.element().value;
if(originalVal != value){
template.setItemProperty("text", value);
//dumpElement(template);
}
template.refresh();
template = null;
}
editor.setEvent("onblur", switchToTextMode);
};
Sonner.Templates.Calendar.create();
...
<script>
var records = [ ["10/05/2002", "10 de Maio de 2002"],
["28/07/2001", "28 de Julho de 2001"],
["17/11/2006", "17 de Novembro de 2006"],
["15/02/2003", "15 de Fevereiro de 2002"],
["08/09/2004", "08 de Agosto de 2004"]
];
var columns = [ "Data", "Data Escrita" ];
var table = new AW.UI.Grid;
table.setHeaderText(columns);
table.setColumnCount(2);
table.setRowCount(5);
table.setCellText(records);
// templates
var calendar = new Sonner.Templates.Calendar;
var text = new AW.Formats.String;
table.setCellFormat([calendar, text]);
document.write(table);
</script>
This topic is archived.