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

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_ = this.document_.createElement('div');
Vladislav Kaznacheev 2012/09/19 12:29:52 I suggest using util.createChild here which is muc
dgozman 2012/09/19 13:45:28 Done.
34 this.imageBox_.classList.add('img-container');
35 this.frame_.appendChild(this.imageBox_);
36
37 var progressContainer = this.document_.createElement('div');
38 progressContainer.className = 'progress-container';
39 this.frame_.appendChild(progressContainer);
40
41 progressContainer.appendChild(this.text_);
42
43 this.progress_ = this.document_.createElement('div');
44 this.progress_.className = 'progress-bar';
45 var track = this.document_.createElement('div');
46 track.className = 'progress-track';
47 this.progress_.appendChild(track);
48 progressContainer.appendChild(this.progress_);
49
50 this.cancelButton_.textContent =
51 loadTimeData.getString('PHOTO_IMPORT_CANCEL_BUTTON');
52 this.frame_.appendChild(this.cancelButton_);
53
54 this.okButton_.textContent =
55 loadTimeData.getString('OK_LABEL');
56 };
57
58 /**
59 * Shows dialog.
60 * @param {Array.<FileEntry>} entries Entries to import.
61 * @param {DirectoryEntry} dir Directory to import to.
62 * @param {boolean} move Whether to move files instead of copying them.
63 */
64 ImportingDialog.prototype.show = function(entries, dir, move) {
65 var message = loadTimeData.getStringF(
66 'PHOTO_IMPORT_IMPORTING', entries.length);
67 cr.ui.dialogs.BaseDialog.prototype.show.call(this, message, null, null, null);
68
69 this.error_ = false;
70 this.entries_ = entries;
71 this.progress_.querySelector('.progress-track').style.width = '0';
72
73 this.copyManager_.addEventListener('copy-progress',
74 this.onCopyProgressBound_);
75
76 this.previewEntry_(0);
77
78 var files = entries.map(function(e) { return e.fullPath }).join('\n');
79 var operationInfo = {
80 isCut: move ? 'true' : 'false',
81 isOnGData: PathUtil.getRootType(entries[0].fullPath) == RootType.GDATA,
82 sourceDir: null,
83 directories: '',
84 files: files
85 };
86 this.copyManager_.paste(operationInfo, dir.fullPath, true);
87 };
88
89 /**
90 * Shows entry preview.
91 * @param {number} index Entry index.
92 * @private
93 */
94 ImportingDialog.prototype.previewEntry_ = function(index) {
95 var box = this.imageBox_;
96 var entry = this.entries_[index];
97 this.metadataCache_.get(entry, 'thumbnail|filesystem',
98 function(metadata) {
99 new ThumbnailLoader(entry.toURL(), metadata).
100 load(box, true /* fill, not fit */);
101 });
102 };
103
104 /**
105 * Closes dialog.
106 */
107 ImportingDialog.prototype.hide = function() {
108 this.copyManager_.removeEventListener('copy-progress',
109 this.onCopyProgressBound_);
110 cr.ui.dialogs.BaseDialog.prototype.hide.call(this);
111 };
112
113 /**
114 * Cancel button click event handler.
115 * @private
116 */
117 ImportingDialog.prototype.onCancelClick_ = function() {
118 this.copyManager_.requestCancel();
119 this.hide();
120 };
121
122 /**
123 * OK button click event handler.
124 * @private
125 */
126 ImportingDialog.prototype.onOkClick_ = function() {
127 this.hide();
128 if (!this.error_)
129 window.close();
130 };
131
132 /**
133 * Event handler for keydown event.
134 * @param {Event} event The event.
135 * @private
136 */
137 ImportingDialog.prototype.onContainerKeyDown_ = function(event) {
138 // Handle Escape.
139 if (event.keyCode == 27) {
140 this.onCancelClick_(event);
141 event.preventDefault();
142 }
143 };
144
145 /**
146 * 'copy-progress' event handler. Show progress.
147 * @param {cr.Event} event A 'copy-progress' event from FileCopyManager.
148 * @private
149 */
150 ImportingDialog.prototype.onCopyProgress_ = function(event) {
151 console.log('got: ', event.reason);
Vladislav Kaznacheev 2012/09/19 12:29:52 I forgot to remove this line
Vladislav Kaznacheev 2012/09/19 12:30:30 I meant YOU forgot:) On 2012/09/19 12:29:52, Vladi
dgozman 2012/09/19 13:45:28 Done.
152 switch (event.reason) {
153 case 'BEGIN':
154 case 'PROGRESS':
155 var progress = this.copyManager_.getStatus().percentage;
156 this.progress_.querySelector('.progress-track').style.width =
157 (progress * 100) + '%';
158 var index = Math.round(this.entries_.length * progress);
159 if (index == this.entries_.length) index--;
160 this.previewEntry_(index);
161 break;
162
163 case 'SUCCESS':
164 this.text_.textContent =
165 loadTimeData.getString('PHOTO_IMPORT_IMPORT_COMPLETE');
166 this.progress_.querySelector('.progress-track').style.
167 webkitAnimationName = '';
168 this.frame_.removeChild(this.cancelButton_);
169 this.frame_.appendChild(this.okButton_);
170 break;
171
172 case 'CANCELLED':
173 this.hide();
174 break;
175
176 case 'ERROR':
177 this.error_ = true;
178 this.text_.textContent =
179 loadTimeData.getString('PHOTO_IMPORT_IMPORTING_ERROR');
180 this.progress_.querySelector('.progress-track').style.
181 webkitAnimationName = '';
182 this.frame_.removeChild(this.cancelButton_);
183 this.frame_.appendChild(this.okButton_);
184 break;
185
186 default:
187 console.log('Unknown "copy-progress" event reason: ' + event.reason);
Vladislav Kaznacheev 2012/09/19 12:29:52 This deserves console.warn or even console.error
dgozman 2012/09/19 13:45:28 Done.
188 }
189 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698