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.updateProfileBadge();
105 this.element_.querySelector('#app-name').innerText =
106 chrome.runtime.getManifest().name;
108 // Initialize dialog type.
109 this.initDialogType_();
111 // Pre-populate the static localized strings.
112 i18nTemplate.process(this.element_.ownerDocument, loadTimeData);
116 * Tweak the UI to become a particular kind of dialog, as determined by the
117 * dialog type parameter passed to the constructor.
121 FileManagerUI.prototype.initDialogType_ = function() {
124 this.dialogType_ == DialogType.SELECT_SAVEAS_FILE ||
125 DialogType.isFolderDialog(this.dialogType_);
127 // If the footer panel exists, the buttons are placed there. Otherwise,
128 // the buttons are on the preview panel.
129 var parentPanelOfButtons = this.element_.ownerDocument.querySelector(
130 !hasFooterPanel ? '.preview-panel' : '.dialog-footer');
131 parentPanelOfButtons.classList.add('button-panel');
132 this.fileTypeSelector = parentPanelOfButtons.querySelector('.file-type');
133 this.okButton = parentPanelOfButtons.querySelector('.ok');
134 this.cancelButton = parentPanelOfButtons.querySelector('.cancel');
137 var okLabel = str('OPEN_LABEL');
139 switch (this.dialogType_) {
140 case DialogType.SELECT_UPLOAD_FOLDER:
141 okLabel = str('UPLOAD_LABEL');
144 case DialogType.SELECT_SAVEAS_FILE:
145 okLabel = str('SAVE_LABEL');
148 case DialogType.SELECT_FOLDER:
149 case DialogType.SELECT_OPEN_FILE:
150 case DialogType.SELECT_OPEN_MULTI_FILE:
151 case DialogType.FULL_PAGE:
155 throw new Error('Unknown dialog type: ' + this.dialogType);
158 this.okButton.textContent = okLabel;
159 this.element_.setAttribute('type', this.dialogType_);
163 * Initialize the dialogs.
165 FileManagerUI.prototype.initDialogs = function() {
166 // Initialize the dialog label.
167 var dialogs = cr.ui.dialogs;
168 dialogs.BaseDialog.OK_LABEL = str('OK_LABEL');
169 dialogs.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL');
170 var appState = window.appState || {};
172 // Create the dialog instances.
173 this.errorDialog = new ErrorDialog(this.element_);
174 this.alertDialog = new dialogs.AlertDialog(this.element_);
175 this.confirmDialog = new dialogs.ConfirmDialog(this.element_);
176 this.promptDialog = new dialogs.PromptDialog(this.element_);
177 this.shareDialog = new ShareDialog(this.element_);
178 this.defaultTaskPicker =
179 new cr.filebrowser.DefaultActionDialog(this.element_);
180 this.suggestAppsDialog = new SuggestAppsDialog(
181 this.element_, appState.suggestAppsDialogState || {});
182 this.conflictDialog = new ConflictDialog(this.element_);
186 * Initialize here elements, which are expensive
187 * or hidden in the beginning.
189 FileManagerUI.prototype.initAdditionalUI = function() {
190 this.searchBox = new SearchBox(this.element_.querySelector('#search-box'));
194 * Updates visibility and image of the profile badge.
196 FileManagerUI.prototype.updateProfileBadge = function() {
197 if (this.dialogType_ !== DialogType.FULL_PAGE)
200 chrome.fileBrowserPrivate.getProfiles(function(profiles,
204 if (currentId !== displayedId) {
205 for (var i = 0; i < profiles.length; i++) {
206 if (profiles[i].profileId === currentId) {
207 imageUri = profiles[i].imageUri;
212 var profileBadge = this.element_.querySelector('#profile-badge');
214 profileBadge.setAttribute('src', imageUri);
216 profileBadge.removeAttribute('src');