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