// CREATE CONTEXT MENU
//***********************************************
function initContextMenu() {
document.write('<div id="contextmenu" class="contextmenu"></div>');
}
function writeContextMenu(content) {
var contextMenu = document.getElementById("contextmenu");
contextMenu.innerHTML = content;
}
function showContextMenu(e) {
var contextMenu = document.getElementById("contextmenu");
var frameWidth, frameHeight, pageOffsetX, pageOffsetY;
if (self.clientWidth) {
frameWidth = self.innerWidth;
frameHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientWidth) {
frameWidth = document.documentElement.clientWidth;
frameHeight = document.documentElement.clientHeight;
} else if (document.body) {
frameWidth = document.body.clientWidth;
frameHeight = document.body.clientHeight;
}
if (self.pageXOffset) {
pageOffsetX = self.pageXOffset;
pageOffsetY = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollLeft) {
pageOffsetX = document.documentElement.scrollLeft;
pageOffsetY = document.documentElement.scrollTop;
} else if (document.body) {
pageOffsetX = document.body.scrollLeft;
pageOffsetY = document.body.scrollTop;
}
if ((frameWidth - e.clientX) < contextMenu.offsetWidth) {
contextMenu.style.left = (pageOffsetX + e.clientX - contextMenu.offsetWidth) + "px";
} else {
contextMenu.style.left = e.clientX + "px";
}
if ((frameHeight - e.clientY) < contextMenu.offsetHeight) {
contextMenu.style.top = (pageOffsetY + e.clientY - contextMenu.offsetHeight) + "px";
} else {
contextMenu.style.top = e.clientY + "px";
}
contextMenu.style.visibility = "visible";
}
function hideContextMenu() {
if (document.getElementById("contextmenu")) document.getElementById("contextmenu").style.visibility = "hidden";
}
// Write the menu to page
initContextMenu();
// Set the click handler for the page
if (!document.addEventListener){
document.attachEvent("onclick", hideContextMenu);
} else {
document.addEventListener("click", hideContextMenu, false);
}
//*****************************************************
obj = new AW.UI.Grid;
// ROW CONTEXT MENU
//************************************************
function raiseMenuEvent(event){
this.raiseEvent("onCellContextMenu", event, this.$0, this.$1);
}
AW.UI.Grid.prototype.getCellTemplate().setEvent("oncontextmenu", raiseMenuEvent);
AW.UI.Grid.prototype.onCellContextMenu = function(event, row,col){
this.setRowSelected(row);
var obj = this.getId();
var contextMenuContent = '';
contextMenuContent += '<a class="menuItem" href="javascript:AW.all[\''+obj+'\'].filterGrid('+row+','+col+')">Filter by content</a>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">Filter out of content</a>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">Filter for: </a>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">Disable Filter or sort</a>';
contextMenuContent += '<div class="menuItemSep"></div>';
contextMenuContent += '<a class="menuItem" href="javascript:AW.all[\''+obj+'\'].menuSort('+col+',\'ascending\');">Sort Asscending</a>';
contextMenuContent += '<a class="menuItem" href="javascript:AW.all[\''+obj+'\'].menuSort('+col+',\'descending\');">Sort Descending</a>';
contextMenuContent += '<div class="menuItemSep"></div>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">New record</a>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">New record by Copy</a>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">Delete record</a>';
writeContextMenu(contextMenuContent);
showContextMenu(event);
}
// HEADER CONTEXT MENU
//************************************************
function raiseHeaderMenuEvent(event){
this.raiseEvent("onHeaderContextMenu", event, this.$0);
}
AW.UI.Grid.prototype.getHeaderTemplate().setEvent("oncontextmenu", raiseHeaderMenuEvent);
AW.UI.Grid.prototype.onHeaderContextMenu = function(event, col){
//this.setRowSelected(row);
var obj = this.getId();
var contextMenuContent = '';
contextMenuContent += '<a class="menuItem" href="javascript:AW.all[\''+obj+'\'].menuSort('+col+',\'ascending\');">Sort Ascending</a>';
contextMenuContent += '<a class="menuItem" href="javascript:AW.all[\''+obj+'\'].menuSort('+col+',\'descending\');">Sort Descending</a>';
contextMenuContent += '<div class="menuItemSep"></div>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionA('+col+')">Column width</a>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">Hide column</a>';
contextMenuContent += '<div class="menuItemSep"></div>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionA('+col+')">Freeze column</a>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">free freezed column</a>';
contextMenuContent += '<div class="menuItemSep"></div>';
contextMenuContent += '<a class="menuItem" href="javascript:customFunctionB()">Select columns to show</a>';
writeContextMenu(contextMenuContent);
showContextMenu(event);
}
AW.UI.Grid.prototype.menuSort = function (col,dir)
{
top.window.document.WAIS_loading.src = "images/icons/loading.gif";
top.window.document.getElementById("contextmenu").style.visibility = "hidden";
this.sort(col,dir);
this.refresh();
top.window.document.WAIS_loading.src = "images/design/blank.gif";
}
AW.UI.Grid.prototype.menuSort = function (col,dir)
{
var activeRow = this.getCurrentRow();
top.window.document.WAIS_loading.src = "images/icons/loading.gif";
top.window.document.getElementById("contextmenu").style.visibility = "hidden";
this.sort(col,dir);
this.refresh();
this.setCurrentRow([activeRow]);
this.setSelectedRows([activeRow]);
top.window.document.WAIS_loading.src = "images/design/blank.gif";
}
This topic is archived.