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 share between profiles.
10 * @param {HTMLElement} parentNode Node to be parent for this dialog.
12 * @extends {FileManagerDialogBase}
14 function MultiProfileShareDialog(parentNode) {
15 FileManagerDialogBase.call(this, parentNode);
17 this.mailLabel_ = parentNode.ownerDocument.createElement('label');
18 this.mailLabel_.className = 'mail-label';
20 var canEdit = parentNode.ownerDocument.createElement('option');
21 canEdit.textContent = str('DRIVE_SHARE_TYPE_CAN_EDIT');
22 canEdit.value = MultiProfileShareDialog.Result.CAN_EDIT;
24 var canComment = parentNode.ownerDocument.createElement('option');
25 canComment.textContent = str('DRIVE_SHARE_TYPE_CAN_COMMENT');
26 canComment.value = MultiProfileShareDialog.Result.CAN_COMMET;
28 var canView = parentNode.ownerDocument.createElement('option');
29 canView.textContent = str('DRIVE_SHARE_TYPE_CAN_VIEW');
30 canView.value = MultiProfileShareDialog.Result.CAN_VIEW;
32 this.shareTypeSelect_ = parentNode.ownerDocument.createElement('select');
33 this.shareTypeSelect_.setAttribute('size', 1);
34 this.shareTypeSelect_.appendChild(canEdit);
35 this.shareTypeSelect_.appendChild(canComment);
36 this.shareTypeSelect_.appendChild(canView);
38 var shareLine = parentNode.ownerDocument.createElement('div');
39 shareLine.className = 'share-line';
40 shareLine.appendChild(this.mailLabel_);
41 shareLine.appendChild(this.shareTypeSelect_);
43 this.frame_.insertBefore(shareLine, this.buttons);
44 this.frame_.id = 'multi-profile-share-dialog';
46 this.currentProfileId_ = new Promise(function(callback) {
47 chrome.fileBrowserPrivate.getProfiles(
48 function(profiles, currentId, displayedId) {
55 * Result of the dialog box.
59 MultiProfileShareDialog.Result = Object.freeze({
61 CAN_COMMET: 'can_comment',
66 MultiProfileShareDialog.prototype = {
67 __proto__: FileManagerDialogBase.prototype
72 * @param {boolean} plural Whether to use message of plural or not.
73 * @return {Promise} Promise fulfilled with the result of dialog. If the dialog
74 * is already opened, it returns null.
76 MultiProfileShareDialog.prototype.show = function(plural) {
77 return this.currentProfileId_.
78 then(function(currentProfileId) {
79 return new Promise(function(fulfill, reject) {
80 this.shareTypeSelect_.selectedIndex = 0;
81 this.mailLabel_.textContent = currentProfileId;
82 var result = FileManagerDialogBase.prototype.showOkCancelDialog.call(
85 'MULTI_PROFILE_SHARE_DIALOG_TITLE_PLURAL' :
86 'MULTI_PROFILE_SHARE_DIALOG_TITLE'),
88 'MULTI_PROFILE_SHARE_DIALOG_MESSAGE_PLURAL' :
89 'MULTI_PROFILE_SHARE_DIALOG_MESSAGE'),
91 fulfill(this.shareTypeSelect_.value);
94 fulfill(MultiProfileShareDialog.Result.CANCEL);
97 reject(new Error('Another dialog has already shown.'));