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.
6 * Dialog to confirm the share between profiles.
8 * @param {HTMLElement} parentNode Node to be parent for this dialog.
10 * @extends {FileManagerDialogBase}
12 function MultiProfileShareDialog(parentNode) {
13 FileManagerDialogBase.call(this, parentNode);
15 this.mailLabel_ = parentNode.ownerDocument.createElement('label');
16 this.mailLabel_.className = 'mail-label';
18 var canEdit = parentNode.ownerDocument.createElement('option');
19 canEdit.textContent = str('DRIVE_SHARE_TYPE_CAN_EDIT');
20 canEdit.value = MultiProfileShareDialog.Result.CAN_EDIT;
22 var canComment = parentNode.ownerDocument.createElement('option');
23 canComment.textContent = str('DRIVE_SHARE_TYPE_CAN_COMMENT');
24 canComment.value = MultiProfileShareDialog.Result.CAN_COMMET;
26 var canView = parentNode.ownerDocument.createElement('option');
27 canView.textContent = str('DRIVE_SHARE_TYPE_CAN_VIEW');
28 canView.value = MultiProfileShareDialog.Result.CAN_VIEW;
30 this.shareTypeSelect_ = parentNode.ownerDocument.createElement('select');
31 this.shareTypeSelect_.setAttribute('size', 1);
32 this.shareTypeSelect_.appendChild(canEdit);
33 this.shareTypeSelect_.appendChild(canComment);
34 this.shareTypeSelect_.appendChild(canView);
36 var shareLine = parentNode.ownerDocument.createElement('div');
37 shareLine.className = 'share-line';
38 shareLine.appendChild(this.mailLabel_);
39 shareLine.appendChild(this.shareTypeSelect_);
41 this.frame_.insertBefore(shareLine, this.buttons);
42 this.frame_.id = 'multi-profile-share-dialog';
44 this.currentProfileId_ = new Promise(function(callback) {
45 chrome.fileManagerPrivate.getProfiles(
46 function(profiles, currentId, displayedId) {
53 * Result of the dialog box.
57 MultiProfileShareDialog.Result = {
59 CAN_COMMET: 'can_comment',
63 Object.freeze(MultiProfileShareDialog.Result);
65 MultiProfileShareDialog.prototype = {
66 __proto__: FileManagerDialogBase.prototype
71 * @param {boolean} plural Whether to use message of plural or not.
72 * @return {Promise} Promise fulfilled with the result of dialog. If the dialog
73 * is already opened, it returns null.
75 MultiProfileShareDialog.prototype.show = function(plural) {
76 return this.currentProfileId_.then(function(currentProfileId) {
77 return new Promise(function(fulfill, reject) {
78 this.shareTypeSelect_.selectedIndex = 0;
79 this.mailLabel_.textContent = currentProfileId;
80 var result = FileManagerDialogBase.prototype.showOkCancelDialog.call(
83 'MULTI_PROFILE_SHARE_DIALOG_TITLE_PLURAL' :
84 'MULTI_PROFILE_SHARE_DIALOG_TITLE'),
86 'MULTI_PROFILE_SHARE_DIALOG_MESSAGE_PLURAL' :
87 'MULTI_PROFILE_SHARE_DIALOG_MESSAGE'),
89 fulfill(this.shareTypeSelect_.value);
92 fulfill(MultiProfileShareDialog.Result.CANCEL);
95 reject(new Error('Another dialog has already shown.'));