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