[ create a new paste ] login | about

Link: http://codepad.org/GJkXWAZN    [ raw code | fork ]

PHP, pasted on Oct 28:
YAHOO.util.Event.onDOMReady(function() { 

YAHOO.namespace("techdocs");		// create namespace for Insert dialog

	// XMLDocs datatable
	YAHOO.techdocs.xmldocs = function(){
				
		// view Record ToolTip
		var view = function(el) {
			el.title = 'View XMLDoc';
		};		

		// edit Record ToolTip
		var edit = function(el, oRecord) {
			//YAHOO.util.Dom.generateId( el ); 
			// console.log("XMLDocID: " + oRecord.getData('XMLDocID') + ", AuthorID: " + oRecord.getData('AuthorID') + ",  EditorID: " + oRecord.getData('EditorID') + ",  ReviewerID: " + oRecord.getData('ReviewerID') + ",  PublisherID: " + oRecord.getData('PublisherID'));
			if(oRecord.getData('AuthorID') ==YAHOO.techdocs.myuserid || oRecord.getData('Editor') ==YAHOO.techdocs.myuserid) {
			//	console.log(YAHOO.techdocs.myuserid);
				YAHOO.util.Dom.addClass(el, 'edit-button');
			} 
		};		


		// Columns to actually be displayed in sDataTable
		var sColumnDefs = [
			{key:"Title", label: "Title", sortable:true},
			{key:"TaskDesc", label: "Description"},
			{key:"XMLDocURI", sortable:true},
			{key:"XMLDocFilename", sortable:true},
			{key:'edit', label:' ', action:'edit', formatter: edit},
			{key:'view', label:' ', className: 'view-button', action:'view', formatter: view}
			];

		// Config variables for sDataTable
		var sConfigs = {
				scrollable: "true",
				height:  "400px",
				selectionMode: "single",
				sortedBy:{
				key: 'Title',
				dir: YAHOO.widget.DataTable.CLASS_ASC
				}
			};


		// make Ajax call to get data
		var sDataSource = new YAHOO.util.XHRDataSource('xmldocs_db.php?action=select_myxmldocs');
		sDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
		
		// responseSchema specifies the columns to pass into the datatable object	
		sDataSource.responseSchema = {resultsList: "resultsList", fields: [{key: "XMLDocID"}, {key: "Title"}, {key: "TaskDesc"}, {key: "XMLDocURI"}, {key: "XMLDocFilename"}, {key: "AuthorID"}, {key: "EditorID"}, {key: "ReviewerID"}, {key: "PublisherID"}, {key: "CreatedOn"}, {key: "UpdatedOn"}, {key: "Standard"}, {key: "TextEntityFilename"}],
			metaFields : { myuserid : "myuserid" }
		};
		
		// display the datatable
		var sDataTable = new YAHOO.widget.DataTable("xmldocs", sColumnDefs, sDataSource, sConfigs);

		// select first row of datatable
		YAHOO.techdocs.firstRow = function(){
			sDataTable.selectRow(sDataTable.getFirstTrEl());				// select the first row
		};

		sDataTable.subscribe("initEvent", YAHOO.techdocs.firstRow);	       // select first row on load

		sDataTable.subscribe('dataReturnEvent',function (e) { YAHOO.techdocs.myuserid = e.response.meta.myuserid; }); // get myuserid from json response
		sDataTable.subscribe('rowClickEvent', sDataTable.onEventSelectRow);	// enable selecting rows

		//onCellClick to Delete Record with Ajax Function

		var onCellClick = function(oArgs) {
			alert("onCellClick");
//			try{
//				   alert("working:" + YAHOO.lang.dump(oArgs));
//				}catch (err){
//				   alert("err:" + YAHOO.lang.dump(oArgs));
//				}
			};
			
		sDataTable.subscribe('cellClickEvent', function (oArgs) {alert(YAHOO.lang.dump(oArgs));});					// call onCellClick when a cell is clicked
//		sDataTable.subscribe('cellClickEvent', onCellClick);					// call onCellClick when a cell is clicked
	}();


	
});


Create a new paste based on this one


Comments: