kers
30 Sep 2009, 1:36 AM
Hi,
i have taken the drag and rop between grids example and have it mostly working with our setup, but I am unsure how to submit this changes to the database.
Ext.ns('itkb.innerSoftwarePatch');
itkb.innerSoftwarePatch.reader = function () {
var cfg = {
fields: ['id', 'software_id', 'patch_id', 'pt_id', {
name: 'from_date',
type: 'date',
dateFormat: 'c'
},
'name', 'modified_by', 'modified_date', 'description', 'version', 'sub_version', 'build_number', {
name: 'date_available',
type: 'date',
dateFormat: 'c'
}]
};
return itkb.entity.reader(cfg);
}
itkb.innerSoftwarePatch.firstStore = function (config) {
var cfg = Ext.apply({},
config, {
entity: 'software_patches_applied',
reader: itkb.innerSoftwarePatch.reader(),
sortInfo: {
field: 'name',
direction: 'asc'
}
});
return itkb.entity.store(cfg);
}
itkb.innerSoftwarePatch.secondStore = function (config) {
var cfg = Ext.apply({},
config, {
entity: 'software_patches_available',
reader: itkb.innerSoftwarePatch.reader(),
sortInfo: {
field: 'name',
direction: 'asc'
}
});
return itkb.entity.store(cfg);
}
itkb.innerSoftwarePatch.demo = function (config) {
// Column Model shortcut array
var cols = [{
id: 'name',
header: "Name",
sortable: true,
dataIndex: 'name'
},
{
header: "Description",
width: 300,
sortable: true,
dataIndex: 'description'
},
{
header: "Version",
width: 100,
sortable: true,
dataIndex: 'version'
},
{
header: "Sub Version",
width: 100,
sortable: true,
dataIndex: 'sub_version'
},
{
header: "Build Number",
width: 100,
sortable: true,
dataIndex: 'build_number'
},
{
header: "Date Available",
width: 80,
sortable: true,
dataIndex: 'date_available',
xtype: 'datecolumn',
format: 'd/m/Y'
},
{
header: "Applied Date",
width: 80,
sortable: true,
dataIndex: 'from_date',
xtype: 'datecolumn',
format: 'd/m/Y'
}];
// declare the source Grid
var firstGrid = new Ext.grid.GridPanel({
id: 'firstGrid',
ddGroup: 'secondGridDDGroup',
store: itkb.innerSoftwarePatch.firstStore(config),
columns: cols,
enableDragDrop: true,
stripeRows: true,
autoExpandColumn: 'name',
flex: 1,
title: 'Applied Software Patches'
});
// create the destination Grid
var secondGrid = new Ext.grid.GridPanel({
id: 'secondGrid',
ddGroup: 'firstGridDDGroup',
store: itkb.innerSoftwarePatch.secondStore(config),
columns: cols,
enableDragDrop: true,
stripeRows: true,
autoExpandColumn: 'name',
flex: 1,
title: 'Available Software Patches'
});
//Simple 'border layout' panel to house both grids
var displayPanel = new Ext.Panel({
layout: 'vbox',
items: [
firstGrid, secondGrid],
bbar: [{
text: 'Drag and drop patch when it has been applied to the software'
}]
});
// used to add records to the destination stores
var blankRecord = Ext.data.Record.create(itkb.innerSoftwarePatch.reader);
//Setup Drop Targets
// This will make sure we only drop to the view container
Ext.getCmp('firstGrid').on('render', function () {
var firstGridDropTargetEl = Ext.getCmp('firstGrid').getView().el.dom.childNodes[0].childNodes[1];
var firstGridDropTarget = new Ext.dd.DropTarget(firstGridDropTargetEl, {
ddGroup: 'firstGridDDGroup',
copy: true,
notifyDrop: function (ddSource, e, data) {
// Generic function to add records.
function addRow(record, index, allItems) {
// Search for duplicates
var foundItem = Ext.getCmp('firstGrid').getStore().findExact('id', record.data.name);
// if not found
if (foundItem == -1) {
Ext.getCmp('firstGrid').getStore().add(record);
// Call a sort dynamically
//Ext.getCmp('firstGrid').getStore().sort('name', 'ASC');
//Remove Record from the source
ddSource.grid.store.remove(record);
Ext.getCmp('firstGrid').submit({
url: 'cfc/actions.cfc',
params: {
method: 'add',
entity: 'software_patches_applied',
software_id: '1',
from_date: '',
patch_id: '3'
}
});
}
}
// Loop through the selections
Ext.each(ddSource.dragData.selections, addRow);
return (true);
}
});
});
Ext.getCmp('secondGrid').on('render', function () {
// This will make sure we only drop to the view container
var secondGridDropTargetEl = Ext.getCmp('secondGrid').getView().el.dom.childNodes[0].childNodes[1]
var destGridDropTarget = new Ext.dd.DropTarget(secondGridDropTargetEl, {
ddGroup: 'secondGridDDGroup',
copy: false,
notifyDrop: function (ddSource, e, data) {
// Generic function to add records.
function addRow(record, index, allItems) {
// Search for duplicates
//var foundItem = itkb.innerSoftwarePatch.secondStore.findExact('name', record.data.name);
// if not found
//if (foundItem == -1) {
itkb.innerSoftwarePatch.secondStore.insert(record);
// Call a sort dynamically
itkb.innerSoftwarePatch.secondStore.sort('name', 'ASC');
//Remove Record from the source
ddSource.grid.store.remove(record);
//}
}
// Loop through the selections
Ext.each(ddSource.dragData.selections, addRow);
return (true);
}
});
});
return displayPanel;
};Thanks for any help offered.
i have taken the drag and rop between grids example and have it mostly working with our setup, but I am unsure how to submit this changes to the database.
Ext.ns('itkb.innerSoftwarePatch');
itkb.innerSoftwarePatch.reader = function () {
var cfg = {
fields: ['id', 'software_id', 'patch_id', 'pt_id', {
name: 'from_date',
type: 'date',
dateFormat: 'c'
},
'name', 'modified_by', 'modified_date', 'description', 'version', 'sub_version', 'build_number', {
name: 'date_available',
type: 'date',
dateFormat: 'c'
}]
};
return itkb.entity.reader(cfg);
}
itkb.innerSoftwarePatch.firstStore = function (config) {
var cfg = Ext.apply({},
config, {
entity: 'software_patches_applied',
reader: itkb.innerSoftwarePatch.reader(),
sortInfo: {
field: 'name',
direction: 'asc'
}
});
return itkb.entity.store(cfg);
}
itkb.innerSoftwarePatch.secondStore = function (config) {
var cfg = Ext.apply({},
config, {
entity: 'software_patches_available',
reader: itkb.innerSoftwarePatch.reader(),
sortInfo: {
field: 'name',
direction: 'asc'
}
});
return itkb.entity.store(cfg);
}
itkb.innerSoftwarePatch.demo = function (config) {
// Column Model shortcut array
var cols = [{
id: 'name',
header: "Name",
sortable: true,
dataIndex: 'name'
},
{
header: "Description",
width: 300,
sortable: true,
dataIndex: 'description'
},
{
header: "Version",
width: 100,
sortable: true,
dataIndex: 'version'
},
{
header: "Sub Version",
width: 100,
sortable: true,
dataIndex: 'sub_version'
},
{
header: "Build Number",
width: 100,
sortable: true,
dataIndex: 'build_number'
},
{
header: "Date Available",
width: 80,
sortable: true,
dataIndex: 'date_available',
xtype: 'datecolumn',
format: 'd/m/Y'
},
{
header: "Applied Date",
width: 80,
sortable: true,
dataIndex: 'from_date',
xtype: 'datecolumn',
format: 'd/m/Y'
}];
// declare the source Grid
var firstGrid = new Ext.grid.GridPanel({
id: 'firstGrid',
ddGroup: 'secondGridDDGroup',
store: itkb.innerSoftwarePatch.firstStore(config),
columns: cols,
enableDragDrop: true,
stripeRows: true,
autoExpandColumn: 'name',
flex: 1,
title: 'Applied Software Patches'
});
// create the destination Grid
var secondGrid = new Ext.grid.GridPanel({
id: 'secondGrid',
ddGroup: 'firstGridDDGroup',
store: itkb.innerSoftwarePatch.secondStore(config),
columns: cols,
enableDragDrop: true,
stripeRows: true,
autoExpandColumn: 'name',
flex: 1,
title: 'Available Software Patches'
});
//Simple 'border layout' panel to house both grids
var displayPanel = new Ext.Panel({
layout: 'vbox',
items: [
firstGrid, secondGrid],
bbar: [{
text: 'Drag and drop patch when it has been applied to the software'
}]
});
// used to add records to the destination stores
var blankRecord = Ext.data.Record.create(itkb.innerSoftwarePatch.reader);
//Setup Drop Targets
// This will make sure we only drop to the view container
Ext.getCmp('firstGrid').on('render', function () {
var firstGridDropTargetEl = Ext.getCmp('firstGrid').getView().el.dom.childNodes[0].childNodes[1];
var firstGridDropTarget = new Ext.dd.DropTarget(firstGridDropTargetEl, {
ddGroup: 'firstGridDDGroup',
copy: true,
notifyDrop: function (ddSource, e, data) {
// Generic function to add records.
function addRow(record, index, allItems) {
// Search for duplicates
var foundItem = Ext.getCmp('firstGrid').getStore().findExact('id', record.data.name);
// if not found
if (foundItem == -1) {
Ext.getCmp('firstGrid').getStore().add(record);
// Call a sort dynamically
//Ext.getCmp('firstGrid').getStore().sort('name', 'ASC');
//Remove Record from the source
ddSource.grid.store.remove(record);
Ext.getCmp('firstGrid').submit({
url: 'cfc/actions.cfc',
params: {
method: 'add',
entity: 'software_patches_applied',
software_id: '1',
from_date: '',
patch_id: '3'
}
});
}
}
// Loop through the selections
Ext.each(ddSource.dragData.selections, addRow);
return (true);
}
});
});
Ext.getCmp('secondGrid').on('render', function () {
// This will make sure we only drop to the view container
var secondGridDropTargetEl = Ext.getCmp('secondGrid').getView().el.dom.childNodes[0].childNodes[1]
var destGridDropTarget = new Ext.dd.DropTarget(secondGridDropTargetEl, {
ddGroup: 'secondGridDDGroup',
copy: false,
notifyDrop: function (ddSource, e, data) {
// Generic function to add records.
function addRow(record, index, allItems) {
// Search for duplicates
//var foundItem = itkb.innerSoftwarePatch.secondStore.findExact('name', record.data.name);
// if not found
//if (foundItem == -1) {
itkb.innerSoftwarePatch.secondStore.insert(record);
// Call a sort dynamically
itkb.innerSoftwarePatch.secondStore.sort('name', 'ASC');
//Remove Record from the source
ddSource.grid.store.remove(record);
//}
}
// Loop through the selections
Ext.each(ddSource.dragData.selections, addRow);
return (true);
}
});
});
return displayPanel;
};Thanks for any help offered.