| OLD | NEW |
| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 document.addEventListener('DOMContentLoaded', function() { | 7 document.addEventListener('DOMContentLoaded', function() { |
| 8 ActionChoice.load(); | 8 ActionChoice.load(); |
| 9 }); | 9 }); |
| 10 | 10 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 this.document_.querySelector('.choices').appendChild(this.list_); | 160 this.document_.querySelector('.choices').appendChild(this.list_); |
| 161 | 161 |
| 162 var self = this; // .bind(this) doesn't work on constructors. | 162 var self = this; // .bind(this) doesn't work on constructors. |
| 163 this.list_.itemConstructor = function(item) { | 163 this.list_.itemConstructor = function(item) { |
| 164 return self.renderItem(item); | 164 return self.renderItem(item); |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 this.list_.selectionModel = new cr.ui.ListSingleSelectionModel(); | 167 this.list_.selectionModel = new cr.ui.ListSingleSelectionModel(); |
| 168 this.list_.dataModel = new cr.ui.ArrayDataModel([]); | 168 this.list_.dataModel = new cr.ui.ArrayDataModel([]); |
| 169 this.list_.autoExpands = true; | 169 this.list_.autoExpands = true; |
| 170 this.list_.activateItemAtIndex = function(index) { | 170 |
| 171 var acceptActionBound = function() { |
| 171 this.acceptAction_(); | 172 this.acceptAction_(); |
| 172 }.bind(this); | 173 }.bind(this); |
| 174 this.list_.activateItemAtIndex = acceptActionBound; |
| 175 this.list_.addEventListener('click', acceptActionBound); |
| 173 | 176 |
| 174 this.previews_ = this.document_.querySelector('.previews'); | 177 this.previews_ = this.document_.querySelector('.previews'); |
| 175 this.counter_ = this.document_.querySelector('.counter'); | 178 this.counter_ = this.document_.querySelector('.counter'); |
| 176 | |
| 177 this.document_.querySelector('button.ok').addEventListener('click', | |
| 178 function(event) { | |
| 179 this.acceptAction_(); | |
| 180 }.bind(this)); | |
| 181 | |
| 182 this.document_.addEventListener('keydown', this.onKeyDown_.bind(this)); | 179 this.document_.addEventListener('keydown', this.onKeyDown_.bind(this)); |
| 183 | 180 |
| 184 metrics.startInterval('PhotoImport.Load'); | 181 metrics.startInterval('PhotoImport.Load'); |
| 185 this.dom_.setAttribute('loading', ''); | 182 this.dom_.setAttribute('loading', ''); |
| 186 | 183 |
| 187 util.disableBrowserShortcutKeys(this.document_); | 184 util.disableBrowserShortcutKeys(this.document_); |
| 188 }; | 185 }; |
| 189 | 186 |
| 190 /** | 187 /** |
| 191 * Renders the list. | 188 * Renders the list. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 * @param {string} source Path to source. | 267 * @param {string} source Path to source. |
| 271 * @param {function()} callback Completion callback. | 268 * @param {function()} callback Completion callback. |
| 272 * @private | 269 * @private |
| 273 */ | 270 */ |
| 274 ActionChoice.prototype.loadSource_ = function(source, callback) { | 271 ActionChoice.prototype.loadSource_ = function(source, callback) { |
| 275 var onTraversed = function(results) { | 272 var onTraversed = function(results) { |
| 276 metrics.recordInterval('PhotoImport.Scan'); | 273 metrics.recordInterval('PhotoImport.Scan'); |
| 277 var videos = results.filter(FileType.isVideo); | 274 var videos = results.filter(FileType.isVideo); |
| 278 if (videos.length == 1) { | 275 if (videos.length == 1) { |
| 279 this.singleVideo_ = videos[0]; | 276 this.singleVideo_ = videos[0]; |
| 280 this.enabledOptions_.push(ActionChoice.Action.PLAY_VIDEO); | 277 this.enabledOptions_.push(ActionChoice.Action.WATCH_SINGLE_VIDEO); |
| 281 this.watchSingleVideoItem_.title = loadTimeData.getStringF( | 278 this.watchSingleVideoItem_.title = loadTimeData.getStringF( |
| 282 'ACTION_CHOICE_WATCH_SINGLE_VIDEO', videos[0].name); | 279 'ACTION_CHOICE_WATCH_SINGLE_VIDEO', videos[0].name); |
| 283 this.watchSingleVideoItem_.hidden = false; | 280 this.watchSingleVideoItem_.hidden = false; |
| 284 this.renderList_(); | 281 this.renderList_(); |
| 285 } | 282 } |
| 286 | 283 |
| 287 var mediaFiles = results.filter(FileType.isImageOrVideo); | 284 var mediaFiles = results.filter(FileType.isImageOrVideo); |
| 288 if (mediaFiles.length == 0) { | 285 if (mediaFiles.length == 0) { |
| 289 // If we have no media files, the only choice is view files. So, don't | 286 // If we have no media files, the only choice is view files. So, don't |
| 290 // confuse user with a single choice, and just open file manager. | 287 // confuse user with a single choice, and just open file manager. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 window.close(); | 391 window.close(); |
| 395 }; | 392 }; |
| 396 | 393 |
| 397 /** | 394 /** |
| 398 * Keydown event handler. | 395 * Keydown event handler. |
| 399 * @param {Event} e The event. | 396 * @param {Event} e The event. |
| 400 * @private | 397 * @private |
| 401 */ | 398 */ |
| 402 ActionChoice.prototype.onKeyDown_ = function(e) { | 399 ActionChoice.prototype.onKeyDown_ = function(e) { |
| 403 switch (util.getKeyModifiers(e) + e.keyCode) { | 400 switch (util.getKeyModifiers(e) + e.keyCode) { |
| 401 case '13': |
| 402 this.acceptAction_(); |
| 403 break; |
| 404 case '27': | 404 case '27': |
| 405 this.recordAction_('close'); | 405 this.recordAction_('close'); |
| 406 this.close_(); | 406 this.close_(); |
| 407 return; | 407 break; |
| 408 } | 408 } |
| 409 }; | 409 }; |
| 410 | 410 |
| 411 /** | 411 /** |
| 412 * Runs an action. | 412 * Runs an action. |
| 413 * @param {ActionChoice.Action} action Action to perform. | 413 * @param {ActionChoice.Action} action Action to perform. |
| 414 * @private | 414 * @private |
| 415 */ | 415 */ |
| 416 ActionChoice.prototype.runAction_ = function(action) { | 416 ActionChoice.prototype.runAction_ = function(action) { |
| 417 switch (action) { | 417 switch (action) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 */ | 507 */ |
| 508 ActionChoice.prototype.recordAction_ = function(action) { | 508 ActionChoice.prototype.recordAction_ = function(action) { |
| 509 metrics.recordEnum('PhotoImport.Action', action, | 509 metrics.recordEnum('PhotoImport.Action', action, |
| 510 ['import-photos-to-drive', | 510 ['import-photos-to-drive', |
| 511 'view-files', | 511 'view-files', |
| 512 'view-files-auto', | 512 'view-files-auto', |
| 513 'watch-single-video', | 513 'watch-single-video', |
| 514 'error', | 514 'error', |
| 515 'close']); | 515 'close']); |
| 516 }; | 516 }; |
| OLD | NEW |