On Click Text box and Select Templates - Comments/Suggestions welcom
Click Text box template
/*****************************************************************
ActiveWidgets Grid 1.0.0 (Free Edition).
Copyright (C) 2004 ActiveWidgets Ltd. All Rights Reserved.
More information at http://www.activewidgets.com/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Supports editing on Click.
This is achieved by creating a Div with a input tag and
toggling visiblity of the input element
*****************************************************************/
/*
Provides ability to edit the grid control cell on click
*/
if (!window.Prima) Prima=[];
if (!Prima.Templates) Prima.Templates=[];
Prima.Templates.ClickInput = Active.System.Template.subclass();
Prima.Templates.ClickInput.create = function()
{
/****************************************************************
Click Input Cell template.
*****************************************************************/
// ---------- DIV ---------------
var mainDiv = this.prototype;
mainDiv.setTag("div");
mainDiv.setClass("templates", "box");
mainDiv.setContent("html", function(){return this.generateHtml();} );
mainDiv.setAttribute("name", function(){ return this.getName("maindiv"); } );
mainDiv.getName = function(prefix)
{
var r = this.getRowProperty("index");
var c = this.getColumnProperty("index");
if (!r) r = 0;
if (!c) c = 0;
return prefix + "_" +r+ "_" +c;
}
/**
* This function can be overridden to receive change events from the
* rendered grid input elements
*/
mainDiv.onChangeAction = function( newVal, name, row, col )
{
myData[row][col]=newVal;
return true;
}
mainDiv.generateHtml = function()
{
var row = this.getRowProperty("index");
var col = this.getColumnProperty("index");
// ---------- INPUT ---------------
var inputDiv = new Active.HTML.DIV;
inputDiv.setClass("templates","clickinput");
inputDiv.setStyle("display", "none");
var input = new Active.HTML.INPUT;
input.setClass("templates", "clickinput");
input.setAttribute("type", "text");
input.setAttribute("value", this.getItemProperty("text"));
input.setEvent("onblur", function(event) { this.makeUneditable( event ); } );
// set the content of the display div
inputDiv.setContent(input.toString());
input.makeUneditable = function(event)
{
var originalVal = this.getAttribute("value");
var currentVal = this.element().value;
if (currentVal!=originalVal)
{
if(mainDiv.onChangeAction( currentVal, name, row, col ) == true)
{
this.setAttribute("value", currentVal);
dispDiv.setContent("html",currentVal);
}
}
inputDiv.setStyle("display", "none");
dispDiv.setStyle("display", "block");
dispDiv.refresh();
}
// ---------- INPUT ---------------
var html = new Array();
html.push(inputDiv);
var dispDiv = new Active.HTML.DIV;
dispDiv.setClass("templates", "clickinput");
dispDiv.setContent("html",this.getItemProperty("text"));
dispDiv.setEvent("ondblclick", function(event) { this.makeEditable( event ); } );
dispDiv.makeEditable = function(event)
{
this.setStyle("display", "none");
inputDiv.setStyle("display", "block");
input.element().focus();
}
html.push(dispDiv);
return html.join("");
}
// ---------- DIV ---------------
};
Prima.Templates.ClickInput.create();
Click Select template
Still working on this
/*****************************************************************
ActiveWidgets Grid 1.0.0 (Free Edition).
Copyright (C) 2004 ActiveWidgets Ltd. All Rights Reserved.
More information at http://www.activewidgets.com/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Supports editing on Click.
This is achieved by creating a Div with a input tag and
toggling visiblity of the input element
*****************************************************************/
/*
Provides ability to edit the grid control cell on click
*/
if (!window.Prima) Prima=[];
if (!Prima.Templates) Prima.Templates=[];
Prima.Templates.ClickSelect = Active.System.Template.subclass();
Prima.Templates.ClickSelect.prototype._options = new Array();
Prima.Templates.ClickSelect.create = function()
{
/****************************************************************
Click Input Cell template.
*****************************************************************/
// ---------- DIV ---------------
var mainDiv = this.prototype;
mainDiv.setTag("div");
mainDiv.setClass("templates", "box");
mainDiv.setContent("html", function(){return this.generateHtml();} );
mainDiv.setAttribute("name", function(){ return this.getName("maindiv"); } );
mainDiv.getName = function(prefix)
{
var r = this.getRowProperty("index");
var c = this.getColumnProperty("index");
if (!r) r = 0;
if (!c) c = 0;
return prefix + "_" +r+ "_" +c;
}
/**
* This function can be overridden to receive change events from the
* rendered grid input elements
*/
mainDiv.onChangeAction = function( newVal, name, row, col )
{
myData[row][col]=newVal;
return true;
}
//------------------------------------------------------------
//Add the text value pair to the select dropdown list
//------------------------------------------------------------
mainDiv.addOption = function( text, value )
{
this._options.push( new Array( value ? value : text, text) );
}
mainDiv.clearOptions = function()
{
this._options = new Array();
}
mainDiv.getOptions = function()
{
return this._options;
}
mainDiv.generateHtml = function()
{
var row = this.getRowProperty("index");
var col = this.getColumnProperty("index");
var textVal = this.getItemProperty("text");
var inputOptions = this._options;
// ---------- INPUT ---------------
var inputDiv = new Active.HTML.DIV;
inputDiv.setClass("templates","clickinput");
inputDiv.setStyle("display", "none");
var input = new Active.System.HTML;
input.setTag("select");
input.setClass("templates", "input");
input.setEvent("onblur", function(event) { this.makeUneditable( event ); } );
input.setContent( "options", function()
{
var optionsHTML = new Array();
var foundMe = false;
for( i=0; i< inputOptions.length; i++ )
{
var oTag = new Active.System.HTML();
var val = inputOptions[i][0];
oTag.setTag("option");
oTag.setAttribute( "value", val );
oTag.setContent("text",inputOptions[i][1]);
if ( val==textVal )
{
oTag.setAttribute( "selected","true" );
foundMe = true;
}
optionsHTML.push( oTag );
}
if (!foundMe)
{
optionsHTML.push("<option value=\""+textVal+"\" selected=\"true\">"+textVal+"</option>");
}
return optionsHTML.join("");
});
inputDiv.setContent(input.toString());
input.makeUneditable = function(event)
{
var originalVal = this.getAttribute("value");
var currentVal = this.element().value;
if (currentVal!=originalVal)
{
if(mainDiv.onChangeAction( currentVal, name, row, col ) == true)
{
this.setAttribute("value", currentVal);
// obtain the text to display
var bFound = false;
for( i=0; i< inputOptions.length; i++ )
{
var val = inputOptions[i][0];
var text = inputOptions[i][1];
if(val == currentVal)
{
bFound = true;
dispDiv.setContent("html",text);
break;
}
}
if(bFound == false)
{
dispDiv.setContent("html",currentVal);
}
}
}
inputDiv.setStyle("display", "none");
dispDiv.setStyle("display", "block");
dispDiv.refresh();
}
// ---------- INPUT ---------------
var html = new Array();
html.push(inputDiv);
var dispDiv = new Active.HTML.DIV;
dispDiv.setClass("templates", "clickinput");
dispDiv.setContent("html",this.getItemProperty("text"));
dispDiv.setEvent("ondblclick", function(event) { this.makeEditable( event ); } );
dispDiv.makeEditable = function(event)
{
this.setStyle("display", "none");
inputDiv.setStyle("display", "block");
input.element().focus();
}
html.push(dispDiv);
return html.join("");
}
// ---------- DIV ---------------
};
Prima.Templates.ClickSelect.create();
Bhaskar
June 17,