Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: chrome/browser/resources/file_manager/js/photo/photo_import.js

Issue 10946029: [filemanager] Importing progress implemented. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 document.addEventListener('DOMContentLoaded', function() { 5 document.addEventListener('DOMContentLoaded', function() {
6 PhotoImport.load(); 6 PhotoImport.load();
7 }); 7 });
8 8
9 /** 9 /**
10 * The main Photo App object. 10 * The main Photo App object.
11 * @param {HTMLElement} dom Container. 11 * @param {HTMLElement} dom Container.
12 * @param {FileSystem} filesystem Local file system. 12 * @param {FileSystem} filesystem Local file system.
13 * @param {Object} params Parameters. 13 * @param {Object} params Parameters.
14 * @constructor 14 * @constructor
15 */ 15 */
16 function PhotoImport(dom, filesystem, params) { 16 function PhotoImport(dom, filesystem, params) {
17 this.filesystem_ = filesystem; 17 this.filesystem_ = filesystem;
18 this.dom_ = dom; 18 this.dom_ = dom;
19 this.document_ = this.dom_.ownerDocument; 19 this.document_ = this.dom_.ownerDocument;
20 this.metadataCache_ = params.metadataCache; 20 this.metadataCache_ = params.metadataCache;
21 this.volumeManager_ = new VolumeManager(); 21 this.volumeManager_ = new VolumeManager();
22 this.copyManager_ = FileCopyManagerWrapper.getInstance(this.filesystem_.root); 22 this.copyManager_ = FileCopyManagerWrapper.getInstance(this.filesystem_.root);
23 this.mediaFilesList_ = null; 23 this.mediaFilesList_ = null;
24 this.albums_ = null; 24 this.destination_ = null;
25 this.albumsDir_ = null;
26 25
27 this.initDom_(); 26 this.initDom_();
28 this.initAlbums_(); 27 this.initDestination_();
29 this.loadSource_(params.source); 28 this.loadSource_(params.source);
30 } 29 }
31 30
32 PhotoImport.prototype = { __proto__: cr.EventTarget.prototype }; 31 PhotoImport.prototype = { __proto__: cr.EventTarget.prototype };
33 32
34 /** 33 /**
35 * Single item width. 34 * Single item width.
36 * Keep in sync with .grid-item rule in photo_import.css. 35 * Keep in sync with .grid-item rule in photo_import.css.
37 */ 36 */
38 PhotoImport.ITEM_WIDTH = 164 + 8; 37 PhotoImport.ITEM_WIDTH = 164 + 8;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 loadTimeData.getString('PHOTO_IMPORT_DELETE_AFTER'); 102 loadTimeData.getString('PHOTO_IMPORT_DELETE_AFTER');
104 this.pickedCount_ = this.dom_.querySelector('.picked-count'); 103 this.pickedCount_ = this.dom_.querySelector('.picked-count');
105 104
106 this.importButton_ = this.dom_.querySelector('button.import'); 105 this.importButton_ = this.dom_.querySelector('button.import');
107 this.importButton_.textContent = 106 this.importButton_.textContent =
108 loadTimeData.getString('PHOTO_IMPORT_IMPORT_BUTTON'); 107 loadTimeData.getString('PHOTO_IMPORT_IMPORT_BUTTON');
109 this.importButton_.addEventListener('click', this.onImportClick_.bind(this)); 108 this.importButton_.addEventListener('click', this.onImportClick_.bind(this));
110 109
111 this.grid_ = this.dom_.querySelector('grid'); 110 this.grid_ = this.dom_.querySelector('grid');
112 cr.ui.Grid.decorate(this.grid_); 111 cr.ui.Grid.decorate(this.grid_);
113 this.onResize_(); // To set columns number.
114 this.grid_.itemConstructor = 112 this.grid_.itemConstructor =
115 GridItem.bind(null, this); 113 GridItem.bind(null, this);
116 this.fileList_ = new cr.ui.ArrayDataModel([]); 114 this.fileList_ = new cr.ui.ArrayDataModel([]);
117 this.grid_.selectionModel = new cr.ui.ListSelectionModel(); 115 this.grid_.selectionModel = new cr.ui.ListSelectionModel();
118 this.grid_.dataModel = this.fileList_; 116 this.grid_.dataModel = this.fileList_;
119 this.grid_.activateItemAtIndex = this.onActivateItemAtIndex_.bind(this); 117 this.grid_.activateItemAtIndex = this.onActivateItemAtIndex_.bind(this);
120 this.grid_.addEventListener('keypress', this.onGridKeyPress_.bind(this)); 118 this.grid_.addEventListener('keypress', this.onGridKeyPress_.bind(this));
121 this.onPickedItemsChanged_(); 119 this.onPickedItemsChanged_();
122 120
123 this.selectAlbumDialog_ = new SelectAlbumDialog(this.dom_); 121 this.importingDialog_ = new ImportingDialog(this.dom_, this.copyManager_,
122 this.metadataCache_);
124 }; 123 };
125 124
126 /** 125 /**
127 * One-time initialization of albums. 126 * One-time initialization of destination directory.
128 * @private 127 * @private
129 */ 128 */
130 PhotoImport.prototype.initAlbums_ = function() { 129 PhotoImport.prototype.initDestination_ = function() {
131 var onError = this.onError_.bind( 130 var onError = this.onError_.bind(
132 this, loadTimeData.getString('PHOTO_IMPORT_GDATA_ERROR')); 131 this, loadTimeData.getString('PHOTO_IMPORT_GDATA_ERROR'));
133 132
134 var albums = []; 133 var onDirectory = function(dir) {
135 134 this.destination_ = dir;
136 var onEntry = function(entry) { 135 // This may enable the import button, so check that.
137 if (entry != null) { 136 this.onPickedItemsChanged_();
138 albums.push(entry);
139 } else {
140 this.albums_ = albums;
141 }
142 }.bind(this);
143
144 var onGData = function(gdata) {
145 this.albumsDir_ = gdata;
146 util.forEachDirEntry(gdata, onEntry);
147 }.bind(this); 137 }.bind(this);
148 138
149 var onMounted = function() { 139 var onMounted = function() {
150 var dir = PathUtil.join(RootDirectory.GDATA, PhotoImport.GDATA_PHOTOS_DIR); 140 var dir = PathUtil.join(RootDirectory.GDATA, PhotoImport.GDATA_PHOTOS_DIR);
151 util.getOrCreateDirectory(this.filesystem_.root, dir, onGData, onError); 141 util.getOrCreateDirectory(this.filesystem_.root, dir, onDirectory, onError);
152 }.bind(this); 142 }.bind(this);
153 143
154 if (this.volumeManager_.isMounted(RootDirectory.GDATA)) { 144 if (this.volumeManager_.isMounted(RootDirectory.GDATA)) {
155 onMounted(); 145 onMounted();
156 } else { 146 } else {
157 this.volumeManager_.mountGData(onMounted, onError); 147 this.volumeManager_.mountGData(onMounted, onError);
158 } 148 }
159 }; 149 };
160 150
161 /** 151 /**
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 */ 363 */
374 PhotoImport.prototype.onError_ = function(message) { 364 PhotoImport.prototype.onError_ = function(message) {
375 // TODO 365 // TODO
376 }; 366 };
377 367
378 /** 368 /**
379 * Resize event handler. 369 * Resize event handler.
380 * @private 370 * @private
381 */ 371 */
382 PhotoImport.prototype.onResize_ = function() { 372 PhotoImport.prototype.onResize_ = function() {
383 var columns = 373 var g = this.grid_;
384 Math.floor((this.dom_.clientWidth - 60) / PhotoImport.ITEM_WIDTH); 374 g.startBatchUpdates();
385 if (columns != this.grid_.columns) { 375 setTimeout(function() {
386 this.grid_.columns = columns; 376 g.columns = 0;
387 this.fillGrid_(); 377 g.redraw();
388 } 378 g.endBatchUpdates();
379 }, 0);
389 }; 380 };
390 381
391 /** 382 /**
392 * @return {Array.<Object>} The list of picked entries. 383 * @return {Array.<Object>} The list of picked entries.
393 * @private 384 * @private
394 */ 385 */
395 PhotoImport.prototype.getPickedItems_ = function() { 386 PhotoImport.prototype.getPickedItems_ = function() {
396 var list = []; 387 var list = [];
397 for (var i = 0; i < this.fileList_.length; i++) { 388 for (var i = 0; i < this.fileList_.length; i++) {
398 var item = this.fileList_.item(i); 389 var item = this.fileList_.item(i);
399 if (item.picked) 390 if (item.picked)
400 list.push(item); 391 list.push(item);
401 } 392 }
402 return list; 393 return list;
403 }; 394 };
404 395
405 /** 396 /**
406 * Event handler for selection change. 397 * Event handler for picked items change.
407 * @param {Event} event The event.
408 * @private 398 * @private
409 */ 399 */
410 PhotoImport.prototype.onPickedItemsChanged_ = function(event) { 400 PhotoImport.prototype.onPickedItemsChanged_ = function() {
411 var count = this.getPickedItems_().length; 401 var count = this.getPickedItems_().length;
412 this.pickedCount_.textContent = 402 this.pickedCount_.textContent =
413 count == 0 ? 403 count == 0 ?
414 loadTimeData.getString('PHOTO_IMPORT_NOTHING_PICKED') : 404 loadTimeData.getString('PHOTO_IMPORT_NOTHING_PICKED') :
415 count == 1 ? 405 count == 1 ?
416 loadTimeData.getString('PHOTO_IMPORT_ONE_PICKED') : 406 loadTimeData.getString('PHOTO_IMPORT_ONE_PICKED') :
417 loadTimeData.getStringF('PHOTO_IMPORT_MANY_PICKED', count); 407 loadTimeData.getStringF('PHOTO_IMPORT_MANY_PICKED', count);
418 this.importButton_.disabled = count == 0 || this.albums_ == null; 408 this.importButton_.disabled = count == 0 || this.destination_ == null;
419 }; 409 };
420 410
421 /** 411 /**
422 * Event handler for import button click. 412 * Event handler for import button click.
423 * @param {Event} event The event. 413 * @param {Event} event The event.
424 * @private 414 * @private
425 */ 415 */
426 PhotoImport.prototype.onImportClick_ = function(event) { 416 PhotoImport.prototype.onImportClick_ = function(event) {
427 var items = this.getPickedItems_(); 417 var items = this.getPickedItems_();
428 418 var entries = items.map(function(item) { return item.entry; });
429 var defaultTitle = loadTimeData.getString('PHOTO_IMPORT_NEW_ALBUM_NAME'); 419 var move = this.dom_.querySelector('#delete-after-checkbox').checked;
430 var group = items[0].group; 420 this.importingDialog_.show(entries, this.destination_, move);
431 if (items.filter(function(i) { return i.group !== group }).length == 0)
432 defaultTitle = group.title;
433
434 // TODO: use albums instead.
435 var dialogAlbums = [];
436 for (var index = 0; index < this.albums_.length; index++) {
437 dialogAlbums.push({
438 name: this.albums_[index].name,
439 entry: this.albums_[index],
440 url: chrome.extension.getURL('../../images/filetype_large_audio.png')
441 });
442 }
443
444 this.selectAlbumDialog_.show(
445 items.length == 1 ?
446 loadTimeData.getString('PHOTO_IMPORT_SELECT_ALBUM_CAPTION') :
447 loadTimeData.getStringF('PHOTO_IMPORT_SELECT_ALBUM_CAPTION_PLURAL',
448 items.length),
449 dialogAlbums,
450 defaultTitle,
451 loadTimeData.getString('PHOTO_IMPORT_IMPORT_BUTTON'),
452 this.onAlbumSelected_.bind(this, items)
453 );
454 };
455
456 /**
457 * Called when album is selected.
458 * @param {Array.<Object>} items List of items to import.
459 * @param {Object} album Album description.
460 * @private
461 */
462 PhotoImport.prototype.onAlbumSelected_ = function(items, album) {
463 var entries = items.map(function(i) { return i.entry });
464
465 if (album.create) {
466 var onError = this.onError_.bind(this,
467 loadTimeData.getString('PHOTO_IMPORT_IMPORTING_ERROR'));
468 this.createAlbum_(album.name,
469 this.startImport_.bind(this, entries),
470 onError);
471 } else {
472 this.startImport_(entries, album.entry);
473 }
474 };
475
476 /**
477 * Starts importing process.
478 * @param {Array.<FileEntry>} entries List of entries to import.
479 * @param {DirectoryEntry} dir Where to import.
480 * @private
481 */
482 PhotoImport.prototype.startImport_ = function(entries, dir) {
483 var files = entries.map(function(e) { return e.fullPath }).join('\n');
484 var operationInfo = {
485 isCut: false,
486 isOnGData: PathUtil.getRootType(entries[0].fullPath) == RootType.GDATA,
487 sourceDir: null,
488 directories: '',
489 files: files
490 };
491 this.copyManager_.paste(operationInfo, dir.fullPath, true);
492 };
493
494 /**
495 * Creates a directory for an album.
496 * @param {string} name Album name.
497 * @param {function(DirectoryEntry)} onSuccess Success callback.
498 * @param {function} onError Failure callback.
499 * @private
500 */
501 PhotoImport.prototype.createAlbum_ = function(name, onSuccess, onError) {
502 var callback = function(entry) {
503 this.initAlbums_();
504 onSuccess(entry);
505 }.bind(this);
506
507 this.albumsDir_.getDirectory(name, { create: true, exclusive: true},
508 callback, onError);
509 }; 421 };
510 422
511 /** 423 /**
512 * Item in the grid. 424 * Item in the grid.
513 * @param {PhotoImport} app Application instance. 425 * @param {PhotoImport} app Application instance.
514 * @param {Entry} entry File entry. 426 * @param {Entry} entry File entry.
515 * @constructor 427 * @constructor
516 */ 428 */
517 function GridItem(app, entry) { 429 function GridItem(app, entry) {
518 var li = app.document_.createElement('li'); 430 var li = app.document_.createElement('li');
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 529
618 /** @inheritDoc */ 530 /** @inheritDoc */
619 GridSelectionController.prototype.getLastIndex = function() { 531 GridSelectionController.prototype.getLastIndex = function() {
620 var dm = this.grid_.dataModel; 532 var dm = this.grid_.dataModel;
621 for (var index = dm.length - 1; index >= 0; index--) { 533 for (var index = dm.length - 1; index >= 0; index--) {
622 if (dm.item(index).type == 'entry') 534 if (dm.item(index).type == 'entry')
623 return index; 535 return index;
624 } 536 }
625 return -1; 537 return -1;
626 }; 538 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698