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.
5 cr.define('apps_dev_tool', function() {
8 /** const*/ var AppsDevTool = apps_dev_tool.AppsDevTool;
11 * Hides the present overlay showing.
13 var hideOverlay = function() {
14 AppsDevTool.showOverlay(null);
18 * PackItemOverlay class
19 * Encapsulated handling of the 'Pack Item' overlay page.
22 function PackItemOverlay() {}
24 cr.addSingletonGetter(PackItemOverlay);
26 PackItemOverlay.prototype = {
27 initializePage: function() {
28 var overlay = $('overlay');
29 cr.ui.overlay.setupOverlay(overlay);
30 cr.ui.overlay.globalInitialization();
31 overlay.addEventListener('cancelOverlay', hideOverlay.bind(this));
33 $('pack-item-dismiss').addEventListener('click',
34 hideOverlay.bind(this));
35 $('pack-item-commit').addEventListener('click',
36 this.handleCommit_.bind(this));
37 $('browse-private-key').addEventListener('click',
38 this.handleBrowsePrivateKey_.bind(this));
42 * Handles a click on the pack button.
43 * @param {Event} e The click event.
46 handleCommit_: function(e) {
47 var itemPath = $('item-root-dir').value;
48 var privateKeyPath = $('item-private-key').value;
49 chrome.developerPrivate.packDirectory(
50 itemPath, privateKeyPath, 0, this.onCommit_);
54 * Handles a commit on the pack request.
55 * @param {string} response Message returned by packing api.
58 onCommit_: function(response) {
59 if (response.status == 'SUCCESS')
60 PackItemOverlay.showSuccessMessage(response);
61 else if (response.status == 'ERROR')
62 PackItemOverlay.showError(response);
64 PackItemOverlay.showWarningMessage(response);
68 * Handles the showing of the item private key file.
69 * @param {Event} e Change event.
72 handleBrowsePrivateKey_: function(e) {
73 chrome.developerPrivate.choosePath('FILE', 'PEM', function(filePath) {
74 $('item-private-key').value = filePath;
80 * Wrap up the pack process by showing the success |message| and closing
82 * @param {string} message The message to show to the user.
84 PackItemOverlay.showSuccessMessage = function(response) {
85 alertOverlay.setValues(
86 loadTimeData.getString('packExtensionOverlay'),
88 loadTimeData.getString('ok'),
92 AppsDevTool.showOverlay($('alertOverlay'));
96 * An alert overlay showing |message|, and upon acknowledgement, close
97 * the alert overlay and return to showing the PackItemOverlay.
98 * @param {string} message The message to show to the user.
100 PackItemOverlay.showError = function(response) {
101 alertOverlay.setValues(
102 loadTimeData.getString('packExtensionErrorTitle'),
103 response.message /* message returned by the packiing api */,
104 loadTimeData.getString('ok'),
107 AppsDevTool.showOverlay($('packItemOverlay'));
110 AppsDevTool.showOverlay($('alertOverlay'));
114 * An alert overlay showing |message| as warning and proceeding after the
115 * user confirms the action.
116 * @param {response} response returned by the packItem API.
118 PackItemOverlay.showWarningMessage = function(response) {
119 alertOverlay.setValues(
120 loadTimeData.getString('packExtensionWarningTitle'),
121 response.message /* message returned by the packing api */,
122 loadTimeData.getString('packExtensionProceedAnyway'),
123 loadTimeData.getString('cancel'),
125 chrome.developerPrivate.packDirectory(
128 response.override_flags,
129 PackItemOverlay.showSuccessMessage);
133 AppsDevTool.showOverlay($('alertOverlay'));
138 PackItemOverlay: PackItemOverlay,