Code:
Ext.apply(Ext.util.Format, {
/** groupCombo
* splits the value of the record on "," and turns it into a combo box component
* @param {String} value
* @param {Object} metaData
* @param {Object} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Object} store
* @return {String}
*/
groupCombo : function (value, metaData, record, rowIndex, colIndex, store) {
var list,
divId = 'delayedRender'+Math.floor(Math.random()*999999999),
divHtml = '<div id=' + divId + '></div>',
comboBox, n;
if (!Ext.isEmpty(value)) {
list = value.split(',');
} else {
list = [];
}
for(n=0;n<list.length;n++){
list[n] = [list[n]];
}
comboBox = {
xtype : 'combo',
displayField:'disp',
typeAhead: true,
preventMark :true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
cls : 'x-combo-in-grid-cell',
ctCls : 'x-combo-in-grid-cell',
itemCls : 'x-combo-in-grid-cell',
selectOnFocus:true,
width : 'auto',
clearChildWidth : true,
//autoWidth : true,
//layout : 'fit',
autoLoad : true,
value : list[0],
editable : true,
renderTo : divId,
store : new Ext.data.ArrayStore({
fields : ['disp'],
data : list,
autoLoad : true
})
};
if (Ext.isEmpty(record.delayedRenders)) {
record.delayedRenders = [];
}
record.delayedRenders.push(comboBox);
return divHtml;
},
/** groupComboWS
* splits the value of the record on a special deliniater "--*--" and turns it into a combo box component
* @param {String} value
* @param {Object} metaData
* @param {Object} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Object} store
* @return {String}
*/
groupComboWS : function (value, metaData, record, rowIndex, colIndex, store) {
var list,
divId = 'delayedRender'+Math.floor(Math.random()*999999999),
divHtml = '<div id=' + divId + '></div>',
comboBox, n;
if (!Ext.isEmpty(value)) {
list = value.split('--*--');
} else {
list = [];
}
for(n=0;n<list.length;n++){
list[n] = [list[n]];
}
comboBox = {
xtype : 'combo',
displayField:'disp',
typeAhead: true,
preventMark :true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
cls : 'x-combo-in-grid-cell',
ctCls : 'x-combo-in-grid-cell',
itemCls : 'x-combo-in-grid-cell',
selectOnFocus:true,
autoLoad : true,
autoWidth : true,
editable : true,
value : list[0],
renderTo : divId,
store : new Ext.data.ArrayStore({
fields : ['disp'],
data : list,
autoLoad : true
})
};
if (Ext.isEmpty(record.delayedRenders)) {
record.delayedRenders = [];
}
record.delayedRenders.push(comboBox);
return divHtml;
},
/** variableCellRenderer
* takes a value like so: [formater_name]|value to formate. The value is passed to the formater specified and the result is returned. This is used to allow the return from the server to dictate what formater should be used for the cell.
* @param {String} value
* @param {Object} metaData
* @param {Object} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Object} store
*/
variableCellRenderer : function (value, metaData, record, rowIndex, colIndex, store) {
//delayedRender are handled in the onload function of analytics grid
if(!Ext.isEmpty(value)) {
var stringSplit = value.split('|'),
renderer = stringSplit[0],
value = stringSplit[1],
returnValue = Ext.util.Format[renderer](value, metaData, record, rowIndex, colIndex, store);
return returnValue;
}
},
/** cellAction
* creates a button named after the grid column. When clicked the button will execute javascript that was stored in the value.
* This formattter is deprecated in favor of cellButtonAction.
* @param {String} value
* @param {Object} metaData
* @param {Object} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Object} store
* @return {String}
*/
cellAction : function (value, metaData, record, rowIndex, colIndex, store) {
var divId = 'delayedRender'+Math.floor(Math.random()*999999999),
divHtml = '<div id=' + divId + '></div>', button;
button = {
xtype : 'button',
text : metaData.id,
evalString : value,
renderTo : divId,
handler : function () {
eval(this.evalString);
}
};
if (Ext.isEmpty(record.delayedRenders)) {
record.delayedRenders = [];
}
record.delayedRenders.push(button);
return divHtml;
},
/** mp3Player
* Creates a dew player mp3 player where the location of the mp3 file to play is the value of the cell. !For use in 3rd party products the location of the dewplayer.swl will need to be modified.
* @param {String} value
* @param {Object} metaData
* @param {Object} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Object} store
* @return {String}
*/
mp3Player : function (value, metaData, record, rowIndex, colIndex, store) {
if(!Ext.isEmpty(value)) {
var divId = 'delayedRender'+Math.floor(Math.random()*999999999),
divHtml = '<div id=' + divId + '></div>', panel,
playerHtml = '<object data="/js_library/dewplayer/dewplayer.swf" width="200" height="20" name="dewplayer" id="dewplayer" type="application/x-shockwave-flash"><param name="movie" value="dewplayer.swf" /><param name="flashvars" value="mp3=' + value + '&javascript=on" /><param name="wmode" value="transparent" /></object>';
panel = {
xtype : 'panel',
//We may need a call recording url in the origination table becuse the call will not alway be in the same account so the account id and the call id will be needed
html: playerHtml,
dataIndex : metaData.id,
sourceRecord : record,
width : 'auto',
clearChildWidth : true,
cls : 'x-button-in-grid-cell',
ctCls : 'x-button-in-grid-cell',
itemCls : 'x-button-in-grid-cell',
renderTo : divId
};
if (Ext.isEmpty(record.delayedRenders)) {
record.delayedRenders = [];
}
record.delayedRenders.push(panel);
return divHtml;
}
},
/** cellButtonAction
* Creates button based on the return from the server. value should be formated: [test to display on the button]|[function to call when button is pressed]|[scope to evaluate the function call in]
* @param {String} value
* @param {Object} metaData
* @param {Object} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Object} store
* @return {String}
*/
cellButtonAction : function (value, metaData, record, rowIndex, colIndex, store) {
if(!Ext.isEmpty(value)) {
var divId = 'delayedRender'+Math.floor(Math.random()*999999999),
divHtml = '<div id=' + divId + '></div>', button,
stringSplit = value.split('|'),
text = (stringSplit[0]=='null')?metaData.id:stringSplit[0],
functionName = stringSplit[1],
arguments = stringSplit[2],
evalScope = (Ext.isEmpty(stringSplit[3]))?'this':stringSplit[3];
button = {
xtype : 'button',
text : text,
dataIndex : metaData.id,
sourceRecord : record,
iconCls: "icon-cellaction",
width : 'auto',
clearChildWidth : true,
cls : 'x-button-in-grid-cell',
ctCls : 'x-button-in-grid-cell',
itemCls : 'x-button-in-grid-cell',
evalFunction : eval(functionName),
evalArguments : eval(arguments),
evalScope : eval(evalScope),
renderTo : divId,
handler : Ext.util.Format.evalCellAction
};
if (Ext.isEmpty(record.delayedRenders)) {
record.delayedRenders = [];
}
record.delayedRenders.push(button);
return divHtml;
}
},
/** cellCheckBoxAction
* Creates checb box based on the return from the server. value should be formated: [checked true or false]|[function to call when button is pressed]|[scope to evaluate the function call in]
* @param {String} value
* @param {Object} metaData
* @param {Object} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Object} store
* @return {String}
*/
cellCheckBoxAction : function (value, metaData, record, rowIndex, colIndex, store) {
if(!Ext.isEmpty(value)) {
//delayedRender are handled in the onload function of analytics grid
var divId = 'delayedRender'+Math.floor(Math.random()*999999999),
divHtml = '<div id=' + divId + '></div>', button,
stringSplit = value.split('|'),
checked = (stringSplit[0]=='true'||stringSplit[0]==1||stringSplit[0]=='1')?true:false,
functionName = stringSplit[1],
arguments = stringSplit[2],
evalScope = (Ext.isEmpty(stringSplit[3]))?'this':stringSplit[3];
checkBox = {
xtype : 'checkbox',
checked : checked,
value : checked,
dataIndex : metaData.id,
sourceRecord : record,
evalFunction : eval(functionName),
evalArguments : eval(arguments),
evalScope : eval(evalScope),
renderTo : divId,
useGetRawValue : true,
listeners : {
'click' : Ext.util.Format.evalCellAction
}
};
if (Ext.isEmpty(record.delayedRenders)) {
record.delayedRenders = [];
}
record.delayedRenders.push(checkBox);
return divHtml;
}
},
/** cellComboBoxAction
* Creates ComboBox box based on the return from the server. value should be formated: [initially selected value]|[an array in json format of names to go in the combo box]|[an array in json format of values to go in the combo box]
* @param {String} value
* @param {Object} metaData
* @param {Object} record
* @param {Number} rowIndex
* @param {Number} colIndex
* @param {Object} store
* @return {String}
*/
cellComboBoxAction : function (value, metaData, record, rowIndex, colIndex, store) {
if(!Ext.isEmpty(value)) {
//delayedRender are handled in the onload function of analytics grid
var divId = 'delayedRender'+Math.floor(Math.random()*999999999),
divHtml = '<div id=' + divId + '></div>', button,
stringSplit = value.split('|'),
value = stringSplit[0],
names = Ext.decode(stringSplit[1]),
values = Ext.decode(stringSplit[2]),
functionName = stringSplit[3],
arguments = stringSplit[4],
evalScope = (Ext.isEmpty(stringSplit[5]))?'this':stringSplit[5],
data=[], n;
for(n=0;n<names.length;n++){
data.push({
name : names[n],
value : values[n]
});
}
comboBox = {
xtype : 'combo',
value : value,
dataIndex : metaData.id,
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
selectOnFocus:true,
sourceRecord : record,
evalFunction : eval(functionName),
evalArguments : eval(arguments),
evalScope : eval(evalScope),
renderTo : divId,
useGetRawValue : false,
displayField:'name',
valueField:'value',
listeners : {
'select' : Ext.util.Format.evalCellAction
},
store : new Ext.data.JsonStore({
fields : ['name', 'value'],
data : data
})
};
if (Ext.isEmpty(record.delayedRenders)) {
record.delayedRenders = [];
}
record.delayedRenders.push(comboBox);
return divHtml;
}
},
/** evalCellAction
* Evaluates an function attached to component component created as a delayed render component
* @private
*/
evalCellAction : function () {
var evalFunction = this.evalFunction,
arguments = this.evalArguments,
evalScope = this.evalScope,
record = this.sourceRecord,
components = record.components,
params = (typeof(arguments[0])=='string' && /^['"]?[\[\{].+[\]\}]['"]?$/.test(arguments[0]))?Ext.decode(arguments[0]):arguments[0],
obj, n, colValue, capturedValues={};
if (Ext.isObject(params)) {
for (obj in record.data) {
colValue = null;
if (!Ext.isEmpty(components)) {
for (n=0; n<components.length; n++) {
if (components[n].dataIndex == obj) {
if (!Ext.isEmpty(components[n].useGetRawValue) && components[n].useGetRawValue) {
if (!Ext.isEmpty(components[n].getRawValue)) {
colValue = components[n].getRawValue();
break;
}
} else if (!Ext.isEmpty(components[n].useGetOutputValue) && components[n].useGetOutputValue) {
if (!Ext.isEmpty(components[n].useGetOutputValue)) {
colValue = components[n].getOutputValue();
break;
}
} else {
if (!Ext.isEmpty(components[n].getValue)) {
colValue = components[n].getValue();
break;
}
}
}
}
}
if (Ext.isEmpty(colValue)) {
colValue = record.data[obj];
}
capturedValues[obj] = colValue;
}
params['caputredValues'] = capturedValues;
arguments[0] = params;
}
evalFunction.apply(evalScope, arguments);
}
});
Best regards