Changeset 10
- Timestamp:
- 08/25/08 03:26:33 (4 years ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
CHANGELOG (modified) (1 diff)
-
src/BufferedRowSelectionModel.js (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG
r8 r10 1 Version 0.1.2 1 2 - fixes: 3 - BufferedRowSelectionModel: "selectRow()" would allow selecting indexes greater than 4 the "totalLength"-property of the store; added condition to check whether the index is 5 out of bounds (closes google issue 5) 6 7 Version 0.1.2 2 8 25-August-2008 3 9 -
trunk/src/BufferedRowSelectionModel.js
r4 r10 2 2 * Ext.ux.grid.BufferedRowSelectionModel V0.1 3 3 * Copyright(c) 2007, http://www.siteartwork.de 4 * 4 * 5 5 * Licensed under the terms of the Open Source LGPL 3.0 6 6 * http://www.gnu.org/licenses/lgpl.html … … 12 12 13 13 Ext.ux.grid.BufferedRowSelectionModel = function(config) { 14 14 15 15 16 16 this.addEvents({ 17 17 /** 18 * The selection dirty event will be triggered in case records were 19 * inserted/ removed at view indexes that may affect the current 20 * selection ranges which are only represented by view indexes, but not 18 * The selection dirty event will be triggered in case records were 19 * inserted/ removed at view indexes that may affect the current 20 * selection ranges which are only represented by view indexes, but not 21 21 * current record-ids 22 22 */ 23 23 'selectiondirty' : true 24 }); 25 26 27 28 24 }); 25 26 27 28 29 29 Ext.apply(this, config); 30 30 31 31 this.bufferedSelections = {}; 32 32 33 33 this.pendingSelections = {}; 34 34 35 35 Ext.ux.grid.BufferedRowSelectionModel.superclass.constructor.call(this); 36 36 37 37 }; 38 38 39 39 Ext.extend(Ext.ux.grid.BufferedRowSelectionModel, Ext.grid.RowSelectionModel, { 40 41 40 41 42 42 // private 43 43 initEvents : function() 44 44 { 45 45 Ext.ux.grid.BufferedRowSelectionModel.superclass.initEvents.call(this); 46 46 47 47 this.grid.store.on('add', this.onAdd, this); 48 48 this.grid.store.on('selectionsload', this.onSelectionsLoad, this); 49 }, 50 51 52 49 }, 50 51 52 53 53 // private 54 54 onRefresh : function() … … 66 66 this.fireEvent("selectionchange", this); 67 67 }*/ 68 }, 69 70 71 68 }, 69 70 71 72 72 /** 73 73 * Callback is called when a row gets removed in the view. The process to … … 83 83 * If r defaults to <tt>null</tt> and index is within the pending selections 84 84 * range, the selectionchange event will be called, too. 85 * Additionally, the method will shift all selections and trigger the 85 * Additionally, the method will shift all selections and trigger the 86 86 * selectiondirty event if any selections are pending. 87 87 * … … 89 89 onRemove : function(v, index, r) 90 90 { 91 // if index equals to Number.MIN_VALUE or Number.MAX_VALUE, mark current 91 // if index equals to Number.MIN_VALUE or Number.MAX_VALUE, mark current 92 92 // pending selections as dirty 93 93 if ((index == Number.MIN_VALUE || index == Number.MAX_VALUE)) { … … 95 95 this.fireEvent('selectiondirty', this, index, r); 96 96 return; 97 } 98 97 } 98 99 99 var viewIndex = index; 100 100 var fire = this.bufferedSelections[viewIndex] === true; 101 101 var ranges = this.getPendingSelections(); 102 102 var rangesLength = ranges.length; 103 104 103 104 105 105 delete this.bufferedSelections[viewIndex]; 106 delete this.pendingSelections[viewIndex]; 107 106 delete this.pendingSelections[viewIndex]; 107 108 108 if (r) { 109 109 this.selections.remove(r); 110 } 111 110 } 111 112 112 if (rangesLength == 0) { 113 113 this.shiftSelections(viewIndex, -1); 114 } else { 114 } else { 115 115 var s = ranges[0]; 116 116 var e = ranges[rangesLength-1]; … … 119 119 this.shiftSelections(viewIndex, -1); 120 120 } 121 } 122 } 123 121 } 122 } 123 124 124 if (fire) { 125 this.fireEvent('selectionchange', this); 125 this.fireEvent('selectionchange', this); 126 126 } 127 127 }, … … 130 130 /** 131 131 * If records where added to the store, this method will work as a callback. 132 * The method gets usually called <b>after</b> the onAdd method of the according 132 * The method gets usually called <b>after</b> the onAdd method of the according 133 133 * view was called. 134 134 * Selections will be shifted down if, and only if, the listeners for the … … 140 140 var ranges = this.getPendingSelections(); 141 141 var rangesLength = ranges.length; 142 143 // if index equals to Number.MIN_VALUE or Number.MAX_VALUE, mark current 142 143 // if index equals to Number.MIN_VALUE or Number.MAX_VALUE, mark current 144 144 // pending selections as dirty 145 145 if ((index == Number.MIN_VALUE || index == Number.MAX_VALUE)) { 146 146 147 147 // we may shift selections if there are no pendning selections. Everything 148 148 // in the current buffer range will be shifted up! … … 150 150 this.shiftSelections(this.grid.getStore().bufferRange[0], records.length); 151 151 } 152 152 153 153 this.fireEvent('selectiondirty', this, index, records.length); 154 154 return; 155 } 156 155 } 156 157 157 if (rangesLength == 0) { 158 158 this.shiftSelections(this.grid.getStore().bufferRange[0]+index, records.length); … … 160 160 } 161 161 162 // it is safe to say that the selection is dirty when the inserted index 163 // is less or equal to the first selection range index or less or equal 162 // it is safe to say that the selection is dirty when the inserted index 163 // is less or equal to the first selection range index or less or equal 164 164 // to the last selection range index 165 165 var s = ranges[0]; … … 172 172 } 173 173 }, 174 175 176 174 175 176 177 177 /** 178 178 * Shifts current/pending selections. This method can be used when rows where … … 186 186 var newRequests = {}; 187 187 var totalLength = this.grid.store.totalLength; 188 188 189 189 this.last = false; 190 190 191 191 for (var i in this.bufferedSelections) { 192 192 index = parseInt(i); … … 195 195 break; 196 196 } 197 197 198 198 if (index >= startRow) { 199 199 newSelections[newIndex] = true; 200 200 201 201 if (this.pendingSelections[i]) { 202 202 newRequests[newIndex] = true; 203 203 } 204 204 205 205 } else { 206 206 newSelections[i] = true; 207 207 208 208 if (this.pendingSelections[i]) { 209 209 newRequests[i] = true; 210 210 } 211 211 } 212 } 213 212 } 213 214 214 this.bufferedSelections = newSelections; 215 215 this.pendingSelections = newRequests; 216 216 }, 217 218 /** 219 * 220 * @param {Array} records The records that have been loaded 217 218 /** 219 * 220 * @param {Array} records The records that have been loaded 221 221 * @param {Array} ranges An array representing the model index ranges the 222 222 * reords have been loaded for. … … 225 225 { 226 226 this.pendingSelections = {}; 227 227 228 228 this.selections.addAll(records); 229 230 }, 231 229 230 }, 231 232 232 /** 233 233 * Returns true if there is a next record to select … … 238 238 return this.last !== false && (this.last+1) < this.grid.store.getTotalCount(); 239 239 }, 240 240 241 241 /** 242 242 * Gets the number of selected rows. … … 246 246 { 247 247 var sels = this.bufferedSelections; 248 248 249 249 var c = 0; 250 250 for (var i in sels) { 251 c++; 252 } 253 251 c++; 252 } 253 254 254 return c; 255 }, 256 255 }, 256 257 257 /** 258 258 * Returns True if the specified row is selected. … … 265 265 return this.bufferedSelections[index] === true; 266 266 } 267 267 268 268 var r = index; 269 269 return (r && this.selections.key(r.id) ? true : false); 270 }, 271 272 273 270 }, 271 272 273 274 274 /** 275 275 * Deselects a row. … … 282 282 this.last = false; 283 283 } 284 284 285 285 if(this.lastActive == index){ 286 286 this.lastActive = false; 287 287 } 288 288 var r = this.grid.store.getAt(index); 289 289 290 290 delete this.pendingSelections[index]; 291 291 delete this.bufferedSelections[index]; … … 299 299 this.fireEvent("selectionchange", this); 300 300 }, 301 302 301 302 303 303 /** 304 304 * Selects a row. … … 308 308 selectRow : function(index, keepExisting, preventViewNotify) 309 309 { 310 // ignore store count, since this is our buffer and the rowIndex may indeed 311 // be greater than the count of records in the store 312 if(this.last === index || this.locked || index < 0) return;// || index >= this.grid.store.getCount())) return; 313 314 310 if(this.last === index 311 || this.locked 312 || index < 0 313 || index >= this.grid.store.getTotalCount()) { 314 return; 315 } 316 317 318 315 319 var r = this.grid.store.getAt(index); 316 320 317 321 if(this.fireEvent("beforerowselect", this, index, keepExisting, r) !== false){ 318 322 if(!keepExisting || this.singleSelect){ 319 323 this.clearSelections(); 320 324 } 321 325 322 326 if (r) { 323 327 this.selections.add(r); … … 326 330 this.pendingSelections[index] = true; 327 331 } 328 329 this.bufferedSelections[index] = true; 330 332 333 this.bufferedSelections[index] = true; 334 331 335 this.last = this.lastActive = index; 332 336 333 337 if(!preventViewNotify){ 334 338 this.grid.getView().onRowSelect(index); … … 338 342 } 339 343 }, 340 344 341 345 clearPendingSelection : function(index) 342 346 { 343 var r = this.grid.store.getAt(index); 347 var r = this.grid.store.getAt(index); 344 348 if (!r) { 345 349 return; 346 350 } 347 351 this.selections.add(r); 348 delete this.pendingSelections[index]; 349 }, 350 352 delete this.pendingSelections[index]; 353 }, 354 351 355 getPendingSelections : function(asRange) 352 356 { … … 355 359 var currentRange = 0; 356 360 var tmpArray = []; 357 361 358 362 for (var i in this.pendingSelections) { 359 363 tmpArray.push(parseInt(i)); 360 364 } 361 365 362 366 tmpArray.sort(function(o1,o2){ 363 367 if (o1 > o2) { … … 369 373 } 370 374 }); 371 375 372 376 if (asRange === false) { 373 377 return tmpArray; 374 378 } 375 379 376 380 var max_i = tmpArray.length; 377 381 378 382 if (max_i == 0) { 379 383 return []; 380 384 } 381 385 382 386 ranges[currentRange] = [tmpArray[0], tmpArray[0]]; 383 387 for (var i = 0, max_i = max_i-1; i < max_i; i++) { … … 389 393 } 390 394 } 391 395 392 396 return ranges; 393 397 }, … … 406 410 }, this);*/ 407 411 s.clear(); 408 412 409 413 for (var i in this.bufferedSelections) { 410 this.deselectRow(i); 411 } 412 414 this.deselectRow(i); 415 } 416 413 417 }else{ 414 418 this.selections.clear(); … … 418 422 this.last = false; 419 423 }, 420 421 422 /** 423 * Selects a range of rows. All rows in between startRow and endRow are also 424 425 426 /** 427 * Selects a range of rows. All rows in between startRow and endRow are also 424 428 * selected. 425 429 * … … 433 437 return; 434 438 } 435 439 436 440 if(!keepExisting) { 437 441 this.clearSelections(); 438 442 } 439 443 440 444 if (startRow <= endRow) { 441 445 for(var i = startRow; i <= endRow; i++) { … … 446 450 this.selectRow(i, true); 447 451 } 448 } 452 } 449 453 } 450 454 451 455 }); 452 456
