OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Namespace | 5 // Namespace |
6 var importer = importer || {}; | 6 var importer = importer || {}; |
7 | 7 |
8 /** @enum {string} */ | 8 /** @enum {string} */ |
9 importer.ResponseId = { | 9 importer.ResponseId = { |
10 EXECUTABLE: 'executable', | 10 READY: 'ready', |
11 HIDDEN: 'hidden', | 11 HIDDEN: 'hidden', |
12 ACTIVE_IMPORT: 'active_import', | 12 IMPORTING: 'importing', |
13 INSUFFICIENT_SPACE: 'insufficient_space', | 13 INSUFFICIENT_SPACE: 'insufficient-space', |
14 NO_MEDIA: 'no_media', | 14 NO_MEDIA: 'no-media', |
15 SCANNING: 'scanning' | 15 SCANNING: 'scanning' |
16 }; | 16 }; |
17 | 17 |
18 /** | 18 /** |
19 * @typedef {{ | |
20 * id: !importer.ResponseId, | |
21 * label: string, | |
22 * visible: boolean, | |
23 * executable: boolean, | |
24 * coreIcon: string | |
25 * }} | |
26 */ | |
27 importer.CommandUpdate; | |
28 | |
29 /** | |
30 * Class that orchestrates background activity and UI changes on | 19 * Class that orchestrates background activity and UI changes on |
31 * behalf of Cloud Import. | 20 * behalf of Cloud Import. |
32 * | 21 * |
33 * @constructor | 22 * @constructor |
34 * @struct | 23 * @struct |
35 * | 24 * |
36 * @param {!importer.ControllerEnvironment} environment The class providing | 25 * @param {!importer.ControllerEnvironment} environment The class providing |
37 * access to runtime environmental information, like the current directory, | 26 * access to runtime environmental information, like the current directory, |
38 * volume lookup and so-on. | 27 * volume lookup and so-on. |
39 * @param {!importer.MediaScanner} scanner | 28 * @param {!importer.MediaScanner} scanner |
(...skipping 13 matching lines...) Expand all Loading... | |
53 this.scanner_ = scanner; | 42 this.scanner_ = scanner; |
54 | 43 |
55 /** @private {!importer.CommandWidget} */ | 44 /** @private {!importer.CommandWidget} */ |
56 this.commandWidget_ = commandWidget; | 45 this.commandWidget_ = commandWidget; |
57 | 46 |
58 /** @type {!importer.ScanManager} */ | 47 /** @type {!importer.ScanManager} */ |
59 this.scanManager_ = new importer.ScanManager(environment, scanner); | 48 this.scanManager_ = new importer.ScanManager(environment, scanner); |
60 | 49 |
61 /** | 50 /** |
62 * The active import task, if any. | 51 * The active import task, if any. |
63 * @private {importer.MediaImportHandler.ImportTask} | 52 * @private {?{ |
53 * scan: !importer.ScanResult, | |
54 * task: !importer.MediaImportHandler.ImportTask | |
55 * }} | |
64 */ | 56 */ |
65 this.activeImportTask_ = null; | 57 this.activeImport_ = null; |
66 | 58 |
67 var listener = this.onScanEvent_.bind(this); | 59 var listener = this.onScanEvent_.bind(this); |
68 this.scanner_.addObserver(listener); | 60 this.scanner_.addObserver(listener); |
69 // Remove the observer when the foreground window is closed. | 61 // Remove the observer when the foreground window is closed. |
70 window.addEventListener( | 62 window.addEventListener( |
71 'pagehide', | 63 'pagehide', |
72 function() { | 64 function() { |
73 this.scanner_.removeObserver(listener); | 65 this.scanner_.removeObserver(listener); |
74 }.bind(this)); | 66 }.bind(this)); |
75 | 67 |
76 this.environment_.addVolumeUnmountListener( | 68 this.environment_.addVolumeUnmountListener( |
77 this.onVolumeUnmounted_.bind(this)); | 69 this.onVolumeUnmounted_.bind(this)); |
78 | 70 |
79 this.environment_.addDirectoryChangedListener( | 71 this.environment_.addDirectoryChangedListener( |
80 this.onDirectoryChanged_.bind(this)); | 72 this.onDirectoryChanged_.bind(this)); |
81 | 73 |
82 this.environment_.addSelectionChangedListener( | 74 this.environment_.addSelectionChangedListener( |
83 this.onSelectionChanged_.bind(this)); | 75 this.onSelectionChanged_.bind(this)); |
84 | 76 |
85 this.commandWidget_.addImportClickedListener( | 77 this.commandWidget_.addImportClickedListener( |
86 this.execute.bind(this)); | 78 this.execute.bind(this)); |
79 | |
80 this.commandWidget_.addDestinationClickedListener( | |
81 this.showDestination.bind(this)); | |
87 }; | 82 }; |
88 | 83 |
89 /** | 84 /** |
90 * @param {!importer.ScanEvent} event Command event. | 85 * @param {!importer.ScanEvent} event Command event. |
91 * @param {importer.ScanResult} scan | 86 * @param {importer.ScanResult} scan |
92 * | 87 * |
93 * @private | 88 * @private |
94 */ | 89 */ |
95 importer.ImportController.prototype.onScanEvent_ = function(event, scan) { | 90 importer.ImportController.prototype.onScanEvent_ = function(event, scan) { |
96 if (!this.scanManager_.isActiveScan(scan)) { | 91 if (!this.scanManager_.isActiveScan(scan)) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 } else { | 138 } else { |
144 this.checkState_(); | 139 this.checkState_(); |
145 } | 140 } |
146 }; | 141 }; |
147 | 142 |
148 /** | 143 /** |
149 * @param {!importer.MediaImportHandler.ImportTask} task | 144 * @param {!importer.MediaImportHandler.ImportTask} task |
150 * @private | 145 * @private |
151 */ | 146 */ |
152 importer.ImportController.prototype.onImportFinished_ = function(task) { | 147 importer.ImportController.prototype.onImportFinished_ = function(task) { |
153 this.activeImportTask_ = null; | 148 this.activeImport_ = null; |
154 this.scanManager_.reset(); | 149 this.scanManager_.reset(); |
155 this.checkState_(); | 150 this.checkState_(); |
156 }; | 151 }; |
157 | 152 |
158 /** | 153 /** |
159 * Executes import against the current directory. Should only | 154 * Executes import against the current directory. Should only |
160 * be called when the current directory has been validated | 155 * be called when the current directory has been validated |
161 * by calling "update" on this class. | 156 * by calling "update" on this class. |
162 */ | 157 */ |
163 importer.ImportController.prototype.execute = function() { | 158 importer.ImportController.prototype.execute = function() { |
164 console.assert(!this.activeImportTask_, | 159 console.assert(!this.activeImport_, |
165 'Cannot execute while an import task is already active.'); | 160 'Cannot execute while an import task is already active.'); |
166 metrics.recordEnum('CloudImport.UserAction', 'IMPORT_INITIATED'); | 161 metrics.recordEnum('CloudImport.UserAction', 'IMPORT_INITIATED'); |
167 | 162 |
168 var scan = this.scanManager_.getActiveScan(); | 163 var scan = this.scanManager_.getActiveScan(); |
169 assert(scan != null); | 164 assert(scan != null); |
170 | 165 |
171 var importTask = this.importRunner_.importFromScanResult( | 166 var importTask = this.importRunner_.importFromScanResult( |
172 scan, | 167 scan, |
173 importer.Destination.GOOGLE_DRIVE); | 168 importer.Destination.GOOGLE_DRIVE); |
174 | 169 |
175 this.activeImportTask_ = importTask; | 170 this.activeImport_ = { |
171 scan: scan, | |
172 task: importTask | |
173 }; | |
176 var taskFinished = this.onImportFinished_.bind(this, importTask); | 174 var taskFinished = this.onImportFinished_.bind(this, importTask); |
177 importTask.whenFinished.then(taskFinished).catch(taskFinished); | 175 importTask.whenFinished.then(taskFinished).catch(taskFinished); |
178 this.checkState_(); | 176 this.checkState_(); |
179 }; | 177 }; |
180 | 178 |
181 /** | 179 /** |
180 * Shows the import destination folder. | |
181 */ | |
182 importer.ImportController.prototype.showDestination = function() { | |
183 console.log('SET THE CURRENT DIRECTORY TO THE DESTINATION'); | |
184 }; | |
185 | |
186 /** | |
182 * Checks the environment and updates UI as needed. | 187 * Checks the environment and updates UI as needed. |
183 * @param {importer.ScanResult=} opt_scan If supplied, | 188 * @param {importer.ScanResult=} opt_scan If supplied, |
184 * @private | 189 * @private |
185 */ | 190 */ |
186 importer.ImportController.prototype.checkState_ = function(opt_scan) { | 191 importer.ImportController.prototype.checkState_ = function(opt_scan) { |
187 // If there is no Google Drive mount, Drive may be disabled | 192 // If there is no Google Drive mount, Drive may be disabled |
188 // or the machine may be running in guest mode. | 193 // or the machine may be running in guest mode. |
189 if (!this.environment_.isGoogleDriveMounted()) { | 194 if (!this.environment_.isGoogleDriveMounted()) { |
190 this.updateUi_(importer.ResponseId.HIDDEN); | 195 this.updateUi_(importer.ResponseId.HIDDEN); |
191 return; | 196 return; |
192 } | 197 } |
193 | 198 |
194 if (!!this.activeImportTask_) { | 199 if (!!this.activeImport_) { |
195 this.updateUi_(importer.ResponseId.ACTIVE_IMPORT); | 200 this.updateUi_(importer.ResponseId.IMPORTING, this.activeImport_.scan); |
196 return; | 201 return; |
197 } | 202 } |
198 | 203 |
199 // If we don't have an existing scan, we'll try to create | 204 // If we don't have an existing scan, we'll try to create |
200 // one. When we do end up creating one (not getting | 205 // one. When we do end up creating one (not getting |
201 // one from the cache) it'll be empty...even if there is | 206 // one from the cache) it'll be empty...even if there is |
202 // a current selection. This is because scans are | 207 // a current selection. This is because scans are |
203 // resolved asynchronously. And we like it that way. | 208 // resolved asynchronously. And we like it that way. |
204 // We'll get notification when the scan is updated. When | 209 // We'll get notification when the scan is updated. When |
205 // that happens, we'll be called back with opt_scan | 210 // that happens, we'll be called back with opt_scan |
(...skipping 30 matching lines...) Expand all Loading... | |
236 /** @param {boolean} fits */ | 241 /** @param {boolean} fits */ |
237 function(fits) { | 242 function(fits) { |
238 if (!fits) { | 243 if (!fits) { |
239 this.updateUi_( | 244 this.updateUi_( |
240 importer.ResponseId.INSUFFICIENT_SPACE, | 245 importer.ResponseId.INSUFFICIENT_SPACE, |
241 opt_scan); | 246 opt_scan); |
242 return; | 247 return; |
243 } | 248 } |
244 | 249 |
245 this.updateUi_( | 250 this.updateUi_( |
246 importer.ResponseId.EXECUTABLE, | 251 importer.ResponseId.READY, // to import... |
247 opt_scan); | 252 opt_scan); |
248 }.bind(this)); | 253 }.bind(this)); |
249 }; | 254 }; |
250 | 255 |
251 /** | 256 /** |
252 * @param {importer.ResponseId} responseId | 257 * @param {importer.ResponseId} responseId |
253 * @param {importer.ScanResult=} opt_scan | 258 * @param {importer.ScanResult=} opt_scan |
254 * | |
255 * @return {!importer.CommandUpdate} | |
256 * @private | 259 * @private |
257 */ | 260 */ |
258 importer.ImportController.prototype.updateUi_ = | 261 importer.ImportController.prototype.updateUi_ = |
259 function(responseId, opt_scan) { | 262 function(responseId, opt_scan) { |
260 switch(responseId) { | 263 this.commandWidget_.update(responseId, opt_scan); |
261 case importer.ResponseId.EXECUTABLE: | |
262 this.commandWidget_.update({ | |
263 id: responseId, | |
264 label: strf( | |
265 'CLOUD_IMPORT_BUTTON_LABEL', | |
266 opt_scan.getFileEntries().length), | |
267 visible: true, | |
268 executable: true, | |
269 coreIcon: 'cloud-upload' | |
270 }); | |
271 this.commandWidget_.updateDetails(opt_scan); | |
272 break; | |
273 case importer.ResponseId.HIDDEN: | |
274 this.commandWidget_.update({ | |
275 id: responseId, | |
276 visible: false, | |
277 executable: false, | |
278 label: '** SHOULD NOT BE VISIBLE **', | |
279 coreIcon: 'cloud-off' | |
280 }); | |
281 this.commandWidget_.setDetailsVisible(false); | |
282 break; | |
283 case importer.ResponseId.ACTIVE_IMPORT: | |
284 this.commandWidget_.update({ | |
285 id: responseId, | |
286 visible: true, | |
287 executable: false, | |
288 label: str('CLOUD_IMPORT_ACTIVE_IMPORT_BUTTON_LABEL'), | |
289 coreIcon: 'swap-vert' | |
290 }); | |
291 this.commandWidget_.setDetailsVisible(false); | |
292 break; | |
293 case importer.ResponseId.INSUFFICIENT_SPACE: | |
294 this.commandWidget_.update({ | |
295 id: responseId, | |
296 visible: true, | |
297 executable: false, | |
298 label: strf( | |
299 'CLOUD_IMPORT_INSUFFICIENT_SPACE_BUTTON_LABEL', | |
300 util.bytesToString(opt_scan.getTotalBytes())), | |
301 coreIcon: 'report-problem' | |
302 }); | |
303 this.commandWidget_.updateDetails(opt_scan); | |
304 break; | |
305 case importer.ResponseId.NO_MEDIA: | |
306 this.commandWidget_.update({ | |
307 id: responseId, | |
308 visible: true, | |
309 executable: false, | |
310 label: str('CLOUD_IMPORT_EMPTY_SCAN_BUTTON_LABEL'), | |
311 coreIcon: 'cloud-done' | |
312 }); | |
313 this.commandWidget_.updateDetails( | |
314 /** @type {!importer.ScanResult} */ (opt_scan)); | |
315 break; | |
316 case importer.ResponseId.SCANNING: | |
317 this.commandWidget_.update({ | |
318 id: responseId, | |
319 visible: true, | |
320 executable: false, | |
321 label: str('CLOUD_IMPORT_SCANNING_BUTTON_LABEL'), | |
322 coreIcon: 'autorenew' | |
323 }); | |
324 this.commandWidget_.updateDetails( | |
325 /** @type {!importer.ScanResult} */ (opt_scan)); | |
326 break; | |
327 default: | |
328 assertNotReached('Unrecognized response id: ' + responseId); | |
329 } | |
330 }; | 264 }; |
331 | 265 |
332 /** | 266 /** |
333 * @return {boolean} true if the current directory is scan eligible. | 267 * @return {boolean} true if the current directory is scan eligible. |
334 * @private | 268 * @private |
335 */ | 269 */ |
336 importer.ImportController.prototype.isCurrentDirectoryScannable_ = | 270 importer.ImportController.prototype.isCurrentDirectoryScannable_ = |
337 function() { | 271 function() { |
338 var directory = this.environment_.getCurrentDirectory(); | 272 var directory = this.environment_.getCurrentDirectory(); |
339 return !!directory && | 273 return !!directory && |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 importer.CommandWidget = function() {}; | 493 importer.CommandWidget = function() {}; |
560 | 494 |
561 /** | 495 /** |
562 * Install a listener that get's called when the user wants to initiate | 496 * Install a listener that get's called when the user wants to initiate |
563 * import. | 497 * import. |
564 * | 498 * |
565 * @param {function()} listener | 499 * @param {function()} listener |
566 */ | 500 */ |
567 importer.CommandWidget.prototype.addImportClickedListener; | 501 importer.CommandWidget.prototype.addImportClickedListener; |
568 | 502 |
569 /** @param {!importer.CommandUpdate} update */ | 503 /** |
504 * Install a listener that get's called when the user wants to initiate | |
505 * import. | |
506 * | |
507 * @param {function()} listener | |
508 */ | |
509 importer.CommandWidget.prototype.addDestinationClickedListener; | |
510 | |
511 /** | |
512 * @param {importer.ResponseId} responseId | |
513 * @param {importer.ScanResult=} opt_scan | |
514 */ | |
570 importer.CommandWidget.prototype.update; | 515 importer.CommandWidget.prototype.update; |
571 | 516 |
572 /** @param {!importer.ScanResult} scan */ | |
573 importer.CommandWidget.prototype.updateDetails; | |
574 | |
575 /** Resets details to default. */ | |
576 importer.CommandWidget.prototype.resetDetails; | |
577 | |
578 /** | 517 /** |
579 * Runtime implementation of CommandWidget. | 518 * Runtime implementation of CommandWidget. |
580 * | 519 * |
581 * @constructor | 520 * @constructor |
582 * @implements {importer.CommandWidget} | 521 * @implements {importer.CommandWidget} |
583 * @struct | 522 * @struct |
584 */ | 523 */ |
585 importer.RuntimeCommandWidget = function() { | 524 importer.RuntimeCommandWidget = function() { |
586 | 525 |
587 /** @private {Element} */ | 526 /** @private {Element} */ |
588 this.importButton_ = document.getElementById('cloud-import-button'); | 527 this.importButton_ = document.getElementById('cloud-import-button'); |
589 this.importButton_.onclick = this.onImportClicked_.bind(this); | 528 this.importButton_.onclick = this.onImportClicked_.bind(this); |
590 | 529 |
591 /** @private {Element} */ | 530 /** @private {Element} */ |
592 this.detailsButton_ = document.getElementById('cloud-import-details-button'); | 531 this.detailsButton_ = document.getElementById('cloud-import-details-button'); |
593 this.detailsButton_.onclick = this.toggleDetails_.bind(this); | 532 this.detailsButton_.onclick = this.toggleDetails_.bind(this); |
594 | 533 |
595 /** @private {Element} */ | 534 /** @private {Element} */ |
596 this.detailsImportButton_ = | 535 this.detailsImportButton_ = |
597 document.querySelector('#cloud-import-details .import'); | 536 document.querySelector('#cloud-import-details paper-button.import'); |
598 this.detailsImportButton_.onclick = this.onImportClicked_.bind(this); | 537 this.detailsImportButton_.onclick = this.onImportClicked_.bind(this); |
599 | 538 |
600 /** @private {Element} */ | 539 /** @private {Element} */ |
601 this.detailsPanel_ = document.getElementById('cloud-import-details'); | 540 this.detailsPanel_ = document.getElementById('cloud-import-details'); |
541 this.detailsPanel_.addEventListener( | |
542 'transitionend', | |
543 this.onDetailsTransitionEnd_.bind(this), | |
544 false); | |
602 | 545 |
603 /** @private {Element} */ | 546 /** @private {Element} */ |
604 this.photoCount_ = | 547 this.detailsPanelBody_ = |
605 document.querySelector('#cloud-import-details .photo-count'); | 548 document.querySelector('#cloud-import-details .main'); |
606 | 549 |
607 /** @private {Element} */ | 550 /** @private {Element} */ |
608 this.spaceRequired_ = | 551 this.statusContent_ = |
609 document.querySelector('#cloud-import-details .space-required'); | 552 document.querySelector('#cloud-import-details .status .content'); |
553 this.statusContent_.onclick = this.onStatusClicked_.bind(this); | |
610 | 554 |
611 /** @private {Element} */ | 555 /** @private {Element} */ |
612 this.icon_ = document.querySelector('#cloud-import-button core-icon'); | 556 this.toolbarIcon_ = |
557 document.querySelector('#cloud-import-button core-icon'); | |
558 this.statusIcon_ = | |
559 document.querySelector('#cloud-import-details .status core-icon'); | |
613 | 560 |
614 /** @private {function()} */ | 561 /** @private {function()} */ |
615 this.importListener_; | 562 this.importListener_; |
563 | |
564 /** @private {function()} */ | |
565 this.destinationListener_; | |
616 }; | 566 }; |
617 | 567 |
618 /** @override */ | 568 /** @override */ |
619 importer.RuntimeCommandWidget.prototype.addImportClickedListener = | 569 importer.RuntimeCommandWidget.prototype.addImportClickedListener = |
620 function(listener) { | 570 function(listener) { |
621 console.assert(!this.importListener_); | 571 console.assert(!this.importListener_); |
622 this.importListener_ = listener; | 572 this.importListener_ = listener; |
623 }; | 573 }; |
624 | 574 |
625 /** @private */ | 575 /** @override */ |
626 importer.RuntimeCommandWidget.prototype.onImportClicked_ = function() { | 576 importer.RuntimeCommandWidget.prototype.addDestinationClickedListener = |
627 console.assert(!!this.importListener_); | 577 function(listener) { |
578 console.assert(!this.destinationListener_); | |
579 this.destinationListener_ = listener; | |
580 }; | |
581 | |
582 /** | |
583 * @param {Event} event Click event. | |
584 * @private | |
585 */ | |
586 importer.RuntimeCommandWidget.prototype.onImportClicked_ = function(event) { | |
587 console.assert(!!this.importListener_, 'Listener not set.'); | |
628 this.importListener_(); | 588 this.importListener_(); |
629 }; | 589 }; |
630 | 590 |
591 /** | |
592 * @param {Event} event Click event. | |
593 * @private | |
594 */ | |
595 importer.RuntimeCommandWidget.prototype.onStatusClicked_ = function(event) { | |
596 console.assert(!!this.destinationListener_, 'Listener not set.'); | |
597 // TODO(smckay): Only if the element is "destination-link". | |
598 this.destinationListener_(); | |
599 }; | |
600 | |
631 /** @private */ | 601 /** @private */ |
632 importer.RuntimeCommandWidget.prototype.toggleDetails_ = function() { | 602 importer.RuntimeCommandWidget.prototype.toggleDetails_ = function() { |
633 this.setDetailsVisible(this.detailsPanel_.className === 'offscreen'); | 603 this.setDetailsVisible(this.detailsPanel_.className === 'hidden'); |
mtomasz
2015/02/13 13:26:24
Hidden attribute should be used instead?
Steve McKay
2015/02/13 17:31:44
We both mark the element as hidden AND add the 'hi
| |
634 }; | 604 }; |
635 | 605 |
636 importer.RuntimeCommandWidget.prototype.setDetailsVisible = function(visible) { | 606 importer.RuntimeCommandWidget.prototype.setDetailsVisible = function(visible) { |
637 if (visible) { | 607 if (visible) { |
608 this.detailsPanel_.hidden = false; | |
638 this.detailsPanel_.className = ''; | 609 this.detailsPanel_.className = ''; |
mtomasz
2015/02/13 13:26:24
ditto
Steve McKay
2015/02/13 17:31:45
Acknowledged.
| |
639 } else { | 610 } else { |
640 this.detailsPanel_.className = 'offscreen'; | 611 this.detailsPanel_.className = 'hidden'; |
mtomasz
2015/02/13 13:26:24
ditto
Steve McKay
2015/02/13 17:31:45
Acknowledged.
| |
612 } | |
613 }; | |
614 | |
615 /** @private */ | |
616 importer.RuntimeCommandWidget.prototype.onDetailsTransitionEnd_ = | |
617 function() { | |
618 if (this.detailsPanel_.className === 'hidden') { | |
619 // if we simply make the panel invisible (via opacity) | |
620 // it'll still be sitting there grabing mouse events | |
621 // and so-on. So we *hide* hide it. | |
622 this.detailsPanel_.hidden = true; | |
641 } | 623 } |
642 }; | 624 }; |
643 | 625 |
644 /** @override */ | 626 /** @override */ |
645 importer.RuntimeCommandWidget.prototype.update = function(update) { | 627 importer.RuntimeCommandWidget.prototype.update = |
646 this.importButton_.setAttribute('title', update.label); | 628 function(responseId, opt_scan) { |
647 this.importButton_.disabled = !update.executable; | 629 switch(responseId) { |
648 this.importButton_.style.display = | 630 case importer.ResponseId.HIDDEN: |
649 update.visible ? 'block' : 'none'; | 631 this.setDetailsVisible(false); |
650 | 632 |
651 this.icon_.setAttribute('icon', update.coreIcon); | 633 this.importButton_.disabled = true; |
634 this.detailsButton_.disabled = true; | |
652 | 635 |
653 this.detailsButton_.disabled = !update.executable; | 636 this.importButton_.hidden = true; |
654 this.detailsButton_.style.display = | 637 this.detailsButton_.hidden = true; |
655 update.visible ? 'block' : 'none'; | |
656 }; | |
657 | 638 |
658 /** @override */ | 639 this.importButton_.setAttribute( |
659 importer.RuntimeCommandWidget.prototype.updateDetails = function(scan) { | 640 'title', |
660 this.photoCount_.textContent = scan.getFileEntries().length.toLocaleString(); | 641 '** SHOULD NOT BE VISIBLE **'); |
661 this.spaceRequired_.textContent = util.bytesToString(scan.getTotalBytes()); | 642 this.statusContent_.innerHTML = |
662 }; | 643 '** SHOULD NOT BE VISIBLE **'; |
663 | 644 |
664 /** @override */ | 645 this.toolbarIcon_.setAttribute('icon', 'cloud-off'); |
665 importer.RuntimeCommandWidget.prototype.resetDetails = function() { | 646 this.statusIcon_.setAttribute('icon', 'cloud-off'); |
666 this.photoCount_.textContent = 0; | 647 |
667 this.spaceRequired_.textContent = 0; | 648 break; |
649 | |
650 case importer.ResponseId.IMPORTING: | |
651 console.assert(!!opt_scan, 'Scan not defined, but is required.'); | |
652 this.setDetailsVisible(false); | |
653 | |
654 this.importButton_.setAttribute('title', strf( | |
655 'CLOUD_IMPORT_TOOLTIP_IMPORTING', | |
656 opt_scan.getFileEntries().length)); | |
657 this.statusContent_.innerHTML = strf( | |
658 'CLOUD_IMPORT_STATUS_IMPORTING', | |
659 opt_scan.getFileEntries().length); | |
660 | |
661 this.importButton_.disabled = true; | |
662 this.detailsButton_.disabled = true; | |
663 this.detailsImportButton_.disabled = true; | |
664 | |
665 this.importButton_.hidden = false; | |
666 this.detailsButton_.hidden = false; | |
667 this.detailsImportButton_.hidden = false; | |
668 | |
669 this.toolbarIcon_.setAttribute('icon', 'autorenew'); | |
670 this.statusIcon_.setAttribute('icon', 'autorenew'); | |
671 | |
672 break; | |
673 | |
674 case importer.ResponseId.INSUFFICIENT_SPACE: | |
675 console.assert(!!opt_scan, 'Scan not defined, but is required.'); | |
676 | |
677 this.importButton_.setAttribute('title', strf( | |
678 'CLOUD_IMPORT_STATUS_INSUFFICIENT_SPACE')); | |
679 this.statusContent_.innerHTML = strf( | |
680 'CLOUD_IMPORT_STATUS_INSUFFICIENT_SPACE', | |
681 opt_scan.getFileEntries().length); | |
682 | |
683 this.importButton_.disabled = true; | |
684 this.detailsButton_.disabled = false; | |
685 this.detailsImportButton_.disabled = true; | |
686 | |
687 this.importButton_.hidden = false; | |
688 this.detailsButton_.hidden = false; | |
689 this.detailsImportButton_.hidden = false; | |
690 | |
691 this.toolbarIcon_.setAttribute('icon', 'image:photo'); | |
692 this.statusIcon_.setAttribute('icon', 'cloud-off'); | |
693 break; | |
694 | |
695 case importer.ResponseId.NO_MEDIA: | |
696 this.importButton_.setAttribute('title', str( | |
697 'CLOUD_IMPORT_STATUS_NO_MEDIA')); | |
698 this.statusContent_.innerHTML = str( | |
699 'CLOUD_IMPORT_STATUS_NO_MEDIA'); | |
700 | |
701 this.importButton_.disabled = true; | |
702 this.detailsButton_.disabled = true; | |
703 this.detailsImportButton_.disabled = true; | |
704 | |
705 this.importButton_.hidden = false; | |
706 this.detailsButton_.hidden = false; | |
707 // Hidden for now, since this is also the "done" importing case. | |
708 this.detailsImportButton_.hidden = true; | |
709 | |
710 this.toolbarIcon_.setAttribute('icon', 'cloud-done'); | |
711 this.statusIcon_.setAttribute('icon', 'cloud-done'); | |
712 break; | |
713 | |
714 case importer.ResponseId.READY: | |
715 console.assert(!!opt_scan, 'Scan not defined, but is required.'); | |
716 | |
717 this.importButton_.setAttribute('title', strf( | |
718 'CLOUD_IMPORT_TOOLTIP_READY', | |
719 opt_scan.getFileEntries().length)); | |
720 this.statusContent_.innerHTML = strf( | |
721 'CLOUD_IMPORT_STATUS_READY', | |
722 opt_scan.getFileEntries().length); | |
723 | |
724 this.importButton_.disabled = false; | |
725 this.detailsButton_.disabled = false; | |
726 this.detailsImportButton_.disabled = false; | |
727 | |
728 this.importButton_.hidden = false; | |
729 this.detailsButton_.hidden = false; | |
730 this.detailsImportButton_.hidden = false; | |
731 | |
732 this.toolbarIcon_.setAttribute('icon', 'cloud-upload'); | |
733 this.statusIcon_.setAttribute('icon', 'image:photo'); | |
734 break; | |
735 | |
736 case importer.ResponseId.SCANNING: | |
737 console.assert(!!opt_scan, 'Scan not defined, but is required.'); | |
738 | |
739 this.importButton_.setAttribute('title', str( | |
740 'CLOUD_IMPORT_TOOLTIP_SCANNING')); | |
741 this.statusContent_.innerHTML = strf( | |
742 'CLOUD_IMPORT_STATUS_SCANNING', | |
743 opt_scan.getFileEntries().length); | |
744 | |
745 this.importButton_.disabled = true; | |
746 this.detailsButton_.disabled = true; | |
747 this.detailsImportButton_.disabled = true; | |
748 | |
749 this.importButton_.hidden = false; | |
750 this.detailsButton_.hidden = false; | |
751 this.detailsImportButton_.hidden = true; | |
752 | |
753 this.toolbarIcon_.setAttribute('icon', 'autorenew'); | |
754 this.statusIcon_.setAttribute('icon', 'autorenew'); | |
755 break; | |
756 | |
757 default: | |
758 assertNotReached('Unrecognized response id: ' + responseId); | |
759 } | |
668 }; | 760 }; |
669 | 761 |
670 /** | 762 /** |
671 * A cache for ScanResults. | 763 * A cache for ScanResults. |
672 * | 764 * |
673 * @constructor | 765 * @constructor |
674 * @struct | 766 * @struct |
675 * | 767 * |
676 * @param {!importer.ControllerEnvironment} environment | 768 * @param {!importer.ControllerEnvironment} environment |
677 * @param {!importer.MediaScanner} scanner | 769 * @param {!importer.MediaScanner} scanner |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 var directory = this.environment_.getCurrentDirectory(); | 858 var directory = this.environment_.getCurrentDirectory(); |
767 var url = directory.toURL(); | 859 var url = directory.toURL(); |
768 var scan = this.directoryScans_[url]; | 860 var scan = this.directoryScans_[url]; |
769 if (!scan) { | 861 if (!scan) { |
770 scan = this.scanner_.scan([directory]); | 862 scan = this.scanner_.scan([directory]); |
771 this.directoryScans_[url] = scan; | 863 this.directoryScans_[url] = scan; |
772 } | 864 } |
773 | 865 |
774 return scan; | 866 return scan; |
775 }; | 867 }; |
OLD | NEW |