OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 cr.define('apps_dev_tool', function() { | |
6 /** | |
7 * Hides the present overlay showing. | |
8 */ | |
9 var hideOverlay = function() { | |
10 AppsDevTool.showOverlay(null); | |
11 }; | |
12 | |
13 /** | |
14 * PackItemOverlay class | |
15 * Encapsulated handling of the 'Pack Item' overlay page. | |
16 * @constructor | |
17 */ | |
18 function PackItemOverlay() {} | |
19 | |
20 cr.addSingletonGetter(PackItemOverlay); | |
21 | |
22 PackItemOverlay.prototype = { | |
23 initializePage: function() { | |
24 var overlay = $('overlay'); | |
25 cr.ui.overlay.setupOverlay(overlay); | |
26 overlay.addEventListener('cancelOverlay', hideOverlay.bind(this)); | |
27 | |
28 $('packItemDismiss').addEventListener('click', | |
29 hideOverlay.bind(this)); | |
30 $('packItemCommit').addEventListener('click', | |
31 this.handleCommit_.bind(this)); | |
32 $('browseItemDir').addEventListener('click', | |
33 this.handleBrowseItemDir_.bind(this)); | |
34 $('browsePrivateKey').addEventListener('click', | |
35 this.handleBrowsePrivateKey_.bind(this)); | |
36 }, | |
37 | |
38 /** | |
39 * Handles a click on the pack button. | |
40 * @param {Event} e The click event. | |
41 * @private | |
42 */ | |
43 handleCommit_: function(e) { | |
44 var itemPath = $('item-root-dir').value; | |
45 var privateKeyPath = $('item-private-key').value; | |
46 chrome.developerPrivate.packDirectory( | |
47 itemPath, privateKeyPath, 0, this.onCommit_); | |
48 }, | |
49 | |
50 /** | |
51 * Handles a commit on the pack request. | |
52 * @param {string} response Message returned by packing api. | |
53 * @private | |
54 */ | |
55 onCommit_: function(response) { | |
56 if (response.status == 'SUCCESS') | |
57 PackItemOverlay.showSuccessMessage(response); | |
58 else if (response.status == 'ERROR') | |
59 PackItemOverlay.showError(response); | |
60 else | |
61 PackItemOverlay.showWarningMessage(response); | |
62 }, | |
63 | |
64 /** | |
65 * Handles the showing of the item directory browser. | |
66 * @param {Event} e Change event. | |
67 * @private | |
68 */ | |
69 handleBrowseItemDir_: function(e) { | |
70 chrome.developerPrivate.choosePath('FOLDER', 'LOAD', function(filePath) { | |
71 $('item-root-dir').value = filePath; | |
72 }); | |
73 }, | |
74 | |
75 /** | |
76 * Handles the showing of the item private key file. | |
77 * @param {Event} e Change event. | |
78 * @private | |
79 */ | |
80 handleBrowsePrivateKey_: function(e) { | |
81 chrome.developerPrivate.choosePath('FILE', 'PEM', function(filePath) { | |
82 $('item-private-key').value = filePath; | |
83 }); | |
84 }, | |
85 }; | |
86 | |
87 /** | |
88 * Wrap up the pack process by showing the success |message| and closing | |
89 * the overlay. | |
90 * @param {string} message The message to show to the user. | |
91 */ | |
92 PackItemOverlay.showSuccessMessage = function(response) { | |
93 alertOverlay.setValues( | |
94 str('packExtensionOverlay'), | |
95 response.message, | |
96 str('ok'), | |
97 '', | |
98 hideOverlay, | |
99 null); | |
100 AppsDevTool.showOverlay($('alertOverlay')); | |
101 }; | |
102 | |
103 /** | |
104 * An alert overlay showing |message|, and upon acknowledgement, close | |
105 * the alert overlay and return to showing the PackItemOverlay. | |
106 * @param {string} message The message to show to the user. | |
107 */ | |
108 PackItemOverlay.showError = function(response) { | |
109 alertOverlay.setValues( | |
110 str('packExtensionErrorTitle'), | |
111 response.message /* message returned by the packiing api */, | |
112 str('ok'), | |
113 '', | |
114 function() { | |
115 AppsDevTool.showOverlay($('packItemOverlay')); | |
116 }, | |
117 null); | |
118 AppsDevTool.showOverlay($('alertOverlay')); | |
119 }; | |
120 | |
121 /** | |
122 * An alert overlay showing |message| as warning and proceeding after the | |
123 * user confirms the action. | |
Dan Beam
2013/02/14 21:10:40
@param {response}
Gaurav
2013/02/15 17:54:24
Done.
| |
124 */ | |
125 PackItemOverlay.showWarningMessage = function(response) { | |
126 alertOverlay.setValues( | |
127 str('packExtensionWarningTitle'), | |
128 response.message /* message returned by the packing api */, | |
129 str('packExtensionProceedAnyway'), | |
130 str('cancel'), | |
131 function() { | |
132 chrome.developerPrivate.packDirectory( | |
133 response.item_path, | |
134 response.pem_path, | |
135 response.override_flags, | |
136 PackItemOverlay.showSuccessMessage); | |
137 hideOverlay(); | |
138 }, | |
139 hideOverlay); | |
140 AppsDevTool.showOverlay($('alertOverlay')); | |
141 }; | |
142 | |
143 // Export | |
144 return { | |
145 PackItemOverlay: PackItemOverlay, | |
146 }; | |
147 }); | |
OLD | NEW |