Calendário para Web… um desafio…?

Durante este último mês apresentou-se perante mim a oportunidade de desenvolver um calendário para Web que tivesse um funcionamento mais parecido com células do nosso conhecido “Microsoft Excel”. À partida, tal parece problemático, a não ser que ponhamos a séria hipótese de usar o nosso maior aliado para este fim: Javascript.

O Javascript permite-nos basear a funcionalidade do calendário mais em Client-Side do que em Server-Side, facilitando-nos variadas tarefas como mudar de cores ou fazer display de mensagens no ecrã – isto sem termos de submeter os dados regularmente.

Resta dizer que, apesar de ser um desafio, é bastante exequível, desde que partamos do pressuposto que vamos usar mais Javascript do que é habitual em maior parte das Web applications.

Segue-se um exemplo bastante simples da utilização de Javascript para adicionar funcionalidade a um calendário:

Code Snippet
  1. <script type=“text/javascript” language=“javascript”>
  2.    var daysToShow;
  3.    
  4.     function jsChangeColor(textBoxObj, parentCellID, daysRemaining, totalDays, originalValue) {
  5.         var radioButton = document.getElementById(“<%=this.radioBtnControl.ClientID %>”);
  6.         
  7.         if (radioBtnControl.checked)
  8.         {
  9.             
  10.             if (daysToShow == undefined)
  11.             {
  12.                 daysToShow = daysRemaining;
  13.             }
  14.             textBoxObj = document.getElementById(textBoxObj);
  15.             var textBoxValue = parseInt(textBoxObj.value);
  16.             var DBValue = originalValue;
  17.             if (textBoxValue == 10)
  18.             {
  19.                 textBoxObj.value = 7;
  20.                 ColorCells(textBoxObj.value, parentCellID);
  21.                 document.getElementById(“<%=this.labelToShowValue.ClientID %>”).innerHTML = “( “ + daysToShow + “/” + totalDays + ” )”;
  22.                 FillHdnField(daysToShow);
  23.                 objInputBuffer = document.getElementById(“<%=this.textBoxToReceiveChangedValues.ClientID %>”);
  24.                 var mynewvalue = textBoxObj.id + “=” + textBoxObj.value + “/” + DBValue + “;”;
  25.                 objInputBuffer.value = objInputBuffer.value.replace(textBoxObj.id + “=” + textBoxValue + “/” + DBValue + “;”, “”);
  26.                 objInputBuffer.value = mynewvalue + objInputBuffer.value;
  27.             }
  28.        }
  29.        
  30.        function ColorCells(cellObjectValue, parentCellID)
  31.        {
  32.              document.getElementById(parentCellID).style.background = “”;
  33.     
  34.              switch (parseInt(cellObjectValue))
  35.              {
  36.                 
  37.                  case 1:
  38.                      GetColorString(“#3F8FFF”, parentCellID, true);
  39.                      break;
  40.                  case 2:
  41.                      GetColorString(“#FFF65E”, parentCellID, true);
  42.              }
  43.        }
  44.        
  45.        function GetColorString(colorString, parentCellID, isBackColor)
  46.         {
  47.             if(isBackColor)
  48.             {
  49.                 document.getElementById(parentCellID).style.backgroundColor = colorString;
  50.             }
  51.             else
  52.             {
  53.                 document.getElementById(parentCellID).style.background = colorString;
  54.             }
  55.         }
  56.         
  57.         function FillHdnField(finalValue)
  58.         {
  59.             document.getElementById(“<%= this.hiddenField.ClientID %>”).value = finalValue;
  60.         }
  61. </script>

A função jsChangeColor recebe vários parâmetros e caso o radioButton esteja checked, processa e passa a colorir uma célula do calendário.

Resumindo, resta mais uma vez sublinhar o quão importante é compreendermos que o Javascript, embora “assuste” alguns programadores, é um aliado imprescindível para este tipo de controlos.

Isto não significa que a utilização do controlo de calendário de ASP .NET não tenha a sua quota de dificuldade. É um controlo que tem algumas limitações quanto à extensão da sua funcionalidade de base, como podemos ver na situação engraçada que se segue:

 

The Problem

You have been tasked to create a time off tool request involving some pretty complicated things.  Your boss has asked for numerous features in this tool which you hoped he had never asked. 

 

clip_image001Da Boss

  • I want it to highlight specific days signaling holidays or time off requests. This helps me visualize what type of day the request is.   Color coding is a plus :-) .
  • I’d like some nice mouse over effect on days that are not requested.  This helps the user notice a clickable type of cell.
  • O I dunno…I’d like to not only see a monthly view, but a yearly view so that I can quickly glance over an entire year for an employee.
  • O well…I dunno…Impress me…maybe allow a user to click a day on the calendar and have it go to a page with that calendar day being selected.

Umm you know the simple things..besides you have all the tools that the company has purchased for you.

clip_image002

You

Thoughts to self: ***O NO NOT THE CALENDAR CONTROL…BUT CANT WE JUST BUY SOMETHING PRE MADE***

clip_image001[1]

Boss

O by the way…we don’t have any money to buy any third party tools…have a great day.  Don’t forget to e-mail when its all done.

clip_image002[1]

You

O certainly boss…*cringe*…this should be no sweat *thank God I wore deodorant*.  Quickly images begin flashing in your head about what your boss said:

"I want it to highlight specific days signaling holidays or time off requests. This helps me visualize what type of day the request is.   Color coding is a plus :-) ."

"I’d like some nice mouse over effect on days that are not requested.  This helps the user notice a clickable type of cell."

"O I dunno…I’d like to not only see a monthly view, but a yearly view so that I can quickly glance over an entire year for an employee."

"O well…I dunno…Impress me…maybe allow a user to click a day on the calendar and have it go to a page with that calendar day being selected."

**Ok that one is simple response.redirect and send a query string**

clip_image002[2]

 

How in the world am I going to do all of these with the ASP.net calendar control?  That control is just so dull, so plain, difficult to use.

 

Por hoje é tudo…

Trar-vos-ei novos desenvolvimentos num futuro próximo…

Até lá, despeço-me…… Até á próxima!

Fontes: http://weblogs.sqlteam.com/jhermiz/archive/2007/12/10/Cool-Tricks-With-The-ASP.net-Calendar.aspx

2 pensamentos em “Calendário para Web… um desafio…?

  1. Pingback: Top Posts de 2009 « Sandro Batista's Blog

  2. Pingback: 100 posts em quase 2 anos! « Inovação em Sistemas de Informação

Deixar uma resposta

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Modificar )

Imagem do Twitter

You are commenting using your Twitter account. Log Out / Modificar )

Facebook photo

You are commenting using your Facebook account. Log Out / Modificar )

Connecting to %s