var argumentnames = structkeyarray(arguments);
var i = 1;
this.gridStr = structNew();
for (i=1;i lte ArrayLen(argumentnames); i=IncrementValue(i)){
this.gridStr[argumentnames[i]] = arguments[argumentnames[i]];
}
this.gridStr.gridColumns = ArrayNew(1);
this.gridStr.printFooter = false;
this.gridStr.printHeader = false;
this.gridStr.grouping = false;
this.gridStr.enableRowBody = false;
this.gridStr.includeForm = false;
var argumentnames = structkeyarray(arguments);
var i = 1;
var gridcolstruct = StructNew();
for (i=1; i lte ArrayLen(argumentnames);i=incrementvalue(i)){
gridcolstruct[argumentnames[i]] = arguments[argumentnames[i]];
}
//column are not not editable by default - must use the setGridColEditable method
gridcolstruct['editable'] = false;
ArrayAppend(this.gridStr.gridColumns,gridcolstruct);
var i = 1;
var col = 0;
for (i=1;i lte ArrayLen(this.gridStr.gridColumns);i=i+1){
if (this.gridStr.gridColumns[i]['name'] eq arguments.name){
col = i;
break;
}
}
if (col gt 0){
this.gridStr.gridColumns[i]['editable'] = true;
this.gridStr.gridColumns[i]['editOptions'] = arguments;
}else{
arrayAppend(this.errormessages,'The name ('&arguments.name&') you specified for an editable column does not match any existing column names');
}
if (not this.gridStr.includeForm){
this.gridStr.includeForm = true;
}
this.gridStr.printFooter = true;
structappend(this.gridStr,arguments);
//this.gridStr.displayMessage = arguments.displayMessage;
//this.gridStr.emptyMessage = arguments.emptyMessage;
//this.gridStr.displayInfo = arguments.displayInfo;
Ext.BLANK_IMAGE_URL = '#this.path#/resources/images/default/s.gif';
Ext.namespace('ExtCFC');
var i = 1;
var cols = '';
function setupDataSource() {
myRecordObj = Ext.data.Record.create([
{name: '#this.gridStr.gridColumns[i]['name']#',
mapping: '#this.gridStr.gridColumns[i]['mapping']#'
, type: '#lcase(this.gridStr.gridColumns[i]['type'])#'
, dateFormat: '#this.gridStr.gridColumns[i]['dateFormat']#'
}
,
, '#this.gridStr.rowBodyCol#'
]);
myReader = new Ext.data.JsonReader({
root: 'data',
totalProperty: 'recordcount',
id: '#this.gridStr.id#'
},myRecordObj);
// Data Store
ds = new Ext.data.GroupingStore({
ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '#this.gridStr.path#',
method: 'POST'
}),
reader: myReader,
sortInfo:{field: '#this.gridStr.defaultSortColumn#', direction: "#this.gridStr.defaultSortOrder#"},
remoteSort: #this.gridStr.remoteSorting#
,groupField:'#this.gridStr.groupcol#'
});
ds.load({params: {
start: 0,
limit: #this.gridStr.limit#
}});
} // end setupDataSource
function render#this.gridStr.gridColumns[i].name#Plain(value){ return #this.gridStr.gridColumns[i].renderer#; }
function getColumnModel() {
if(!colModel) { //only need to create columnModel if it doesn't already exist
//pluggable renders
colModel = new Ext.grid.ColumnModel([
{
id: '#this.gridStr.gridColumns[i]['id']#',
header: "#this.gridStr.gridColumns[i]['header']#",
dataIndex: '#this.gridStr.gridColumns[i]['name']#',
css: '#this.gridStr.gridColumns[i]['css']#',
sortable: truefalse,
hidden: truealign: '#this.gridStr.gridColumns[i]['align']#',renderer: render#this.gridStr.gridColumns[i].name#Plain,
width: #this.gridStr.gridColumns[i]['width']#
, editor: new fm.TextField({
#printGridEditFormOptions(i)#
})
, editor: new fm.TextArea({
#printGridEditFormOptions(i)#
})
, editor: new fm.ComboBox({
#printGridEditFormOptions(i)#
,lazyRender:true
})
, editor: new fm.Checkbox({
#printGridEditFormOptions(i)#
})
, editor: new fm.HtmlEditor({
#printGridEditFormOptions(i)#
})
, editor: new fm.Radio({
#printGridEditFormOptions(i)#
})
, editor: new fm.NumberField({
#printGridEditFormOptions(i)#
})
, editor: new fm.DateField({
#printGridEditFormOptions(i)#
})
, editor: new fm.TimeField({
#printGridEditFormOptions(i)#
})
},
]);//end colModel
//instead of specifying sorting permission by individual columns can also specify for entire grid
//colModel.defaultSortable = false;
}//end if colModel
return colModel;
}//getColumnModel
allowBlank: #boolFormat(this.gridStr.gridColumns[arguments.i]['editOptions']['allowBlank'])#,
blankText: '#this.gridStr.gridColumns[arguments.i]['editOptions']['blankText']#',
cls: '#this.gridStr.gridColumns[arguments.i]['editOptions']['class']#',
ctCls: '#this.gridStr.gridColumns[arguments.i]['editOptions']['containerClass']#',
disabled: #boolFormat(this.gridStr.gridColumns[arguments.i]['editOptions']['disabled'])#
,disabledClass: '#this.gridStr.gridColumns[arguments.i]['editOptions']['disabledClass']#'
,emptyClass: '#this.gridStr.gridColumns[arguments.i]['editOptions']['emptyClass']#'
,emptyText: '#this.gridStr.gridColumns[arguments.i]['editOptions']['emptyText']#'
,fieldClass: '#this.gridStr.gridColumns[arguments.i]['editOptions']['fieldClass']#'
,fieldLabel: '#this.gridStr.gridColumns[arguments.i]['editOptions']['fieldLabel']#'
,focusClass: '#this.gridStr.gridColumns[arguments.i]['editOptions']['focusClass']#'
,maxLength: #this.gridStr.gridColumns[arguments.i]['editOptions']['maxLength']#
,minLength: #this.gridStr.gridColumns[arguments.i]['editOptions']['minLength']#
function buildGrid(){
grid = new Ext.grid.EditorGridPanel({
grid = new Ext.grid.GridPanel({
store: ds, //the DataStore object to use (ds: is shorthand)
colModel: getColumnModel(),
selModel: new Ext.grid.RowSelectionModel({singleSelect:truefalse}),
selModel: new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),
height:350,//you must specify height or autoHeight
//autoHeight:true,//autoHeight resizes the height to show all records
width:740,
title:'#this.gridStr.title#',
stripeRows:true,
frame: true,
collapsible: true,
animCollapse: true,
clicksToEdit: 1,
renderTo: '#this.gridStr.name#-grid'
//this is the key to showing the GroupingStore
, view: new Ext.grid.GroupingView({
, viewConfig: {
forceFit:true
, startCollapsed: true
//custom grouping text template to display the number of items per group
, groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
, enableRowBody: true
, showDetails: true
, showDetails: false
, getRowClass: function(record, rowIndex, p, store){
if(this.showDetails){
p.body = '
'+record.data.#this.gridStr.rowBodyCol#+'
';
return 'x-grid3-row-expanded';
}
return 'x-grid3-row-collapsed';
}
})
}
});
grid.render();
function toggleDetails(btn, pressed){
var view = grid.getView();
//if enableRowBody we need a variable to indicate whether or not to show row
view.showDetails = pressed;
view.refresh();
}
}
//Add a top bar
, tbar: [
{
text: 'Add Record',
tooltip: 'Click to Add a row',
iconCls:'add', //we create our own css with a class called 'add'
//custom class not included in ext-all.css by default
handler: addRecord //what happens when user clicks on it
}, '-', //add a separator
{
text: 'Delete Selected',
tooltip: 'Click to Delete selected row(s)',
handler: handleDelete, //what happens when user clicks on it
iconCls:'remove' //we create our own css with a class called 'add'
}, '-', //add a separator
{
text: 'Refresh',
tooltip: 'Click to Refresh the table',
handler: refreshGrid, //what happens when user clicks on it
iconCls:'refresh' //we create our own css with a class called 'add'
}
]
,
bbar: new Ext.PagingToolbar({
pageSize: #this.gridStr.limit#,
store: ds,
displayInfo: truefalse, //default is false (to not show displayMsg)
displayMsg: '#this.gridStr.displayMessage#',
emptyMsg: "#this.gridStr.emptyMessage#" //display message when no records found
, items:[
'-', {
pressed: true,
enableToggle:true,
text: '#this.gridStr.detailsButtonText#',
cls: 'x-btn-text-icon details',
toggleHandler: toggleDetails
}]
})
/**
* Strip xml-like tags from a string when they are within or not within a list of tags.
*
* @param stripmode A string, disallow or allow. Specifies if the list of tags in the mytags attribute is a list of tags to allow or disallow. (Required)
* @param mytags List of tags to either allow or disallow. (Required)
* @param mystring The string to check. (Required)
* @param findonly Boolean value. If true, returns the first match. If false, all instances are replaced. (Optional)
* @return Returns either a string or the first instance of a match.
* @author Isaac Dealey (info@turnkey.to)
* @version 2, September 22, 2004
*/
function stripTags(stripmode,mytags,mystring) {
var spanquotes = "([^"">]*""[^""]*"")*";
var spanstart = "[[:space:]]*/?[[:space:]]*";
var endstring = "[^>$]*?(>|$)";
var x = 1;
var currenttag = structNew();
var subex = "";
var findonly = false;
var cfversion = iif(structKeyExists(GetFunctionList(),"getPageContext"), 6, 5);
var backref = "\\1"; // this backreference works in cf 5 but not cf mx
var rexlimit = len(mystring);
if (arraylen(arguments) gt 3) { findonly = arguments[4]; }
if (cfversion gt 5) { backref = "\#backref#"; } // fix backreference for mx and later cf versions
else { rexlimit = 19000; } // limit regular expression searches to 19000 characters to support CF 5 regex character limit
if (len(trim(mystring))) {
// initialize defaults for examining this string
currenttag.pos = ListToArray("0");
currenttag.len = ListToArray("0");
mytags = ArrayToList(ListToArray(mytags)); // remove any empty items in the list
if (len(trim(mytags))) {
// turn the comma delimited list of tags with * as a wildcard into a regular expression
mytags = REReplace(mytags,"[[:space:]]","","ALL");
mytags = REReplace(mytags,"([[:punct:]])",backref,"ALL");
mytags = Replace(mytags,"\*","[^$>[:space:]]*","ALL");
mytags = Replace(mytags,"\,","[$>[:space:]]|","ALL");
mytags = "#mytags#[$>[:space:]]";
} else { mytags = "$"; } // set the tag list to end of string to evaluate the "allow nothing" condition
// loop over the string
for (x = 1; x gt 0 and x lt len(mystring); x = x + currenttag.pos[1] + currenttag.len[1] -1)
{
// find the next tag within rexlimit characters of the starting point
currenttag = REFind("<#spanquotes##endstring#",mid(mystring,x,rexlimit),1,true);
if (currenttag.pos[1])
{
// if a tag was found, compare it to the regular expression
subex = mid(mystring,x + currenttag.pos[1] -1,currenttag.len[1]);
if (stripmode is "allow" XOR REFindNoCase("^<#spanstart#(#mytags#)",subex,1,false) eq 1)
{
if (findonly) { return subex; } // return invalid tag as an error message
else { // remove the invalid tag from the string
myString = RemoveChars(myString,x + currenttag.pos[1] -1,currenttag.len[1]);
currenttag.len[1] = 0; // set the length of the tag string found to zero because it was removed
}
}
}
// no tag was found within rexlimit characters
// move to the next block of rexlimit characters -- CF 5 regex limitation
else { currenttag.pos[1] = rexlimit; }
}
}
if (findonly) { return ""; } // return an empty string indicating no invalid tags found
else { return mystring; } // return the new string discluding any invalid tags
}
/**
* Removes HTML from the string.
*
* @param string String to be modified.
* @return Returns a string.
* @author Raymond Camden (ray@camdenfamily.com)
* @version 1, December 19, 2001
*/
function StripHTML(str) {
var s = REReplaceNoCase(str,"<[^>]*>","","ALL");
return rereplacenocase(s,"\[rnt]*","","ALL");
}
function boolFormat(val){
if (val)
return 'true';
else
return 'false';
}