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

Side by Side Diff: chrome/browser/resources/file_manager/js/photo/importing_dialog.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
(Empty)
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
3 // found in the LICENSE file.
4
5
6 /**
7 * ImportingDialog manages the import process (which is really a copying).
8 * @param {HTMLElement} parentNode Node to be parent for this dialog.
9 * @param {FileCopyManager} copyManager Copy manager isntance.
10 * @param {MetadataCache} metadataCache Metadata cache.
11 */
12 function ImportingDialog(parentNode, copyManager, metadataCache) {
13 cr.ui.dialogs.BaseDialog.call(this, parentNode);
14 this.copyManager_ = copyManager;
15 this.metadataCache_ = metadataCache;
16 this.onCopyProgressBound_ = this.onCopyProgress_.bind(this);
17 }
18
19 ImportingDialog.prototype = {
20 __proto__: cr.ui.dialogs.BaseDialog.prototype
21 };
22
23 /**
24 * One-time initialization of DOM.
25 * @private
26 */
27 ImportingDialog.prototype.initDom_ = function() {
28 cr.ui.dialogs.BaseDialog.prototype.initDom_.call(this);
29
30 this.container_.classList.add('importing-dialog');
31 this.frame_.textContent = '';
32
33 this.imageBox_ = util.createChild(this.frame_, 'img-container');
34
35 var progressContainer = util.createChild(this.frame_, 'progress-container');
36 progressContainer.appendChild(this.text_);
37
38 this.progress_ = util.createChild(progressContainer, 'progress-bar');
39 util.createChild(this.progress_, 'progress-track');
40
41 this.cancelButton_.textContent =
42 loadTimeData.getString('PHOTO_IMPORT_CANCEL_BUTTON');
43 this.frame_.appendChild(this.cancelButton_);
44
45 this.okButton_.textContent =
46 loadTimeData.getString('OK_LABEL');
47 };
48
49 /**
50 * Shows dialog.
51 * @param {Array.<FileEntry>} entries Entries to import.
52 * @param {DirectoryEntry} dir Directory to import to.
53 * @param {boolean} move Whether to move files instead of copying them.
54 */
55 ImportingDialog.prototype.show = function(entries, dir, move) {
56 var message = loadTimeData.getStringF(
57 'PHOTO_IMPORT_IMPORTING', entries.length);
58 cr.ui.dialogs.BaseDialog.prototype.show.call(this, message, null, null, null);
59
60 this.error_ = false;
61 this.entries_ = entries;
62 this.progress_.querySelector('.progress-track').style.width = '0';
63
64 this.copyManager_.addEventListener('copy-progress',
65 this.onCopyProgressBound_);
66
67 this.previewEntry_(0);
68
69 var files = entries.map(function(e) { return e.fullPath }).join('\n');
70 var operationInfo = {
71 isCut: move ? 'true' : 'false',
72 isOnGData: PathUtil.getRootType(entries[0].fullPath) == RootType.GDATA,
73 sourceDir: null,
74 directories: '',
75 files: files
76 };
77 this.copyManager_.paste(operationInfo, dir.fullPath, true);
78 };
79
80 /**
81 * Shows entry preview.
82 * @param {number} index Entry index.
83 * @private
84 */
85 ImportingDialog.prototype.previewEntry_ = function(index) {
86 var box = this.imageBox_;
87 var entry = this.entries_[index];
88 this.metadataCache_.get(entry, 'thumbnail|filesystem',
89 function(metadata) {
90 new ThumbnailLoader(entry.toURL(), metadata).
91 load(box, true /* fill, not fit */);
92 });
93 };
94
95 /**
96 * Closes dialog.
97 */
98 ImportingDialog.prototype.hide = function() {
99 this.copyManager_.removeEventListener('copy-progress',
100 this.onCopyProgressBound_);
101 cr.ui.dialogs.BaseDialog.prototype.hide.call(this);
102 };
103
104 /**
105 * Cancel button click event handler.
106 * @private
107 */
108 ImportingDialog.prototype.onCancelClick_ = function() {
109 this.copyManager_.requestCancel();
110 this.hide();
111 };
112
113 /**
114 * OK button click event handler.
115 * @private
116 */
117 ImportingDialog.prototype.onOkClick_ = function() {
118 this.hide();
119 if (!this.error_)
120 window.close();
121 };
122
123 /**
124 * Event handler for keydown event.
125 * @param {Event} event The event.
126 * @private
127 */
128 ImportingDialog.prototype.onContainerKeyDown_ = function(event) {
129 // Handle Escape.
130 if (event.keyCode == 27) {
131 this.onCancelClick_(event);
132 event.preventDefault();
133 }
134 };
135
136 /**
137 * 'copy-progress' event handler. Show progress.
138 * @param {cr.Event} event A 'copy-progress' event from FileCopyManager.
139 * @private
140 */
141 ImportingDialog.prototype.onCopyProgress_ = function(event) {
142 switch (event.reason) {
143 case 'BEGIN':
144 case 'PROGRESS':
145 var progress = this.copyManager_.getStatus().percentage;
146 this.progress_.querySelector('.progress-track').style.width =
147 (progress * 100) + '%';
148 var index = Math.round(this.entries_.length * progress);
149 if (index == this.entries_.length) index--;
150 this.previewEntry_(index);
151 break;
152
153 case 'SUCCESS':
154 this.text_.textContent =
155 loadTimeData.getString('PHOTO_IMPORT_IMPORT_COMPLETE');
156 this.progress_.querySelector('.progress-track').style.
157 backgroundImage = 'none';
158 this.frame_.removeChild(this.cancelButton_);
159 this.frame_.appendChild(this.okButton_);
160 break;
161
162 case 'CANCELLED':
163 this.hide();
164 break;
165
166 case 'ERROR':
167 this.error_ = true;
168 this.text_.textContent =
169 loadTimeData.getString('PHOTO_IMPORT_IMPORTING_ERROR');
170 this.progress_.querySelector('.progress-track').style.
171 backgroundImage = 'none';
172 this.frame_.removeChild(this.cancelButton_);
173 this.frame_.appendChild(this.okButton_);
174 break;
175
176 default:
177 console.error('Unknown "copy-progress" event reason: ' + event.reason);
178 }
179 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698