Permalink
Browse files

JS cleanup

  • Loading branch information...
nabcos authored and cstamas committed Nov 16, 2012
1 parent 23a1381 commit 175a0aee4593e9059bd6bfc2b1147dde3bc596dc
@@ -11,67 +11,67 @@
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
/*global define*/
-define('nexus/log',['extjs', 'nexus', 'nexus/config'], function(Ext, Nexus, Sonatype){
-/**
- * Nexus logging utility.
- *
- * @static
- */
-Nexus.Log = (function() {
- var log = Ext.emptyFn;
+define('nexus/log', ['extjs', 'nexus', 'nexus/config'], function(Ext, Nexus, Sonatype) {
+ /**
+ * Nexus logging utility.
+ *
+ * @static
+ */
+ Nexus.Log = (function() {
+ var log = Ext.emptyFn;
- try {
- if ( typeof(console) === "object" && console.log !== undefined ) {
- log = function(level, msg) {
- console.log(level + ' ' + msg);
- };
+ try {
+ if (typeof(console) === "object" && console.log !== undefined) {
+ log = function(level, msg) {
+ console.log(level + ' ' + msg);
+ };
+ }
+ }
+ catch (e) {
+ // ignore, nothing left to do
}
- } catch (e) {
- // ignore, nothing left to do
- }
- return {
- /**
- * @static
- * @param msg {String} The message to log.
- */
- debug : function(msg) {
- // Sonatype.config may be undefined if Nexus.log is called on setup of ext js extensions
- // it should always be there on runtime for UI components, but better safe than sorry
- if ( Sonatype.config && Sonatype.config.isDebug )
- {
- log('DEBUG', msg);
+ return {
+ /**
+ * @static
+ * @param msg {String} The message to log.
+ */
+ debug : function(msg) {
+ // Sonatype.config may be undefined if Nexus.log is called on setup of ext js extensions
+ // it should always be there on runtime for UI components, but better safe than sorry
+ if (Sonatype.config && Sonatype.config.isDebug) {
+ log('DEBUG', msg);
+ }
+ },
+ /**
+ * @static
+ * @param msg {String} The message to log.
+ */
+ info : function(msg) {
+ log('INFO', msg);
+ },
+ /**
+ * @static
+ * @param msg {String} The message to log.
+ */
+ warn : function(msg) {
+ log('WARN', msg);
+ },
+ /**
+ * @static
+ * @param msg {String} The message to log.
+ */
+ error : function(msg) {
+ log('ERROR', msg);
}
- },
- /**
- * @static
- * @param msg {String} The message to log.
- */
- info : function(msg) {
- log('INFO', msg);
- },
- /**
- * @static
- * @param msg {String} The message to log.
- */
- warn : function(msg) {
- log('WARN', msg);
- },
- /**
- * @static
- * @param msg {String} The message to log.
- */
- error : function(msg) {
- log('ERROR', msg);
- }
- };
-}());
+ };
+ }());
-/**
- * @static
- * @see Nexus.Log.debug
- */
-Nexus.log = Nexus.Log.debug;
+ /**
+ * @static
+ * @see Nexus.Log.debug
+ */
+ Nexus.log = Nexus.Log.debug;
- return Nexus;
+ return Nexus.Log;
});
@@ -133,5 +133,5 @@ Ext.extend(Sonatype.panels.AutoTabPanel, Ext.Panel, {
}
});
-
+ return Sonatype.panels.AutoTabPanel;
});
@@ -10,66 +10,27 @@
* 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.
*/
-/*
- * Repository panel superclass
- */
-define('repoServer/AbstractRepoPanel',['sonatype/all'], function(){
+
+/*global define*/
+define('nexus/repository/AbstractRepoPanel',['extjs', 'sonatype/all', 'nexus', 'nexus/repository/action'], function(Ext, Sonatype, Nexus, Action){
/*
+ * Repository panel superclass
+ *
* config options: { id: the is of this panel instance [required] title: title
* of this panel (shows in tab) }
*/
-
-/*global Ext, Sonatype, Nexus*/
Sonatype.repoServer.AbstractRepoPanel = function(cfg) {
var
config = cfg || {},
defaultConfig = {},
- sp = Sonatype.lib.Permissions,
- Action;
+ sp = Sonatype.lib.Permissions;
Ext.apply(this, config, defaultConfig);
this.ctxRecord = null;
this.reposGridPanel = null;
- Action = function(cfg) {
- var
- _action = this,
- conditions = [];
-
- if ( cfg.condition )
- {
- conditions.push(cfg.condition);
- }
-
- this.maybeAddToMenu = function(menu, repo, content) {
- if ( _action.isApplicable(repo, content) ) {
- menu.add(cfg.action);
- }
- };
-
- this.addCondition = function(condition) {
- if ( typeof(condition) === 'function' ) {
- conditions.push(condition);
- } else {
- Nexus.log('Tried to add non-function condition, ignoring');
- }
- };
-
- this.isApplicable = function(repo, content) {
- var i, condition;
- for( i = 0; i < conditions.length; i = i+1 )
- {
- condition = conditions[i];
- if ( !condition(repo, content) ) {
- return false;
- }
- }
- return true;
- };
- };
-
this.repoActions = {
downloadRemoteItem : new Action({
condition : function(repo, content) {
@@ -189,13 +150,15 @@ Ext.extend(Sonatype.repoServer.AbstractRepoPanel, Ext.Panel, {
return this.ctxRecord || this.reposGridPanel.getSelectionModel().hasSelection();
},
+ /*
viewHandler : function() {
if (this.ctxRecord || this.reposGridPanel.getSelectionModel().hasSelection())
{
- var rec = (this.ctxRecord) ? this.ctxRecord : this.reposGridPanel.getSelectionModel().getSelected();
+ var rec = this.ctxRecord || this.reposGridPanel.getSelectionModel().getSelected();
this.viewRepo(rec);
}
},
+ */
repoActionAjaxSuccessHandler : function(response, options) {
var statusResp = Ext.decode(response.responseText);
@@ -310,7 +273,7 @@ Ext.extend(Sonatype.repoServer.AbstractRepoPanel, Ext.Panel, {
}
var
- remoteStatus = ('' + status.remoteStatus).toLowerCase(),
+ remoteStatus = (String(status.remoteStatus)).toLowerCase(),
sOut = (status.localStatus === 'IN_SERVICE') ? 'In Service' : 'Out of Service';
if (parent.repoType === 'proxy')
@@ -341,6 +304,7 @@ Ext.extend(Sonatype.repoServer.AbstractRepoPanel, Ext.Panel, {
},
updateRepoStatuses : function(status, rec) {
+ var i, status2, rec2;
rec.beginEdit();
rec.data.status = status;
rec.set('displayStatus', this.statusConverter(status, rec.data));
@@ -349,10 +313,10 @@ Ext.extend(Sonatype.repoServer.AbstractRepoPanel, Ext.Panel, {
if (status.dependentRepos)
{
- for (var i = 0; i < status.dependentRepos.length; i++)
+ for (i = 0; i < status.dependentRepos.length; i+=1)
{
- var status2 = status.dependentRepos[i];
- var rec2 = rec.store.getById(Sonatype.config.host + Sonatype.config.repos.urls.repositories + '/' + status2.id);
+ status2 = status.dependentRepos[i];
+ rec2 = rec.store.getById(Sonatype.config.host + Sonatype.config.repos.urls.repositories + '/' + status2.id);
if (rec2)
{
rec2.beginEdit();
@@ -448,10 +412,7 @@ Ext.extend(Sonatype.repoServer.AbstractRepoPanel, Ext.Panel, {
repo = repoRecord.data,
actions = this.repoActions;
- if (contentRecord.data.resourceURI == null)
- {
- contentRecord.data.resourceURI = contentRecord.data.id;
- }
+ contentRecord.data.resourceURI = contentRecord.data.resourceURI || contentRecord.data.id;
actions.clearCache.maybeAddToMenu(menu, repo, contentRecord);
actions.rebuildMetadata.maybeAddToMenu(menu, repo, contentRecord);
@@ -0,0 +1,94 @@
+/*
+ * 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 define*/
+
+define('nexus/repository/ArtifactContainer', ['extjs', 'sonatype/all', 'nexus/panels/AutoTabPanel'],
+ function(Ext, Sonatype, AutoTabPanel) {
+
+ Sonatype.repoServer.ArtifactContainer = function(cfg) {
+ Ext.apply(this, cfg || {}, {
+ initEventName : 'artifactContainerInit',
+ updateEventName : 'artifactContainerUpdate'
+ });
+
+ Sonatype.repoServer.ArtifactContainer.superclass.constructor.call(this, {
+ layoutOnTabChange : true
+ });
+
+ var items = [], i;
+
+ Sonatype.Events.fireEvent(this.initEventName, items, null);
+
+ items.sort(function(a, b) {
+ if (a.preferredIndex === undefined && b.preferredIndex === undefined) {
+ return 0;
+ }
+
+ if (a.preferredIndex === undefined) {
+ return 1;
+ }
+ else if (b.preferredIndex === undefined) {
+ return -1;
+ }
+ else if (a.preferredIndex < b.preferredIndex) {
+ return -1;
+ }
+ else if (a.preferredIndex > b.preferredIndex) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ });
+
+ for (i = 0; i < items.length; i+=1) {
+ this.add(items[i]);
+ }
+ };
+
+ Ext.extend(Sonatype.repoServer.ArtifactContainer, Sonatype.panels.AutoTabPanel, {
+ collapsePanel : function() {
+ this.collapse();
+ Sonatype.Events.fireEvent(this.updateEventName, this, null);
+ },
+ updateArtifact : function(data) {
+ Sonatype.Events.fireEvent(this.updateEventName, this, data);
+ if (data) {
+ this.expand();
+ }
+ },
+ hideTab : function(panel) {
+ var i, nextPanel;
+
+ panel.tabHidden = true;
+ this.tabPanel.hideTabStripItem(panel);
+ for (i = 0; i < this.tabPanel.items.getCount(); i+=1) {
+ nextPanel = this.tabPanel.items.get(i);
+ if (nextPanel.id !== panel.id && !nextPanel.tabHidden) {
+ this.tabPanel.setActiveTab(nextPanel);
+ return;
+ }
+ }
+
+ // we haven't found anything, so collapse
+ this.tabPanel.doLayout();
+ this.collapse();
+ },
+ showTab : function(panel) {
+ panel.tabHidden = false;
+ this.tabPanel.unhideTabStripItem(panel);
+ }
+
+ });
+ });
+
Oops, something went wrong.

0 comments on commit 175a0ae

Please sign in to comment.