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