Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/default_action_dialog.js |
| diff --git a/chrome/browser/resources/file_manager/js/default_action_dialog.js b/chrome/browser/resources/file_manager/js/default_action_dialog.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f869beec05356babef34d7444861a94eaa36c456 |
| --- /dev/null |
| +++ b/chrome/browser/resources/file_manager/js/default_action_dialog.js |
| @@ -0,0 +1,110 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| + |
| +/** |
| + * PromptDialog contains a message, a text input, an ok button, and a |
|
dgozman
2012/05/18 14:50:06
Copypasted comment.
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
|
| + * cancel button. |
| + */ |
| +cr.define('cr.filebrowser', function() { |
| + function DefaultActionDialog(parentNode) { |
|
dgozman
2012/05/18 14:50:06
No JSDoc.
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
|
| + cr.ui.dialogs.BaseDialog.apply(this, [parentNode]); |
|
dgozman
2012/05/18 14:50:06
If you have explicit arguments, better use |call|.
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
|
| + |
| + this.list_ = this.document_.createElement('list'); |
| + this.list_.id = 'default-actions-list'; |
| + this.frame_.insertBefore(this.list_, this.text_.nextSibling); |
| + |
| + cr.ui.List.decorate(this.list_); |
|
dgozman
2012/05/18 14:50:06
I believe, you can just |this.list_ = new cr.ui.Li
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
|
| + this.selectionModel_ = this.list_.selectionModel = |
| + new cr.ui.ListSingleSelectionModel(); |
| + this.dataModel_ = this.list_.dataModel = new cr.ui.ArrayDataModel([]); |
| + this.list_.autoExpands = true; |
|
dgozman
2012/05/18 14:50:06
This really means that dialog is not constrained i
Dmitry Zvorygin
2012/05/22 14:32:59
Added comment.
|
| + this.list_.activateItemAtIndex = this.activateItemAtIndex_.bind(this); |
| + |
| + this.initialFocusElement_ = this.list_; |
| + |
| + var self = this; |
| + |
| + this.list_.itemConstructor = function(item) { |
|
dgozman
2012/05/18 14:50:06
this.list_.itemConstructor = this.renderItem.bind(
Dmitry Zvorygin
2012/05/22 14:32:59
Binding stuff doesn't work with constructors. See
|
| + return self.renderItem(item); |
| + } |
| + } |
| + |
| + DefaultActionDialog.prototype = { |
| + __proto__: cr.ui.dialogs.BaseDialog.prototype |
| + }; |
| + |
| + DefaultActionDialog.prototype.onInputFocus = function() { |
| + this.list_.select(); |
| + }; |
| + |
| + DefaultActionDialog.prototype.onKeyDown_ = function(event) { |
| + if (event.keyCode == 13) // Enter |
| + this.onOkClick_(event); |
| + }; |
| + |
| + DefaultActionDialog.prototype.renderItem = function(item) { |
| + var result = this.document_.createElement('li'); |
| + |
| + var iconNode = this.document_.createElement('img'); |
| + iconNode.src = item.iconUrl; |
| + result.appendChild(iconNode); |
| + |
| + var labelNode = this.document_.createElement('span'); |
| + labelNode.textContent = item.title; |
| + result.appendChild(labelNode); |
| + |
| + cr.defineProperty(result, 'lead', cr.PropertyKind.BOOL_ATTR); |
| + cr.defineProperty(result, 'selected', cr.PropertyKind.BOOL_ATTR); |
| + |
| + return result; |
| + } |
| + |
| + DefaultActionDialog.prototype.show = function(message, tasksList, onOk, |
| + onCancel, onShow) { |
| + |
| + cr.ui.dialogs.BaseDialog.prototype.show.apply(this, |
| + [message, onOk, onCancel, onShow]); |
| + |
| + this.list_.startBatchUpdates(); |
| + |
| + this.dataModel_.splice(0, this.dataModel_.length); |
| + |
| + for (var i = 0; i < tasksList.length; i++) { |
| + this.dataModel_.push(tasksList[i]); |
|
dgozman
2012/05/18 14:50:06
Instead of pushing n times, use one splice?
Dmitry Zvorygin
2012/05/22 14:32:59
Splice requires items passed as parameters, not as
|
| + } |
| + |
| + this.selectionModel_.selectedIndex = 0; |
| + |
| + this.list_.endBatchUpdates(); |
| + }; |
| + |
| + DefaultActionDialog.prototype.getValue = function() { |
| + return this.list_.value; |
|
dgozman
2012/05/18 14:50:06
Wow, list has |value| method?
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
|
| + }; |
| + |
| + DefaultActionDialog.prototype.activateItemAtIndex_ = function(index) { |
| + this.hide(); |
| + if (this.onOk_) |
| + this.onOk_(this.dataModel_.item(index)); |
| + } |
| + |
| + DefaultActionDialog.prototype.onOkClick_ = function() { |
| + this.activateItemAtIndex_(this.selectionModel_.selectedIndex); |
| + }; |
| + |
| + DefaultActionDialog.prototype.onContainerKeyDown_ = function(event) { |
|
dgozman
2012/05/18 14:50:06
Where do you add this listener?
Dmitry Zvorygin
2012/05/22 14:32:59
Added comment.
|
| + // Handle Escape. |
| + if (event.keyCode == 27 && !this.cancelButton_.disabled) { |
| + this.onCancelClick_(event); |
| + event.preventDefault(); |
| + } else if (!this.okButton_.disabled && |
|
dgozman
2012/05/18 14:50:06
How can it be disabled?
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
|
| + (event.keyCode == 32 || event.keyCode == 13)) { |
| + this.onOkClick_(); |
| + event.preventDefault(); |
| + } |
| + }; |
| + |
| + return {DefaultActionDialog: DefaultActionDialog}; |
| +}); |