This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
/
Sonatype.view.js
284 lines (253 loc) · 9.56 KB
/
Sonatype.view.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2007-2012 Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
/*global Ext, Sonatype, Nexus*/
Sonatype.view = {
FIELD_OFFSET_WITH_SCROLL : (3 + 16 + 3 + 30) * (-1) + '', // (help icon
// margin) + (help
// icon) + margin +
// (scrollbar)
FIELD_OFFSET : (3 + 16) * (-1) + '', // extra padding on right of icon not
// needed
FIELDSET_OFFSET : (3 + 18) * (-1) + '', // (extra room between border and
// scrollbar) + (scrollbar)
FIELDSET_OFFSET_WITH_SCROLL : (3 + 18 + 3 + 30) * (-1) + '', // (extra room
// between
// border and
// scrollbar) +
// (scrollbar) +
// margin +
// (scrollbar)
HISTORY_DELIMITER : ';',
headLinks : new Sonatype.headLinks(),
init : function() {
var dq = Ext.DomQuery;
Sonatype.Events.addListener('initHeadLinks', function() {
Sonatype.view.headLinks.updateLinks();
});
Sonatype.Events.fireEvent('initHeadLinks');
// Ext.get('login-link').on('click',
// Sonatype.repoServer.RepoServer.loginHandler,
// Sonatype.repoServer.RepoServer);
// this.updateLoginLinkText();
Ext.get('header').show();
Ext.get('welcome-tab').show();
Sonatype.view.welcomeTab = new Ext.Panel({
contentEl : 'welcome-tab',
title : 'Welcome',
id : 'welcome'
});
Sonatype.view.headerPanel = new Ext.Panel({
contentEl : 'header',
region : 'north',
margins : '0 0 0 0',
border : false,
autoHeight : true
});
Ext.Ajax.on({
"requestexception" : {
fn : function(conn, response, options) {
var suppressed = options.suppressStatus;
if (Sonatype.config.repos.urls.status === options.url)
{
// never show the connection error message for the status resource
// (if anonymous is disabled, UI would show this all the time, until you're logged in)
return;
} else if ( suppressed === true ) {
// 'true' means suppress all error handling
return;
}
if (suppressed === undefined) {
suppressed = [];
} else if (!Ext.isArray(suppressed)) {
suppressed = [suppressed];
}
// NEXUS-5228 some plugins use numbers in their options, some use strings (suppressStatus : '404')
// and rely on type conversion. That should be fixed because
// a) it was relying on broken js behavior (implicit conversion),
// b) it did not work at all when multiple status codes should be suppressed
// (['400', '404'] would still show error messages)
Ext.each(suppressed, function(item, idx, array) {
if (Ext.type(item) !== 'number') {
Nexus.Log.warn('The "suppressStatus" config option is not an instance of Number. Trying to convert.' );
array[idx] = parseInt(item, 10);
}
});
if (suppressed.indexOf(response.status) < 0)
{
Sonatype.utils.connectionError(response, null, null, options);
}
},
scope : this
}
});
var viewport = new Ext.Viewport({
layout : 'border',
items : [Sonatype.view.headerPanel, {
region : 'west',
title : 'Sonatype™ Servers',
collapsible : true,
// collapseMode: 'mini',
// border: false,
split : false,
width : 185,
minSize : 185,
maxSize : 185,
layout : 'fit',
margins : '0 5 5 5',
items : [{
xtype : 'tabpanel',
id : 'st-server-tab-panel',
border : false,
tabPosition : 'top',
layoutOnTabChange : true
// tabs added by servers
}]
}, new Sonatype.view.MainTabPanel({
id : 'st-main-tab-panel',
region : 'center',
margins : '0 5 5 0',
deferredRender : false,
resizeTabs : true,
enableTabScroll : true,
minTabWidth : 140,
autoScroll : false, // default
defaults : {
autoScroll : false,
closable : true
},
activeTab : 0,
layoutOnTabChange : true,
// border: false,
// bodyBorder: true,
items : [Sonatype.view.welcomeTab]
})]
});
// Export useful values to Sonatype.view namespace
Sonatype.view.viewport = viewport;
Sonatype.view.serverTabPanel = viewport.findById('st-server-tab-panel');
Sonatype.view.mainTabPanel = viewport.findById('st-main-tab-panel');
Sonatype.view.supportedNexusTabs = {};
var size = Sonatype.view.serverTabPanel.getSize();
Sonatype.view.serverTabPanel.setHeight(size.height - 20);
// allow each included sonatype server to setup its tab and events
var availSvrs = Sonatype.config.installedServers;
for (var srv in availSvrs)
{
if (availSvrs[srv] && typeof(Sonatype[srv]) != 'undefined')
{
Sonatype[srv][Sonatype.utils.capitalize(srv)].initServerTab();
}
}
Sonatype.view.serverTabPanel.setActiveTab('st-nexus-tab');
Ext.History.addListener('change', Sonatype.utils.onHistoryChange);
Sonatype.view.mainTabPanel.addListener('tabchange', function(panel, tab) {
Sonatype.utils.updateHistory(tab);
});
}
// updateLoginLinkText : function(){
// var loginEl = Ext.get('login-link');
// var usernameEl = Ext.get('username');
//
// if (Sonatype.user.curr.isLoggedIn){
// usernameEl.update(Sonatype.user.curr.username + ' | ').show();
// loginEl.update('Log Out');
// }
// else {
// loginEl.update('Log In');
// usernameEl.update('');
// }
// }
};
/**
* Very simple plugin for adding a close context menu to tabs.
*
* Copied from ExtJS 2.3 examples/tabs/TabCloseMenu.js
*
* @constructor
*/
Ext.ux.TabCloseMenu = function () {
var tabs, menu, ctxItem;
this.init = function (tp) {
tabs = tp;
tabs.on('contextmenu', onContextMenu);
}
function onContextMenu(ts, item, e) {
// create context menu on first right click
if (!menu) {
menu = new Ext.menu.Menu([
{
id: tabs.id + '-close',
text: 'Close Tab',
handler: function () {
tabs.remove(ctxItem);
}
},
{
id: tabs.id + '-close-others',
text: 'Close Other Tabs',
handler: function () {
tabs.items.each(function (item) {
if (item.closable && item != ctxItem) {
tabs.remove(item);
}
});
}
}
]);
}
ctxItem = item;
var items = menu.items;
items.get(tabs.id + '-close').setDisabled(!item.closable);
// Disable close others options if there are no tabs which can be closed
var disableCloseOthers = true;
tabs.items.each(function () {
if (this != item && this.closable) {
disableCloseOthers = false;
return false;
}
});
items.get(tabs.id + '-close-others').setDisabled(disableCloseOthers);
// If there is only one tab, then disable close (close others will also be disabled by ^^^)
// FIXME: This is partially faulty since all tabs are closeable but really should disable closable for the last tab
var disableClose = false;
if (tabs.items.length === 1) {
disableClose = true;
}
items.get(tabs.id + '-close').setDisabled(disableClose);
menu.showAt(e.getPoint());
}
};
Sonatype.view.MainTabPanel = Ext.extend(Ext.TabPanel, {
plugins: new Ext.ux.TabCloseMenu(),
addOrShowTab : function(id, panelClass, panelClassParams) {
var panelClassParams = panelClassParams || {};
var tab = this.getComponent(id);
if (tab)
{
this.setActiveTab(tab);
}
else
{
tab = new panelClass(Ext.apply({
id : id
}, panelClassParams));
this.add(tab);
}
this.setActiveTab(tab);
return tab;
}
});
Sonatype.Events.addListener('nexusNavigationInit', function(panel) {
Sonatype.view.viewport.doLayout();
});
Sonatype.utils.updateGlobalTimeout();