1 // Copyright 2013 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.
6 * Dialog to confirm the operation for conflicted file operations.
8 * @param {HTMLElement} parentNode Node to be parent for this dialog.
10 * @extends {FileManagerDialogBase}
12 function ConflictDialog(parentNode) {
13 FileManagerDialogBase.call(this, parentNode);
16 * Callback to be called when the showing task is completed. The first
17 * argument is which button is pressed. The second argument is whether to
20 * @type {?function(ConflictDialog.Result, boolean)}
23 this.callback_ = null;
26 * Checkbox to specify whether to apply the selection to all entries or not.
30 this.applyAllCheckbox_ = parentNode.ownerDocument.createElement('input');
31 this.applyAllCheckbox_.id = 'conflict-confirm-dialog-apply-all-checkbox';
32 this.applyAllCheckbox_.type = 'checkbox';
35 var applyAllLabel = parentNode.ownerDocument.createElement('label');
36 applyAllLabel.textContent = str('CONFLICT_DIALOG_APPLY_TO_ALL');
37 applyAllLabel.setAttribute('for', this.applyAllCheckbox_.id);
40 * Element of the keep both button.
44 this.keepBothButton_ = parentNode.ownerDocument.createElement('button');
45 this.keepBothButton_.textContent = str('CONFLICT_DIALOG_KEEP_BOTH');
46 this.keepBothButton_.addEventListener(
48 this.hideWithResult_.bind(this, ConflictDialog.Result.KEEP_BOTH));
51 * Element of the replace button.
55 this.replaceButton_ = parentNode.ownerDocument.createElement('button');
56 this.replaceButton_.textContent = str('CONFLICT_DIALOG_REPLACE');
57 this.replaceButton_.addEventListener(
59 this.hideWithResult_.bind(this, ConflictDialog.Result.REPLACE));
62 var buttons = this.okButton_.parentNode;
63 buttons.insertBefore(this.applyAllCheckbox_, this.okButton_);
64 buttons.insertBefore(applyAllLabel, this.okButton_);
65 buttons.replaceChild(this.keepBothButton_, this.okButton_);
66 buttons.appendChild(this.replaceButton_);
69 this.frame_.id = 'conflict-confirm-dialog';
73 * Result of conflict confirm dialogs.
77 ConflictDialog.Result = {
78 KEEP_BOTH: 'keepBoth',
82 Object.freeze(ConflictDialog.Result);
84 ConflictDialog.prototype = {
85 __proto__: FileManagerDialogBase.prototype
89 * Shows the conflict confirm dialog.
91 * @param {string} fileName Filename that is conflicted.
92 * @param {function(ConflictDialog.Result, boolean)} callback Complete
93 * callback. See also ConflictDialog#callback_.
94 * @return {boolean} True if the dialog can show successfully. False if the
95 * dialog failed to show due to an existing dialog.
97 ConflictDialog.prototype.show = function(fileName, callback) {
101 this.callback_ = callback;
102 FileManagerDialogBase.prototype.showOkCancelDialog.call(
104 '', // We dont't show the title for the dialog.
105 strf('CONFLICT_DIALOG_MESSAGE', fileName));
110 * Handles cancellation.
111 * @param {Event} event Click event.
114 ConflictDialog.prototype.onCancelClick_ = function(event) {
115 this.hideWithResult_(ConflictDialog.Result.CANCEL);
119 * Hides the dialog box with the result.
120 * @param {ConflictDialog.Result} result Result.
123 ConflictDialog.prototype.hideWithResult_ = function(result) {
124 this.hide(function() {
127 this.callback_(result, this.applyAllCheckbox_.checked);
128 this.callback_ = null;
129 this.applyAllCheckbox_.checked = false;