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);
40 var applyAllLine = parentNode.ownerDocument.createElement('div');
41 applyAllLine.className = 'apply-all-line';
42 applyAllLine.appendChild(this.applyAllCheckbox_);
43 applyAllLine.appendChild(applyAllLabel);
46 * Element of the keep both button.
50 this.keepBothButton_ = parentNode.ownerDocument.createElement('button');
51 this.keepBothButton_.textContent = str('CONFLICT_DIALOG_KEEP_BOTH');
52 this.keepBothButton_.addEventListener(
54 this.hideWithResult_.bind(this, ConflictDialog.Result.KEEP_BOTH));
57 * Element of the replace button.
61 this.replaceButton_ = parentNode.ownerDocument.createElement('button');
62 this.replaceButton_.textContent = str('CONFLICT_DIALOG_REPLACE');
63 this.replaceButton_.addEventListener(
65 this.hideWithResult_.bind(this, ConflictDialog.Result.REPLACE));
68 var buttons = this.okButton_.parentNode;
69 buttons.replaceChild(this.keepBothButton_, this.okButton_);
70 buttons.appendChild(this.replaceButton_);
73 this.frame_.id = 'conflict-confirm-dialog';
74 this.frame_.insertBefore(applyAllLine, buttons);
78 * Result of conflict confirm dialogs.
82 ConflictDialog.Result = Object.freeze({
83 KEEP_BOTH: 'keepBoth',
88 ConflictDialog.prototype = {
89 __proto__: FileManagerDialogBase.prototype
93 * Shows the conflict confirm dialog.
95 * @param {string} fileName Filename that is conflicted.
96 * @param {function(ConflictDialog.Result, boolean)} callback Complete
97 * callbak. See also ConflictDialog#callback_.
98 * @return {boolean} True if the dialog can show successfully. False if the
99 * dialog failed to show due to an existing dialog.
101 ConflictDialog.prototype.show = function(fileName, callback) {
105 this.callback_ = callback;
106 FileManagerDialogBase.prototype.showOkCancelDialog.call(
108 str('CONFLICT_DIALOG_TITLE'),
109 strf('CONFLICT_DIALOG_MESSAGE', fileName));
114 * Handles cancellation.
115 * @param {Event} event Click event.
118 ConflictDialog.prototype.onCancelClick_ = function(event) {
119 this.hideWithResult_(ConflictDialog.Result.CANCEL);
123 * Hides the dialog box with the result.
124 * @param {ConflictDialog.Result} result Result.
127 ConflictDialog.prototype.hideWithResult_ = function(result) {
128 this.hide(function() {
131 this.callback_(result, this.applyAllCheckbox_.checked);
132 this.callback_ = null;
133 this.applyAllCheckbox_.checked = false;