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