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.
8 * Dialog to confirm the operation for conflicted file operations.
10 * @param {HTMLElement} parentNode Node to be parent for this dialog.
12 * @extends {FileManagerDialogBase}
14 function ConflictDialog(parentNode) {
15 FileManagerDialogBase.call(this, parentNode);
18 * Callback to be called when the showing task is completed. The first
19 * argument is which button is pressed. The second argument is whether to
22 * @type {function(ConflictDialog.Result, boolean)}
25 this.callback_ = null;
28 * Checkbox to specify whether to apply the selection to all entries or not.
32 this.applyAllCheckbox_ = parentNode.ownerDocument.createElement('input');
33 this.applyAllCheckbox_.id = 'conflict-confirm-dialog-apply-all-checkbox';
34 this.applyAllCheckbox_.type = 'checkbox';
37 var applyAllLabel = parentNode.ownerDocument.createElement('label');
38 applyAllLabel.textContent = str('CONFLICT_DIALOG_APPLY_TO_ALL');
39 applyAllLabel.setAttribute('for', this.applyAllCheckbox_.id);
42 * Element of the keep both button.
46 this.keepBothButton_ = parentNode.ownerDocument.createElement('button');
47 this.keepBothButton_.textContent = str('CONFLICT_DIALOG_KEEP_BOTH');
48 this.keepBothButton_.addEventListener(
50 this.hideWithResult_.bind(this, ConflictDialog.Result.KEEP_BOTH));
53 * Element of the replace button.
57 this.replaceButton_ = parentNode.ownerDocument.createElement('button');
58 this.replaceButton_.textContent = str('CONFLICT_DIALOG_REPLACE');
59 this.replaceButton_.addEventListener(
61 this.hideWithResult_.bind(this, ConflictDialog.Result.REPLACE));
64 var buttons = this.okButton_.parentNode;
65 buttons.insertBefore(this.applyAllCheckbox_, this.okButton_);
66 buttons.insertBefore(applyAllLabel, this.okButton_);
67 buttons.replaceChild(this.keepBothButton_, this.okButton_);
68 buttons.appendChild(this.replaceButton_);
71 this.frame_.id = 'conflict-confirm-dialog';
75 * Result of conflict confirm dialogs.
79 ConflictDialog.Result = Object.freeze({
80 KEEP_BOTH: 'keepBoth',
85 ConflictDialog.prototype = {
86 __proto__: FileManagerDialogBase.prototype
90 * Shows the conflict confirm dialog.
92 * @param {string} fileName Filename that is conflicted.
93 * @param {function(ConflictDialog.Result, boolean)} callback Complete
94 * callbak. See also ConflictDialog#callback_.
95 * @return {boolean} True if the dialog can show successfully. False if the
96 * dialog failed to show due to an existing dialog.
98 ConflictDialog.prototype.show = function(fileName, callback) {
102 this.callback_ = callback;
103 FileManagerDialogBase.prototype.showOkCancelDialog.call(
105 '', // We dont't show the title for the dialog.
106 strf('CONFLICT_DIALOG_MESSAGE', fileName));
111 * Handles cancellation.
112 * @param {Event} event Click event.
115 ConflictDialog.prototype.onCancelClick_ = function(event) {
116 this.hideWithResult_(ConflictDialog.Result.CANCEL);
120 * Hides the dialog box with the result.
121 * @param {ConflictDialog.Result} result Result.
124 ConflictDialog.prototype.hideWithResult_ = function(result) {
125 this.hide(function() {
128 this.callback_(result, this.applyAllCheckbox_.checked);
129 this.callback_ = null;
130 this.applyAllCheckbox_.checked = false;