Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add js helpers from usertoken #698

Merged
merged 2 commits into from

4 participants

@jdillon
Owner

Adds bits used by usertoken to oss core:

  • Ext.define
  • Nexus.messages
  • Ext.Image
  • String.startsWith
  • String.endsWith
  • Ext.CallbackRef
  • Nexus.currentUser
@peterlynch
Owner

is this needed for 2.3?

@jdillon
Owner

No it can wait until 2.4

@peterlynch
Owner

+1 for 2.4

@nabcos

+1

@adreghiciu
Owner

+0 (+1 for moving but too low Est js knowledge to review changes)

@jdillon jdillon Merge branch 'master' into move-usertoken-js-helpers
Conflicts:
	nexus/nexus-webapp/src/main/webapp/style/Sonatype.css
43b8f5e
@jdillon jdillon merged commit 030502d into master
@jdillon jdillon deleted the move-usertoken-js-helpers branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 8, 2012
  1. @jdillon

    Add js helpers from usertoken

    jdillon authored
Commits on Jan 4, 2013
  1. @jdillon

    Merge branch 'master' into move-usertoken-js-helpers

    jdillon authored
    Conflicts:
    	nexus/nexus-webapp/src/main/webapp/style/Sonatype.css
This page is out of date. Refresh to see the latest.
View
4 nexus/nexus-webapp/src/main/webapp/js/ext/all.js
@@ -12,8 +12,8 @@
*/
/*global define*/
define('ext/all',
- ['extjs', 'ext/ux', 'ext/data', 'ext/dd', 'ext/form',
- 'ext/layout', 'ext/lib', 'ext/tree', 'ext/component',
+ ['extjs', 'ext/define', 'ext/ux', 'ext/data', 'ext/dd', 'ext/form',
+ 'ext/image', 'ext/layout', 'ext/lib', 'ext/tree', 'ext/component',
'ext/string', 'ext/tooltip', 'ext/util', 'ext/element'],
function(Ext) {
Ext.BLANK_IMAGE_URL = "ext-3.4.0/resources/images/default/s.gif";
View
123 nexus/nexus-webapp/src/main/webapp/js/ext/define.js
@@ -0,0 +1,123 @@
+/*
+ * 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.
+ */
+define('ext/define', ['extjs', 'nexus/log'], function () {
+ //
+ // NOTE: extjs 3.4.1 has an Ext.define, but its no available in a GPL version, so we have to use this cruft until we move over to extjs 4.x
+ //
+
+ /**
+ * Used as the super-class for all Ext.define classes which not not provide a class to extend.
+ * Do not put anything special in here, since not everything will use this as its super-class.
+ *
+ * @constructor
+ */
+ Ext.Base = function (config) {
+ //console.log('Ext.Base CTOR');
+ Ext.apply(this, config);
+ };
+
+ /**
+ * Define a new class.
+ *
+ * @param {String} className The name of the class to define.
+ * @param {Object} data Configuration for the class.
+ * @param {Function} createdFn Function to execute when class has been defined.
+ * @return {Function} A reference to the defined class.
+ * @static
+ */
+ Ext.define = function (className, data, createdFn) {
+ data = data || {};
+
+ var i, nameSpace, baseClassName, superName, type, superClass, statics, obj;
+
+ obj = function (path) {
+ var context = window;
+ Ext.each(path.split('.'), function (part) {
+ context = context[part];
+ });
+ return context;
+ };
+
+ // Find the namespace (if any) for the new class
+ i = className.lastIndexOf('.');
+ if (i !== -1) {
+ nameSpace = className.substring(0, i);
+ baseClassName = className.substring(i + 1);
+ }
+ else {
+ baseClassName = className;
+ }
+
+ // Determine the super-class
+ superName = data.extend || 'Ext.Base';
+ delete data.extend;
+
+ // Extract static configuration
+ statics = data.statics;
+ delete data.statics;
+
+ Nexus.log('Defining class: ' + className + ' (ns: ' + nameSpace + ', super: ' + superName + ')');
+
+ // Create namespace if required
+ if (nameSpace) {
+ Ext.namespace(nameSpace);
+ }
+
+ // Get a reference to the super-class
+ superClass = obj(superName);
+
+ // When no constructor given in configuration (its always there due to picking upt from Object.prototype), use a synthetic version
+ if (data.constructor === Object.prototype.constructor) {
+ data.constructor = function () {
+ // Just call superclass constructor
+ this.constructor.superclass.constructor.apply(this, arguments);
+ };
+ }
+
+ // Create the sub-class
+ type = Ext.extend(superClass, data);
+
+ // Assign to global namespace
+ obj(nameSpace)[baseClassName] = type;
+
+ // Enrich the sub-class prototype
+ type.prototype.$className = className;
+
+ // FIXME: Figure out how to fucking define this properly, all seem to work in different fucking ways
+ //type.prototype.superclass = superClass;
+ //type.prototype.$super = superClass.prototype;
+ //type.prototype.$super = eval(className + '.superclass');
+ //type.prototype.$super = function () {};
+
+ type.prototype.$log = function (message) {
+ Nexus.log(this.$className + ': ' + message);
+ };
+
+ // Apply any static members
+ if (statics !== undefined) {
+ Ext.apply(type, statics);
+ }
+
+ // Call post-define hook
+ if (createdFn !== undefined) {
+ // Scope to created type, empty args seems to be required here
+ createdFn.call(type, []);
+ }
+
+ return type;
+ };
+
+ // FIXME: Port over extjs-4 Ext.create() bits so we can have sane[r] object creation
+
+ // FIXME: Port over extjs-4 Ext.Error.* bits so we can have sane[r] exception handling
+});
View
48 nexus/nexus-webapp/src/main/webapp/js/ext/image.js
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+define('ext/image', ['ext/define'], function(){
+
+ /**
+ * A simple component to display an image.
+ *
+ * @class Ext.Image
+ * @extends Ext.BoxComponent
+ * @namespace Ext
+ */
+ Ext.define('Ext.Image', {
+ extend: 'Ext.BoxComponent',
+
+ /**
+ * @cfg {String} src Image source
+ */
+ constructor: function (config) {
+ var self = this;
+
+ Ext.apply(self, {
+ autoEl: {
+ tag: 'img',
+ src: config.src
+ }
+ });
+
+ // Call super constructor
+ self.constructor.superclass.constructor.apply(self, arguments);
+ }
+ },
+
+ function () {
+ var type = this;
+ Ext.ComponentMgr.registerType('image', type);
+ });
+
+});
View
65 nexus/nexus-webapp/src/main/webapp/js/ext/string.js
@@ -10,18 +10,59 @@
* 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.
*/
-define('ext/string',function(){
-String.prototype.replaceAll = function(strTarget, strSubString) {
- var
- strText = this,
- intIndexOfMatch = strText.indexOf(strTarget);
+define('ext/string', ['extjs'], function () {
- while (intIndexOfMatch !== -1)
- {
- strText = strText.replace(strTarget, strSubString);
- intIndexOfMatch = strText.indexOf(strTarget);
- }
+ /**
+ * Add support for String.replaceAll(String,String).
+ *
+ * @class String
+ */
+ Ext.applyIf(String.prototype, {
+ /**
+ * @param strTarget
+ * @param strSubString
+ * @return {String}
+ */
+ replaceAll: function (strTarget, strSubString) {
+ var strText = this, intIndexOfMatch = strText.indexOf(strTarget);
+
+ while (intIndexOfMatch !== -1) {
+ strText = strText.replace(strTarget, strSubString);
+ intIndexOfMatch = strText.indexOf(strTarget);
+ }
+
+ return (strText);
+ }
+ });
+
+ /**
+ * Add support for String.startsWith(String).
+ *
+ * @class String
+ */
+ Ext.applyIf(String.prototype, {
+ /**
+ * @param str
+ * @return {Boolean}
+ */
+ startsWith: function (str) {
+ return this.indexOf(str) === 0;
+ }
+ });
+
+ /**
+ * Add support for String.endsWith(String).
+ *
+ * @class String
+ */
+ Ext.applyIf(String.prototype, {
+ /**
+ * @param str
+ * @return {Boolean}
+ */
+ endsWith: function (str) {
+ return this.slice(-str.length) === str;
+ }
+ });
- return (strText);
-};
});
View
14 nexus/nexus-webapp/src/main/webapp/js/nexus.js
@@ -15,7 +15,17 @@
define('nexus', ['extjs'], function(Ext){
- Ext.namespace('Nexus');
+ Ext.namespace('Nexus');
- return window.Nexus;
+ /**
+ * Return the current user.
+ *
+ * @return {*}
+ * @static
+ */
+ Nexus.currentUser = function () {
+ return Sonatype.user.curr;
+ };
+
+ return window.Nexus;
});
View
6 nexus/nexus-webapp/src/main/webapp/js/nexus/all.js
@@ -11,15 +11,17 @@
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
define('nexus/all',
- ['nexus/config',
+ [ 'nexus/callbackref',
+ 'nexus/config',
'nexus/error',
'nexus/ext',
'nexus/form',
'nexus/log',
+ 'nexus/messages',
'nexus/messagebox',
'nexus/navigation',
'nexus/panels',
'nexus/grid',
'nexus/profile',
- 'nexus/util'],
+ 'nexus/util' ],
function() {});
View
49 nexus/nexus-webapp/src/main/webapp/js/nexus/callbackref.js
@@ -0,0 +1,49 @@
+/*
+ * 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/callbackref', ['ext/define'], function () {
+
+ /**
+ * Encapsulates a callback reference.
+ *
+ * @class Nexus.CallbackRef
+ * @namespace Nexus
+ */
+ Ext.define('Nexus.CallbackRef', {
+ /**
+ * @cfg {Object} Scope to use when invoking callback function.
+ */
+ scope: undefined,
+
+ /**
+ * @cfg {Function} Callback function.
+ */
+ fn: undefined,
+
+ /**
+ * Invoke the callback function in the configured scope.
+ *
+ * @return {*} Whatever the callback function returns.
+ */
+ invoke: function () {
+ var self = this;
+
+ if (self.fn === undefined) {
+ throw 'Missing configuration: fn';
+ }
+
+ return self.fn.apply(self.scope || self, arguments);
+ }
+ });
+
+});
View
49 nexus/nexus-webapp/src/main/webapp/js/nexus/messages.js
@@ -0,0 +1,49 @@
+/*
+ * 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/messages', ['extjs', 'nexus'], function() {
+ /**
+ * Helper to show transient messages to users.
+ *
+ * This is based on the Ext.examples.msg helper in the 2.3 sources.
+ */
+ Nexus.messages = function () {
+ var msgCt;
+
+ // FIXME: Sort out a better way to do this so we can include icons and other muck if needed
+
+ function createBox(t, s) {
+ return [
+ '<div class="nx-msg">',
+ '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
+ '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
+ '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
+ '</div>'
+ ].join('');
+ }
+
+ return {
+ show: function (title, format) {
+ var s, m;
+
+ if (!msgCt) {
+ msgCt = Ext.DomHelper.insertFirst(document.body, {id: 'nx-msg-div'}, true);
+ }
+ msgCt.alignTo(document, 't-t');
+ s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
+ m = Ext.DomHelper.append(msgCt, {html: createBox(title, s)}, true);
+ m.slideIn('t').pause(2).ghost("t", {remove: true});
+ }
+ };
+ }();
+});
View
22 nexus/nexus-webapp/src/main/webapp/style/Sonatype.css
@@ -521,6 +521,28 @@ body.x-body-masked .x-window-plain .x-window-mc {
background-color: #F2F1F0 !important;
}
+/* Nexus.messages */
+
+.nx-msg .x-box-mc {
+ font-size: 14px;
+}
+
+#nx-msg-div {
+ position: absolute;
+ left: 35%;
+ top: 10px;
+ width: 250px;
+ z-index: 20000;
+}
+
+/* Ext.LinkButton */
+
+.x-linkbtn-wrap {}
+.x-linkbtn-left {}
+.x-linkbtn-center {}
+.x-linkbtn-text {}
+.x-linkbtn-wright {}
+
/*
* Text in linkbutton should be centered.
*/
Something went wrong with that request. Please try again.