// ---------- StoryTable class ---------- Bxt.StoryTable = function(config) { var defaultDDgrp = 'GridDD'; var dflt = { ds : new Ext.data.Store({ proxy: new Ext.data.HttpProxy({url:'pbv/PBVAsyncHandler?action=LOAD-REQS'}), reader: new Ext.data.JsonReader( {id:'id'}, [ {name: 'id'}, {name: 'name', sortType:'asUCString'}, {name: 'status'}, {name: 'rank', type:'float', sortType: BxtUtil.rankSort }, {name: 'size', type:'int' }, {name: 'confidence'}, {name: 'submittedby', sortType: 'asUCString'}, {name: 'category', sortType:'asUCString'}, {name: 'lastupdated'}, {name: 'acceptedby'} ]), sortInfo:{field: 'rank', direction: "ASC"} }), autoExpandColumn : 'name', loadMask: {msg: '$LOADING'}, frame : true, collapsible : false, animCollapse : false, tbar : [], bbar : [], layout :'fit', headerAsText :false, renderTo : document.body, enableDragDrop : true, ddGroup : defaultDDgrp, sm : new Ext.grid.RowSelectionModel(), listeners : [{'loadexception': BxtUtil.lexHandler}] }; // apply settings Ext.apply(this, config, dflt); // construct Bxt.StoryTable.superclass.constructor.call(this); this.ddGroup = (!config.ddGroup) ? defaultDDgrp : config.ddGroup; }; Ext.extend(Bxt.StoryTable, Ext.grid.GridPanel, { /* * context menu set on this story table */ contextMenu : null, /* * selected item from context menu */ selectedContextMenuItem : null, /* * DragDrop target */ ddTarget : null, /** * DDgroup to use */ ddGroup : null, /** * Set panel contextMenu. This displays contextMenu * in the non-row areas of the grid. * @param {Object} menuItems */ setPanelContextMenu : function(menuItems) { var contextMenu = new Ext.menu.Menu(); // add menu items for(var i = 0;i < menuItems.length; i++) { contextMenu.add(menuItems[i]); } this.panelContextMenu = contextMenu; this.addListener('contextmenu', function (e) { e.stopEvent(); var coords = e.getXY(); this.selectedContextMenuItem = null; this.panelContextMenu.showAt([coords[0], coords[1]]); } ); }, /* * method to set context menu on the table * @param menuItems an array of menuItem objects */ setContextMenu : function(menuItems) { var contextMenu = new Ext.menu.Menu(); // add menu items for(var i = 0;i < menuItems.length; i++) { contextMenu.add(menuItems[i]); } this.contextMenu = contextMenu; this.addListener('rowcontextmenu', function (grid, rowIndex, e) { e.stopEvent(); var coords = e.getXY(); this.selectedContextMenuItem = this.getStore().getAt(rowIndex); this.contextMenu.showAt([coords[0], coords[1]]); } ); }, /* * method to set up drag and drop of table rows * @param ddOnOffFn function to be called to enable/disable drag and drop * @param customNotifyDropFn custom function for handling drag-drop * @param ddrankFn function to call after changing the rank of the story. It is * called with parameters (dd, e, data) */ setDragDropHandler : function( ddOnOffFn, customNotifyDropFn, ddrankFn) { // set dragdroptext this.getDragDropText = function() { var count = this.selModel.getCount(); var selections = this.selModel.selections; var result = ''; for(i = 0; i < count; i ++) { var rec = selections.get(i); if(i>0) result += ", "; result += rec.data.name; } return result; } this.ddRankFn = ddrankFn; var customNotifyDropFncDelegate = (customNotifyDropFn) ? customNotifyDropFn.createDelegate(this): null; var ndFn = customNotifyDropFncDelegate || this.dfltNotifyDrop.createDelegate(this); this.ddTarget = new Ext.dd.DropTarget(this.getEl(), { ddGroup : this.ddGroup, copy:false, containerScroll : true, notifyDrop : ndFn, notifyOver : this.dfltNotifyOver.createDelegate(this) } ); // For row drag and drop scrolling . Ext.dd.ScrollManager.register(this.view.scroller); if (ddOnOffFn) { this.on("headerclick", ddOnOffFn); } this.ddTarget.unlock(); }, // ---- default notifyDrop handler dfltNotifyDrop : function (dd, e, data) { var ddat = dd.getDragData(e); if(ddat.grid == undefined) { // for across-grid DD. return false; } var ds = ddat.grid.getStore(); var state = ds.getSortState(); var rows = data.selections; // check direction var sdir = (state.direction == 'ASC'); if (!sdir) { return; } var cindex = ddat.rowIndex; if(cindex == undefined) { return; } BxtRanks.buildRankString(ddat.grid.ddRankFn, cindex, rows, ds); }, // ---- default notifyDrop handler dfltNotifyOver : function (dd, e, data) { var ddat = dd.getDragData(e); if(ddat.grid == undefined) { // for across-grid DD. return dd.dropNotAllowed; } var srcGrid = ddat.grid; if(srcGrid != this) return dd.dropNotAllowed;; var cindex = ddat.rowIndex; if(cindex == undefined) { return dd.dropNotAllowed;; } return dd.dropAllowed; } });