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('extensions', function() { | |
6 /** | |
7 * PackItemOverlay class | |
8 * Encapsulated handling of the 'Pack Item' overlay page. | |
9 * @constructor | |
10 */ | |
11 function PackItemOverlay() { | |
Dan Beam
2013/02/07 01:54:44
nit: don't think you need this \n
Gaurav
2013/02/08 04:39:19
Done.
| |
12 } | |
13 | |
14 cr.addSingletonGetter(PackItemOverlay); | |
15 | |
16 PackItemOverlay.prototype = { | |
17 /** | |
18 * Initialize the page. | |
19 */ | |
20 initializePage: function() { | |
21 var overlay = $('overlay'); | |
22 cr.ui.overlay.setupOverlay(overlay); | |
23 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this)); | |
24 | |
25 $('packItemDismiss').addEventListener('click', | |
26 this.handleDismiss_.bind(this)); | |
27 $('packItemCommit').addEventListener('click', | |
28 this.handleCommit_.bind(this)); | |
29 $('browseItemDir').addEventListener('click', | |
30 this.handleBrowseItemDir_.bind(this)); | |
31 $('browsePrivateKey').addEventListener('click', | |
32 this.handleBrowsePrivateKey_.bind(this)); | |
33 }, | |
34 | |
35 /** | |
36 * Handles a click on the dismiss button. | |
37 * @param {Event} e The click event. | |
Dan Beam
2013/02/07 01:54:44
@private
Gaurav
2013/02/08 04:39:19
Done.
| |
38 */ | |
39 handleDismiss_: function(e) { | |
40 AppsDebugger.showOverlay(null); | |
41 }, | |
42 | |
43 /** | |
44 * Handles a click on the pack button. | |
45 * @param {Event} e The click event. | |
Dan Beam
2013/02/07 01:54:44
@private
Gaurav
2013/02/08 04:39:19
Done.
| |
46 */ | |
47 handleCommit_: function(e) { | |
48 var itemPath = $('itemRootDir').value; | |
49 var privateKeyPath = $('itemPrivateKey').value; | |
50 chrome.developerPrivate.packDirectory( | |
51 itemPath, privateKeyPath, 0, this.onCommit_); | |
52 }, | |
53 | |
Dan Beam
2013/02/07 01:54:44
nit: jsdoc
Gaurav
2013/02/08 04:39:19
Done.
Gaurav
2013/02/08 04:39:19
Done.
| |
54 onCommit_: function(response) { | |
55 if (response.status == 'SUCCESS') | |
56 PackItemOverlay.showSuccessMessage(response); | |
57 else if (response.status == 'ERROR') | |
58 PackItemOverlay.showError(response); | |
59 else | |
60 PackItemOverlay.showWarningMessage(response); | |
61 }, | |
62 | |
63 /** | |
64 * Handles the showing of the item directory browser. | |
65 * @param {Event} e Change event. | |
66 * @private | |
67 */ | |
68 handleBrowseItemDir_: function(e) { | |
69 chrome.developerPrivate.choosePath('FOLDER', 'LOAD', function(filePath) { | |
70 $('itemRootDir').value = filePath; | |
71 }); | |
72 }, | |
73 | |
74 /** | |
75 * Handles the showing of the item private key file. | |
76 * @param {Event} e Change event. | |
77 * @private | |
78 */ | |
79 handleBrowsePrivateKey_: function(e) { | |
80 chrome.developerPrivate.choosePath('FILE', 'PEM', function(filePath) { | |
81 $('itemPrivateKey').value = filePath; | |
82 }); | |
83 }, | |
84 }; | |
85 | |
86 /** | |
87 * Wrap up the pack process by showing the success |message| and closing | |
88 * the overlay. | |
89 * @param {String} message The message to show to the user. | |
Dan Beam
2013/02/07 01:54:44
nit: @param {string}
Gaurav
2013/02/08 04:39:19
Done.
| |
90 */ | |
91 PackItemOverlay.showSuccessMessage = function(response) { | |
92 alertOverlay.setValues( | |
Dan Beam
2013/02/07 01:54:44
nit: this is a little scary looking, can you do on
Gaurav
2013/02/08 04:39:19
Done.
| |
93 str('packExtensionOverlay'), | |
94 response.message, | |
95 str('ok'), | |
96 '', | |
97 function() { | |
98 AppsDebugger.showOverlay(null); | |
99 }, | |
100 null); | |
101 AppsDebugger.showOverlay($('alertOverlay')); | |
102 }; | |
103 | |
104 /** | |
105 * An alert overlay showing |message|, and upon acknowledgement, close | |
106 * the alert overlay and return to showing the PackItemOverlay. | |
Dan Beam
2013/02/07 01:54:44
nit: missing @param
Gaurav
2013/02/08 04:39:19
Done.
| |
107 */ | |
108 PackItemOverlay.showError = function(response) { | |
109 alertOverlay.setValues( | |
110 str('packExtensionErrorTitle'), | |
111 response.message, | |
112 str('ok'), | |
113 '', | |
114 function() { | |
115 AppsDebugger.showOverlay($('packItemOverlay')); | |
116 }, | |
117 null); | |
118 AppsDebugger.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/07 01:54:44
nit: missing @param
| |
124 */ | |
125 PackItemOverlay.showWarningMessage = function(response) { | |
126 var closeAlert = function() { | |
127 AppsDebugger.showOverlay(null); | |
Dan Beam
2013/02/07 01:54:44
nit: can you make a central function and re-use it
Gaurav
2013/02/08 04:39:19
Done.
| |
128 }; | |
129 | |
130 alertOverlay.setValues( | |
131 str('packExtensionWarningTitle'), | |
132 response.message, | |
133 str('packExtensionProceedAnyway'), | |
134 str('cancel'), | |
135 function() { | |
136 chrome.developerPrivate.packDirectory( | |
137 response.item_path, | |
138 response.pem_path, | |
139 response.override_flags, | |
140 PackItemOverlay.showSuccessMessage); | |
141 closeAlert(); | |
142 }, | |
143 closeAlert()); | |
144 AppsDebugger.showOverlay($('alertOverlay')); | |
145 }; | |
146 | |
147 // Export | |
148 return { | |
149 PackItemOverlay: PackItemOverlay | |
Dan Beam
2013/02/07 01:54:44
opt nit: I prefer , at the end
Gaurav
2013/02/08 04:39:19
Done.
| |
150 }; | |
151 }); | |
OLD | NEW |