| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview This is a data model representin | 6 * @fileoverview This is a data model representin |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('cr.ui', function() { | 9 cr.define('cr.ui', function() { |
| 10 const EventTarget = cr.EventTarget; | 10 const EventTarget = cr.EventTarget; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 var arr = this.array_; | 142 var arr = this.array_; |
| 143 | 143 |
| 144 // TODO(arv): Maybe unify splice and change events? | 144 // TODO(arv): Maybe unify splice and change events? |
| 145 var spliceEvent = new Event('splice'); | 145 var spliceEvent = new Event('splice'); |
| 146 spliceEvent.index = index; | 146 spliceEvent.index = index; |
| 147 spliceEvent.removed = arr.slice(index, index + deleteCount); | 147 spliceEvent.removed = arr.slice(index, index + deleteCount); |
| 148 spliceEvent.added = Array.prototype.slice.call(arguments, 2); | 148 spliceEvent.added = Array.prototype.slice.call(arguments, 2); |
| 149 | 149 |
| 150 var rv = arr.splice.apply(arr, arguments); | 150 var rv = arr.splice.apply(arr, arguments); |
| 151 var self = this; | |
| 152 | 151 |
| 153 // if sortStatus.field is null, this restores original order. | 152 // if sortStatus.field is null, this restores original order. |
| 154 this.prepareSort(this.sortStatus.field, function() { | 153 var sortPermutation = this.doSort_(this.sortStatus.field, |
| 155 var sortPermutation = self.doSort_(self.sortStatus.field, | 154 this.sortStatus.direction); |
| 156 self.sortStatus.direction); | 155 if (sortPermutation) { |
| 157 if (sortPermutation) { | 156 var splicePermutation = deletePermutation.map(function(element) { |
| 158 var splicePermutation = deletePermutation.map(function(element) { | 157 return element != -1 ? sortPermutation[element] : -1; |
| 159 return element != -1 ? sortPermutation[element] : -1; | 158 }); |
| 160 }); | 159 this.dispatchPermutedEvent_(splicePermutation); |
| 161 self.dispatchPermutedEvent_(splicePermutation); | 160 } else { |
| 162 } else { | 161 this.dispatchPermutedEvent_(deletePermutation); |
| 163 self.dispatchPermutedEvent_(deletePermutation); | 162 } |
| 164 } | |
| 165 | 163 |
| 166 self.dispatchEvent(spliceEvent); | 164 this.dispatchEvent(spliceEvent); |
| 167 }); | |
| 168 | |
| 169 return rv; | 165 return rv; |
| 170 }, | 166 }, |
| 171 | 167 |
| 172 /** | 168 /** |
| 173 * Appends items to the end of the model. | 169 * Appends items to the end of the model. |
| 174 * | 170 * |
| 175 * This dispatches a splice event. | 171 * This dispatches a splice event. |
| 176 * | 172 * |
| 177 * @param {...*} The items to append. | 173 * @param {...*} The items to append. |
| 178 * @return {number} The new length of the model. | 174 * @return {number} The new length of the model. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 194 updateIndex: function(index) { | 190 updateIndex: function(index) { |
| 195 if (index < 0 || index >= this.length) | 191 if (index < 0 || index >= this.length) |
| 196 throw Error('Invalid index, ' + index); | 192 throw Error('Invalid index, ' + index); |
| 197 | 193 |
| 198 // TODO(arv): Maybe unify splice and change events? | 194 // TODO(arv): Maybe unify splice and change events? |
| 199 var e = new Event('change'); | 195 var e = new Event('change'); |
| 200 e.index = index; | 196 e.index = index; |
| 201 this.dispatchEvent(e); | 197 this.dispatchEvent(e); |
| 202 | 198 |
| 203 if (this.sortStatus.field) { | 199 if (this.sortStatus.field) { |
| 204 var self = this; | 200 var sortPermutation = this.doSort_(this.sortStatus.field, |
| 205 this.prepareSort(self.sortStatus.field, function() { | 201 this.sortStatus.direction); |
| 206 var sortPermutation = self.doSort_(self.sortStatus.field, | 202 if (sortPermutation) |
| 207 self.sortStatus.direction); | 203 this.dispatchPermutedEvent_(sortPermutation); |
| 208 if (sortPermutation) | |
| 209 self.dispatchPermutedEvent_(sortPermutation); | |
| 210 }); | |
| 211 } | 204 } |
| 212 }, | 205 }, |
| 213 | 206 |
| 214 /** | 207 /** |
| 215 * Creates sort status with given field and direction. | 208 * Creates sort status with given field and direction. |
| 216 * @param {string} field Sort field. | 209 * @param {string} field Sort field. |
| 217 * @param {string} direction Sort direction. | 210 * @param {string} direction Sort direction. |
| 218 * @return {!Object} Created sort status. | 211 * @return {!Object} Created sort status. |
| 219 */ | 212 */ |
| 220 createSortStatus: function(field, direction) { | 213 createSortStatus: function(field, direction) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 if (a > b) | 340 if (a > b) |
| 348 return 1; | 341 return 1; |
| 349 return 0; | 342 return 0; |
| 350 } | 343 } |
| 351 }; | 344 }; |
| 352 | 345 |
| 353 return { | 346 return { |
| 354 ArrayDataModel: ArrayDataModel | 347 ArrayDataModel: ArrayDataModel |
| 355 }; | 348 }; |
| 356 }); | 349 }); |
| OLD | NEW |