webgui/www/extras/yui/examples/datatable/dt_contextmenu_clean.html
2008-03-25 16:13:25 +00:00

109 lines
No EOL
4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Context Menu Integration</title>
<style type="text/css">
/*margin and padding on body element
can introduce errors in determining
element position and are not recommended;
we turn them off as a foundation for YUI
CSS treatments. */
body {
margin:0;
padding:0;
}
</style>
<link rel="stylesheet" type="text/css" href="../../build/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="../../build/menu/assets/skins/sam/menu.css" />
<link rel="stylesheet" type="text/css" href="../../build/datatable/assets/skins/sam/datatable.css" />
<script type="text/javascript" src="../../build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="../../build/container/container_core-min.js"></script>
<script type="text/javascript" src="../../build/menu/menu-min.js"></script>
<script type="text/javascript" src="../../build/element/element-beta-min.js"></script>
<script type="text/javascript" src="../../build/datasource/datasource-beta-min.js"></script>
<script type="text/javascript" src="../../build/datatable/datatable-beta-min.js"></script>
<!--begin custom header content for this example-->
<style type="text/css">
div.yuimenu .bd {
zoom: normal;
}
</style>
<!--end custom header content for this example-->
</head>
<body class=" yui-skin-sam">
<h1>Context Menu Integration</h1>
<div class="exampleIntro">
<p>Right-click on a row to see the ContextMenu integration in action. For more
information on using the ContextMenu class please refer to the
<a href="http://developer.yahoo.com/yui/menu/">documentation for the Menu control.</a></p>
</div>
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
<div id="myContainer"></div>
<script type="text/javascript" src="assets/js/data.js"></script>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.ContextMenu = new function() {
var myColumnDefs = [
{key:"SKU", sortable:true},
{key:"Quantity", sortable:true},
{key:"Item", sortable:true},
{key:"Description"}
];
this.myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.inventory);
this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
this.myDataSource.responseSchema = {
fields: ["SKU","Quantity","Item","Description"]
};
this.myDataTable = new YAHOO.widget.DataTable("myContainer", myColumnDefs, this.myDataSource);
this.onContextMenuClick = function(p_sType, p_aArgs, p_myDataTable) {
var task = p_aArgs[1];
if(task) {
// Extract which TR element triggered the context menu
var elRow = this.contextEventTarget;
elRow = p_myDataTable.getTrEl(elRow);
if(elRow) {
switch(task.index) {
case 0: // Delete row upon confirmation
var oRecord = p_myDataTable.getRecord(elRow);
if(confirm("Are you sure you want to delete SKU " +
oRecord.getData("SKU") + " (" +
oRecord.getData("Description") + ")?")) {
p_myDataTable.deleteRow(elRow);
}
}
}
}
};
this.myContextMenu = new YAHOO.widget.ContextMenu("mycontextmenu",
{trigger:this.myDataTable.getTbodyEl()});
this.myContextMenu.addItem("Delete Item");
// Render the ContextMenu instance to the parent container of the DataTable
this.myContextMenu.render("myContainer");
this.myContextMenu.clickEvent.subscribe(this.onContextMenuClick, this.myDataTable);
};
});
</script>
<!--END SOURCE CODE FOR EXAMPLE =============================== -->
</body>
</html>