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 * The root of the file manager's view managing the DOM of Files.app.
10 * @param {HTMLElement} element Top level element of Files.app.
11 * @param {DialogType} dialogType Dialog type.
14 var FileManagerUI = function(element, dialogType) {
16 * Top level element of Files.app.
20 this.element_ = element;
27 this.dialogType_ = dialogType;
33 this.errorDialog = null;
37 * @type {cr.ui.dialogs.AlertDialog}
39 this.alertDialog = null;
43 * @type {cr.ui.dialogs.ConfirmDialog}
45 this.confirmDialog = null;
49 * @type {cr.ui.dialogs.PromptDialog}
51 this.promptDialog = null;
57 this.shareDialog = null;
60 * Default task picker.
61 * @type {DefaultActionDialog}
63 this.defaultTaskPicker = null;
66 * Suggest apps dialog.
67 * @type {SuggestAppsDialog}
69 this.suggestAppsDialog = null;
73 * @type {ConflictDialog}
75 this.conflictDialog = null;
81 this.searchBox = null;
84 * File type selector in the footer.
87 this.fileTypeSelector = null;
90 * OK button in the footer.
96 * Cancel button in the footer.
99 this.cancelButton = null;
103 // Initialize the header.
104 this.element_.querySelector('#app-name').innerText =
105 chrome.runtime.getManifest().name;
107 // Initialize dialog type.
108 this.initDialogType_();
110 // Pre-populate the static localized strings.
111 i18nTemplate.process(this.element_.ownerDocument, loadTimeData);
115 * Tweak the UI to become a particular kind of dialog, as determined by the
116 * dialog type parameter passed to the constructor.
120 FileManagerUI.prototype.initDialogType_ = function() {
123 this.dialogType_ == DialogType.SELECT_SAVEAS_FILE ||
124 this.dialogType_ == DialogType.SELECT_FOLDER;
126 // If the footer panel exists, the buttons are placed there. Otherwise,
127 // the buttons are on the preview panel.
128 var parentPanelOfButtons = this.element_.ownerDocument.querySelector(
129 !hasFooterPanel ? '.preview-panel' : '.dialog-footer');
130 parentPanelOfButtons.classList.add('button-panel');
131 this.fileTypeSelector = parentPanelOfButtons.querySelector('.file-type');
132 this.okButton = parentPanelOfButtons.querySelector('.ok');
133 this.cancelButton = parentPanelOfButtons.querySelector('.cancel');
137 var okLabel = str('OPEN_LABEL');
139 switch (this.dialogType_) {
140 case DialogType.SELECT_FOLDER:
141 defaultTitle = str('SELECT_FOLDER_TITLE');
144 case DialogType.SELECT_UPLOAD_FOLDER:
145 defaultTitle = str('SELECT_UPLOAD_FOLDER_TITLE');
146 okLabel = str('UPLOAD_LABEL');
149 case DialogType.SELECT_OPEN_FILE:
150 defaultTitle = str('SELECT_OPEN_FILE_TITLE');
153 case DialogType.SELECT_OPEN_MULTI_FILE:
154 defaultTitle = str('SELECT_OPEN_MULTI_FILE_TITLE');
157 case DialogType.SELECT_SAVEAS_FILE:
158 defaultTitle = str('SELECT_SAVEAS_FILE_TITLE');
159 okLabel = str('SAVE_LABEL');
162 case DialogType.FULL_PAGE:
166 throw new Error('Unknown dialog type: ' + this.dialogType);
169 this.okButton.textContent = okLabel;
170 this.element_.setAttribute('type', this.dialogType_);
174 * Initialize the dialogs.
176 FileManagerUI.prototype.initDialogs = function() {
177 // Initialize the dialog label.
178 var dialogs = cr.ui.dialogs;
179 dialogs.BaseDialog.OK_LABEL = str('OK_LABEL');
180 dialogs.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL');
181 var appState = window.appState || {};
183 // Create the dialog instances.
184 this.errorDialog = new ErrorDialog(this.element_);
185 this.alertDialog = new dialogs.AlertDialog(this.element_);
186 this.confirmDialog = new dialogs.ConfirmDialog(this.element_);
187 this.promptDialog = new dialogs.PromptDialog(this.element_);
188 this.shareDialog = new ShareDialog(this.element_);
189 this.defaultTaskPicker =
190 new cr.filebrowser.DefaultActionDialog(this.element_);
191 this.suggestAppsDialog = new SuggestAppsDialog(
192 this.element_, appState.suggestAppsDialogState || {});
193 this.conflictDialog = new ConflictDialog(this.element_);
197 * Initialize here elements, which are expensive
198 * or hidden in the beginning.
200 FileManagerUI.prototype.initAdditionalUI = function() {
201 this.searchBox = new SearchBox(this.element_.querySelector('#search-box'));