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 * Dialog to confirm the share between profiles. 9 * 10 * @param {HTMLElement} parentNode Node to be parent for this dialog. 11 * @constructor 12 * @extends {FileManagerDialogBase} 13 */ 14function MultiProfileShareDialog(parentNode) { 15 FileManagerDialogBase.call(this, parentNode); 16 17 this.mailLabel_ = parentNode.ownerDocument.createElement('label'); 18 this.mailLabel_.className = 'mail-label'; 19 20 var canEdit = parentNode.ownerDocument.createElement('option'); 21 canEdit.textContent = str('DRIVE_SHARE_TYPE_CAN_EDIT'); 22 canEdit.value = MultiProfileShareDialog.Result.CAN_EDIT; 23 24 var canComment = parentNode.ownerDocument.createElement('option'); 25 canComment.textContent = str('DRIVE_SHARE_TYPE_CAN_COMMENT'); 26 canComment.value = MultiProfileShareDialog.Result.CAN_COMMET; 27 28 var canView = parentNode.ownerDocument.createElement('option'); 29 canView.textContent = str('DRIVE_SHARE_TYPE_CAN_VIEW'); 30 canView.value = MultiProfileShareDialog.Result.CAN_VIEW; 31 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); 37 38 var shareLine = parentNode.ownerDocument.createElement('div'); 39 shareLine.className = 'share-line'; 40 shareLine.appendChild(this.mailLabel_); 41 shareLine.appendChild(this.shareTypeSelect_); 42 43 this.frame_.insertBefore(shareLine, this.buttons); 44 this.frame_.id = 'multi-profile-share-dialog'; 45 46 this.currentProfileId_ = new Promise(function(callback) { 47 chrome.fileManagerPrivate.getProfiles( 48 function(profiles, currentId, displayedId) { 49 callback(currentId); 50 }); 51 }); 52} 53 54/** 55 * Result of the dialog box. 56 * @enum {string} 57 * @const 58 */ 59MultiProfileShareDialog.Result = Object.freeze({ 60 CAN_EDIT: 'can_edit', 61 CAN_COMMET: 'can_comment', 62 CAN_VIEW: 'can_view', 63 CANCEL: 'cancel' 64}); 65 66MultiProfileShareDialog.prototype = { 67 __proto__: FileManagerDialogBase.prototype 68}; 69 70/** 71 * Shows the dialog. 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. 75 */ 76MultiProfileShareDialog.prototype.show = function(plural) { 77 return this.currentProfileId_.then(function(currentProfileId) { 78 return new Promise(function(fulfill, reject) { 79 this.shareTypeSelect_.selectedIndex = 0; 80 this.mailLabel_.textContent = currentProfileId; 81 var result = FileManagerDialogBase.prototype.showOkCancelDialog.call( 82 this, 83 str(plural ? 84 'MULTI_PROFILE_SHARE_DIALOG_TITLE_PLURAL' : 85 'MULTI_PROFILE_SHARE_DIALOG_TITLE'), 86 str(plural ? 87 'MULTI_PROFILE_SHARE_DIALOG_MESSAGE_PLURAL' : 88 'MULTI_PROFILE_SHARE_DIALOG_MESSAGE'), 89 function() { 90 fulfill(this.shareTypeSelect_.value); 91 }.bind(this), 92 function() { 93 fulfill(MultiProfileShareDialog.Result.CANCEL); 94 }); 95 if (!result) 96 reject(new Error('Another dialog has already shown.')); 97 }.bind(this)); 98 }.bind(this)); 99}; 100