[% PROCESS javascript/grid/columns.tt %] [% PROCESS javascript/grid/toolbar.tt %] [% PROCESS javascript/grid/pagebar.tt %] [% PROCESS javascript/grid/view.tt %] // most of the work in the grid itself is making the filter row work // we want clickable filter fields for cols which can be filtered // and the clicks ignored on other fields, and the delete col field // and pressing return after editing should not start edit on anything // else. var grid = new Ext.grid.EditorGridPanel({ id: 'search-grid' ,renderTo: 'content' ,autoHeight: true ,autoScroll: true ,stripeRows: true ,store: store ,loadMask: true ,colModel: cm ,trackMouseOver: true ,disableSelection: true ,viewConfig: new Ext.grid.GridView({ autoFill: true ,forceFit: true //,scrollOffset: 0 ,getRowClass: function (record, index) { if (index === 0) { return 'half-grey' } } }) ,listeners: { cellclick: function(g, row, col) { var rec = g.getStore().getAt(row); var fieldName = g.getColumnModel().getDataIndex(col); // var data = rec.get(fieldName); // reset the grid selectionModel g.getSelectionModel().deselectRow(row); if (fieldName == 'lf-multi-column') { // multi rows are ignored return false; } if (fieldName == 'lf-delete-column') { if (row === 0) { // edit row is ignored return false; } var data = rec.get('[% lf.main.pk %]'); Ext.MessageBox.confirm ( 'Confirm Delete [% lf.main.title %]' ,'Are you sure you want to delete [% lf.main.title %] [% lf.main.pk %](' + data + ')?' ,function (btn) { if (btn == 'yes') { grid.loadMask.el.mask(); Ext.Ajax.request({ url: '[% c.uri_for( c.controller('LFB::Root').action_for('db_picker'), db, lf.main.path, "delete" ) %]' ,params: { key: data } ,success: function(response,options) { grid.loadMask.el.unmask(); Ext.MessageBox.alert( 'Success' ,'Entry successfully deleted.' ,function() { // XXX private parts of pagingtoolbar pagebar.doLoad(pagebar.cursor); } ); } ,failure: function(response,options) { grid.loadMask.el.unmask(); Ext.MessageBox.alert( 'Problem deleting entry' ,'Sorry, the entry could not be deleted. ' + 'Is its primary key referenced in another table?' ); } }); } } ); return false; } if (row === 0) { if (isFK(fieldName) || isCheck(fieldName)) { return false; } g.stopEditing; rec.set(fieldName, ''); g.startEditing(row,col); } else { // draw the window! var win = generate_win(); win.show(this); // handle for the form var mainform = Ext.getCmp('form-panel').getForm(); // import data from grid row mainform.loadRecord(rec); // fill in reverse relations mainform.setValues({ [% SET count = 1 %] [% FOREACH table IN lf.tab_order.keys %] [% NEXT IF lf.tab_order.item(table) == 1 %] [% FOREACH col IN lf.table_info.$table.cols.keys %] [% NEXT UNLESS lf.table_info.$table.cols.$col.is_fk AND NOT lf.table_info.$table.cols.$col.editable %] [% ',' IF count > 1 %] '[% lf.table_info.$table.path %].[% col %]': rec.data['[% lf.main.pk %]'] [% SET count = count + 1 %] [% END %] [% END %] }); } } ,beforeedit: function(e) { // cancel ENTER key driven edits from the filter row // also cancel on the filter row itself if a FK if ((e.row !== 0) || isFK(e.field) || isCheck(e.field)) { return false } } ,columnmove: function(oldidx, newidx) { // XXX private parts of pagingtoolbar pagebar.doLoad(pagebar.cursor); } } ,selModel: new Ext.grid.RowSelectionModel // req'd to deselect row ,tbar: toolbar ,bbar: pagebar });