OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * Data model for gallery. | 6 * Data model for gallery. |
7 * | 7 * |
8 * @param {!MetadataModel} metadataModel | 8 * @param {!MetadataModel} metadataModel |
9 * @param {!EntryListWatcher=} opt_watcher Entry list watcher. | 9 * @param {!EntryListWatcher=} opt_watcher Entry list watcher. |
10 * @constructor | 10 * @constructor |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_ = 5; | 51 GalleryDataModel.MAX_SCREEN_IMAGE_CACHE_ = 5; |
52 | 52 |
53 GalleryDataModel.prototype = { | 53 GalleryDataModel.prototype = { |
54 __proto__: cr.ui.ArrayDataModel.prototype | 54 __proto__: cr.ui.ArrayDataModel.prototype |
55 }; | 55 }; |
56 | 56 |
57 /** | 57 /** |
58 * Saves new image. | 58 * Saves new image. |
59 * | 59 * |
60 * @param {!VolumeManagerWrapper} volumeManager Volume manager instance. | 60 * @param {!VolumeManagerWrapper} volumeManager Volume manager instance. |
61 * @param {!Gallery.Item} item Original gallery item. | 61 * @param {!GalleryItem} item Original gallery item. |
62 * @param {!HTMLCanvasElement} canvas Canvas containing new image. | 62 * @param {!HTMLCanvasElement} canvas Canvas containing new image. |
63 * @param {boolean} overwrite Set true to overwrite original if it's possible. | 63 * @param {boolean} overwrite Set true to overwrite original if it's possible. |
64 * @return {!Promise} Promise to be fulfilled with when the operation completes. | 64 * @return {!Promise} Promise to be fulfilled with when the operation completes. |
65 */ | 65 */ |
66 GalleryDataModel.prototype.saveItem = function( | 66 GalleryDataModel.prototype.saveItem = function( |
67 volumeManager, item, canvas, overwrite) { | 67 volumeManager, item, canvas, overwrite) { |
68 var oldEntry = item.getEntry(); | 68 var oldEntry = item.getEntry(); |
69 var oldLocationInfo = item.getLocationInfo(); | 69 var oldLocationInfo = item.getLocationInfo(); |
70 var oldIsOriginal = item.isOriginal(); | 70 var oldIsOriginal = item.isOriginal(); |
71 return new Promise(function(fulfill, reject) { | 71 return new Promise(function(fulfill, reject) { |
(...skipping 18 matching lines...) Expand all Loading... |
90 this.dispatchEvent(event); | 90 this.dispatchEvent(event); |
91 | 91 |
92 if (!util.isSameEntry(oldEntry, item.getEntry())) { | 92 if (!util.isSameEntry(oldEntry, item.getEntry())) { |
93 Promise.all([ | 93 Promise.all([ |
94 this.metadataModel_.get( | 94 this.metadataModel_.get( |
95 [oldEntry], Gallery.PREFETCH_PROPERTY_NAMES), | 95 [oldEntry], Gallery.PREFETCH_PROPERTY_NAMES), |
96 new ThumbnailModel(this.metadataModel_).get([oldEntry]) | 96 new ThumbnailModel(this.metadataModel_).get([oldEntry]) |
97 ]).then(function(itemLists) { | 97 ]).then(function(itemLists) { |
98 // New entry is added and the item now tracks it. | 98 // New entry is added and the item now tracks it. |
99 // Add another item for the old entry. | 99 // Add another item for the old entry. |
100 var anotherItem = new Gallery.Item( | 100 var anotherItem = new GalleryItem( |
101 oldEntry, | 101 oldEntry, |
102 oldLocationInfo, | 102 oldLocationInfo, |
103 itemLists[0][0], | 103 itemLists[0][0], |
104 itemLists[1][0], | 104 itemLists[1][0], |
105 oldIsOriginal); | 105 oldIsOriginal); |
106 // The item must be added behind the existing item so that it does | 106 // The item must be added behind the existing item so that it does |
107 // not change the index of the existing item. | 107 // not change the index of the existing item. |
108 // TODO(hirono): Update the item index of the selection model | 108 // TODO(hirono): Update the item index of the selection model |
109 // correctly. | 109 // correctly. |
110 this.splice(this.indexOf(item) + 1, 0, anotherItem); | 110 this.splice(this.indexOf(item) + 1, 0, anotherItem); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 * @private | 162 * @private |
163 */ | 163 */ |
164 GalleryDataModel.prototype.onSplice_ = function(event) { | 164 GalleryDataModel.prototype.onSplice_ = function(event) { |
165 if (!event.removed || !event.removed.length) | 165 if (!event.removed || !event.removed.length) |
166 return; | 166 return; |
167 var removedURLs = event.removed.map(function(item) { | 167 var removedURLs = event.removed.map(function(item) { |
168 return item.getEntry().toURL(); | 168 return item.getEntry().toURL(); |
169 }); | 169 }); |
170 this.metadataModel_.notifyEntriesRemoved(removedURLs); | 170 this.metadataModel_.notifyEntriesRemoved(removedURLs); |
171 }; | 171 }; |
OLD | NEW |