• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5'use strict';
6
7/**
8 * This class is an extended class, to manage the status of the dialogs.
9 *
10 * @param {HTMLElement} parentNode Parent node of the dialog.
11 * @extends {cr.ui.dialogs.FileManagerDialogBase}
12 * @constructor
13 */
14var FileManagerDialogBase = function(parentNode) {
15  cr.ui.dialogs.BaseDialog.call(this, parentNode);
16};
17
18FileManagerDialogBase.prototype = {
19  __proto__: cr.ui.dialogs.BaseDialog.prototype
20};
21
22/**
23 * The FileManager object. This is used to notify events of showing or hiding
24 * dialog to file manager.
25 *
26 * @type {FileManager}
27 * @private
28 */
29FileManagerDialogBase.fileManager_ = null;
30
31/**
32 * Setter of FileManagerDialogBase.fileManager_.
33 * @param {FileManager} fileManager The fileManager object.
34 */
35FileManagerDialogBase.setFileManager = function(fileManager) {
36  FileManagerDialogBase.fileManager_ = fileManager;
37};
38
39/**
40 * The flag if any dialog is shown. True if a dialog is visible, false
41 *     otherwise.
42 * @type {boolean}
43 */
44FileManagerDialogBase.shown = false;
45
46/**
47 * @param {string} title Title.
48 * @param {string} message Message.
49 * @param {function()} onOk Called when the OK button is pressed.
50 * @param {function()} onCancel Called when the cancel button is pressed.
51 * @return {boolean} True if the dialog can show successfully. False if the
52 *     dialog failed to show due to an existing dialog.
53 */
54FileManagerDialogBase.prototype.showOkCancelDialog = function(
55    title, message, onOk, onCancel) {
56  return this.showImpl_(title, message, onOk, onCancel);
57};
58
59/**
60 * @param {string} title Title.
61 * @param {string} message Message.
62 * @param {function()} onOk Called when the OK button is pressed.
63 * @param {function()} onCancel Called when the cancel button is pressed.
64 * @return {boolean} True if the dialog can show successfully. False if the
65 *     dialog failed to show due to an existing dialog.
66 * @private
67 */
68FileManagerDialogBase.prototype.showImpl_ = function(
69    title, message, onOk, onCancel) {
70  if (FileManagerDialogBase.shown)
71    return false;
72
73  FileManagerDialogBase.shown = true;
74  if (FileManagerDialogBase.fileManager_)
75    FileManagerDialogBase.fileManager_.onDialogShownOrHidden(true);
76  cr.ui.dialogs.BaseDialog.prototype.showWithTitle.call(
77      this, title, message, onOk, onCancel, null);
78
79  return true;
80};
81
82/**
83 * @return {boolean} True if the dialog can show successfully. False if the
84 *     dialog failed to show due to an existing dialog.
85 */
86FileManagerDialogBase.prototype.showBlankDialog = function() {
87  return this.showImpl_('', '', null, null, null);
88};
89
90/**
91 * @param {string} title Title.
92 * @return {boolean} True if the dialog can show successfully. False if the
93 *     dialog failed to show due to an existing dialog.
94 */
95FileManagerDialogBase.prototype.showTitleOnlyDialog = function(title) {
96  return this.showImpl_(title, '', null, null, null);
97};
98
99/**
100 * @param {string} title Title.
101 * @param {string} text Text to be shown in the dialog.
102 * @return {boolean} True if the dialog can show successfully. False if the
103 *     dialog failed to show due to an existing dialog.
104 */
105FileManagerDialogBase.prototype.showTitleAndTextDialog = function(title, text) {
106  return this.showImpl_(title, text, null, null, null);
107};
108
109/**
110 * @param {function()=} opt_onHide Called when the dialog is hidden.
111 */
112FileManagerDialogBase.prototype.hide = function(opt_onHide) {
113  cr.ui.dialogs.BaseDialog.prototype.hide.call(
114      this,
115      function() {
116        if (opt_onHide)
117          opt_onHide();
118        if (FileManagerDialogBase.fileManager_)
119          FileManagerDialogBase.fileManager_.onDialogShownOrHidden(false);
120        FileManagerDialogBase.shown = false;
121      });
122};
123