if (!window.Prima) Prima=[];
if (!Prima.Templates) Prima.Templates=[];
Prima.Templates.StatusSelect = Active.Templates.Text.subclass();
Prima.Templates.StatusSelect.prototype._options = new Array();
Prima.Templates.StatusSelect.create = function()
{
var obj = this.prototype;
//------------------------------------------------------------
//Add the text value pair to the select dropdown list
//------------------------------------------------------------
obj.addOption = function( text, value )
{
this._options.push( new Array( value ? value : text, text) );
}
obj.clearOptions = function()
{
this._options = new Array();
}
obj.getOptions = function()
{
return this._options;
}
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new Active.HTML.DIV;
editor.setTag("select");
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
editor.setEvent("onblur", function(event) { this.switchToTextMode( event ); } );
editor.setContent( "options", function()
{
var text = template.getItemProperty("text");
var inputOptions = obj._options;
var optionsHTML = new Array();
for( i=0; i< inputOptions.length; i++ )
{
var oTag = new Active.System.HTML();
var val = inputOptions[i][0];
var txt = inputOptions[i][1];
oTag.setTag("option");
oTag.setAttribute( "value", val );
oTag.setContent("text",inputOptions[i][1]);
if ( text==txt )
{
oTag.setAttribute( "selected","true" );
}
optionsHTML.push( oTag );
}
return optionsHTML.join("");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template;
function switchToEditMode()
{
template = this;
template.element().style.padding = 0;
template.element().innerHTML = editor;
editor.element().focus();
}
obj.setEvent("ondblclick", switchToEditMode);
function switchToTextMode()
{
var originalText = template.getItemProperty("text");
var value = editor.element().value;
var selectedIndex = editor.element().selectedIndex;
var text = editor.element().options[selectedIndex].text;
// we want to compare the text in the grid
// grid display only the text
if(originalText != text)
{
template.setItemProperty("text", text);
template.setItemProperty("value", value);
if(obj.onChangeEvent)
{
obj.onChangeEvent();
}
}
template.refresh();
template = null;
}
obj.onChangeEvent = function()
{
// alert("User must override this function to recieve the events");
}
editor.setEvent("onblur", switchToTextMode);
};
Prima.Templates.StatusSelect.create();
/****************************************************************
Set the cell text.
@param i (Index) Row index.
@param j (Index) Column index.
*****************************************************************/
obj.setValue = function(value, i, j)
{
// used to commit the changes
var taskId = taskTable.getValue(i,<%=TASK_ID_COL%>);
// create HTTP request object and save the value to the database
var commitChangeRequest = new Active.HTTP.Request;
// URL
commitChangeRequest.setURL("<%=request.getContextPath()%>/UpdateTask.do");
// set request method to POST (default is GET)
commitChangeRequest.setRequestMethod("POST");
// set request parameters (i.e. form values)
commitChangeRequest.setParameter("taskId", taskId);
if(j > <%=TASK_GRID_COLS%>)
{
commitChangeRequest.setParameter("backlogDay", (j-1)-<%=TASK_GRID_COLS%>);
commitChangeRequest.setParameter("duration", value);
commitChangeRequest.setParameter("durationType", durationType);
// send the request (async)
commitChangeRequest.request();
}
else
{
switch(j)
{
case 0 : commitChangeRequest.setParameter("name", value);
// send the request (async)
commitChangeRequest.request();
break;
case 1 : commitChangeRequest.setParameter("originalUnits", value);
// send the request (async)
commitChangeRequest.request();
break;
case 2 : commitChangeRequest.setParameter("resource", value);
// send the request (async)
commitChangeRequest.request();
break;
case 3 : commitChangeRequest.setParameter("status", value);
// send the request (async)
commitChangeRequest.request();
break;
default: alert("<bean:message key='error.fieldvaluechange'/>");
}
}
// set event handler to process the result
commitChangeRequest.response = function(text)
{
// display a message only if the status code is other than 200
// alert("Alert status code " + this.getStatus());
};
};
This topic is archived.