4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
12 Roo.BLANK_IMAGE_URL = "../../images/default/s.gif";
16 Roo.onReady(function(){
18 function formatBoolean(value){
19 return value ? 'Yes' : 'No';
22 function formatDate(value){
23 return value ? value.dateFormat('M d, Y') : '';
26 var fm = Roo.form, Ed = Roo.grid.GridEditor;
28 // the column model has information about grid columns
29 // dataIndex maps the column to the specific data field in
30 // the data store (created below)
31 var cm = new Roo.grid.ColumnModel([{
32 header: "Common Name",
36 editor: new Ed(new fm.TextField({
43 editor: new Ed(new Roo.form.ComboBox({
55 editor: new Ed(new fm.NumberField({
62 dataIndex: 'availDate',
65 editor: new Ed(new fm.DateField({
69 disabledDaysText: 'Plants are not available on the weekends'
75 renderer: formatBoolean,
76 editor: new Ed(new fm.Checkbox())
79 // by default columns are sortable
80 cm.defaultSortable = true;
82 // this could be inline, but we want to define the Plant record
83 // type so we can add records dynamically
84 var Plant = Roo.data.Record.create([
85 // the "name" below matches the tag name to read, except "availDate"
86 // which is mapped to the tag "availability"
87 {name: 'common', type: 'string'},
88 {name: 'botanical', type: 'string'},
90 {name: 'price', type: 'float'}, // automatic date conversions
91 {name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
92 {name: 'indoor', type: 'bool'}
95 // create the Data Store
96 var ds = new Roo.data.Store({
98 proxy: new Roo.data.HttpProxy({url: 'plants.xml'}),
101 // the return will be XML, so lets set up a reader
102 reader: new Roo.data.XmlReader({
103 // records will have a "plant" tag
108 // create the editor grid
109 grid = new Roo.grid.EditorGrid('editor-grid', {
114 enableDragDrop : true,
120 var layout = Roo.BorderLayout.create({
122 margins:{left:3,top:3,right:3,bottom:3},
123 panels: [new Roo.GridPanel(grid)]
132 grid.dropTarget = new Roo.dd.DropTarget(grid.view.el, {
134 drop : function (source, e, data)
137 var t = Roo.lib.Event.getTarget(e);
138 var ri = grid.view.findRowIndex(t);
145 over : function (source, e, data)
147 this.getDropPoint(e,data)
148 Roo.log([source,e,data]);
150 // Roo.log("dragover");
154 var t = Roo.lib.Event.getTarget(e);
155 var ri = _this.grid.view.findRowIndex(t);
160 rid = _this.grid.getDataSource().getAt(ri).data;
163 var s = _this.grid.getSelectionModel().getSelections();
165 //if (!isFromGroup && isToGroup) {
166 this.valid = 'ok-add';
172 getDropPoint : function(e, data)
175 // data is from griddragzone
177 var dragEl = data.ddel;
178 var t = Roo.lib.Dom.getY(dragEl),
179 b = t + dragEl.offsetHeight;
180 var y = Roo.lib.Event.getPageY(e);
181 //var noAppend = tn.allowChildren === false || tn.isLeaf();
183 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
187 if(y >= t && y < (t + q)){
190 if(!noBelow && (noAppend || y >= b-q && y <= b)){
199 var gridHead = grid.getView().getHeaderPanel(true);
200 var tb = new Roo.Toolbar(gridHead, [{
202 handler : function(){
204 common: 'New Plant 1',
205 light: 'Mostly Shade',
207 availDate: new Date(),
212 grid.startEditing(0, 0);
216 // trigger the data store load