Permalink
Browse files

nav/cms refactor, changes all over, added navigationDataSourceInterfa…

…ce.js
  • Loading branch information...
1 parent ae10cbe commit 7038775ffee29468ac6db3009d69dcc5055d21e9 Thiago de Mello Bueno committed May 7, 2011
View
@@ -14,7 +14,69 @@ if (!window.console ){ window.console = {};
/*
Section: Extending Mootools
+*/
+
+/*
+Class: Interfaces
+description: Interfaces provides some Interface functionality to Class (and also provides an Interface Object)
+license: MIT-style
+authors: Sebastian Wohlrab
+requires: core/1.2.4: '*'
+provides: [Class.Interfaces]
+...
+*/
+
+Class.Mutators.Interfaces = function( interfaces ) {
+ this.implement('initialize', function(){});
+ console.log( "Interfaces", interfaces );
+ return interfaces;
+};
+
+Class.Mutators.initialize = function( initialize ) {
+ return function() {
+ Array.from( this.Interfaces ).each( function( implemented ) {
+ console.log( ":::", this.Interfaces, implemented, implemented.Interface );
+ implemented.Interface.Check( this );
+ }, this );
+ return initialize.apply( this, arguments );
+ }
+}
+var Interface = function( name, members ) {
+ members.Interface = {
+ Name: name,
+ Check: function( obj ) {
+ console.log( "What?" );
+ var error = [];
+ for ( p in members ) {
+ switch( p ) {
+ case "Interface": /* reservated */ break;
+ case "Interfaces":
+ var existing = false;
+ $splat(members[p]).each(function(iNeeded) {
+ $splat(obj[p]).each(function(iExisting) {
+ if ( iNeeded.Interface.Name == iExisting.Interface.Name) existing = true;
+ });
+ });
+ if ( !existing ) {
+ error.push( p );
+ }
+ break;
+ default:
+ if ( !(p in obj) ) {
+ error.push( p );
+ }
+ break;
+ }
+ }
+ if ( error.length > 0 ) {
+ throw new Error( "[" + this.Name + "] The following Interface members are not implemented yet: " + error.join(', ') );
+ }
+ }
+ };
+ return members;
+};
+/*
Function: getSiblings
Arguments:
match - {Element} an element to get the sibling
@@ -69,7 +131,7 @@ Function.implement({
s - {String} a string
Returns: {String} argumemt string as UTF-8 string
*/
-String.implement( "encodeUTF8", function( ){
+String.implement( "encodeUTF8", function(){
return unescape( encodeURIComponent( this ) );
});
@@ -195,6 +257,7 @@ mop.util.getBaseURL = function(){
Gets urls to the application front-controller
Returns: baseURL + appention (appurl for ajax purposes)
*/
+
mop.util.getAppURL = function(){
var appURLAppendClassName = mop.util.getValueFromClassName( "appUrlAppend", $(document).getElement("body").get("class") );
var appUrlAppend;
@@ -247,6 +310,7 @@ mop.util.getUniqueId = function ( prefix ){
Note: Does this need to exist?
*/
mop.util.JSONSend = function( url, data, options ){
+ url.toURI().toAbsolute();
if( options ){
options.url = url;
}else{
@@ -464,7 +528,7 @@ mop.MoPObject = new Class({
Convenience method that calls mop.util.JSONSend;
*/
JSONSend: function( action, data, options ){
- var url = mop.util.getAppURL() + "ajax/" + this.getSubmissionController() + "/" + action + "/" + mop.objectId;
+ var url = "ajax/" + this.getSubmissionController() + "/" + action + "/" + mop.objectId;
if( options ){ options.url = url; }else{ options = { url: url }; }
new Request.JSON( options ).post( data );
},
@@ -529,9 +593,9 @@ mop.util.HistoryManager = new Class({
Implements: mop.util.Broadcaster,
locationListener: null,
- appState: new Hash(),
+ appState: {},
_instance: null,
- registeredEvents: new Hash(),
+ registeredEvents: {},
initialize: function(){
return this;
@@ -549,7 +613,7 @@ mop.util.HistoryManager = new Class({
},
init: function( eventKey, eventString ){
- this.registeredEvents.set( eventKey, eventString );
+ this.registeredEvents[ eventKey ] = eventString;
this.currentHash = this.getStrippedHash();
// console.log( "HistoryManager.init", this.currentHash );
this.storeStateFromHash();
@@ -567,7 +631,7 @@ mop.util.HistoryManager = new Class({
keyValuePair = keyValuePair.split("-");
var key = keyValuePair[0];
var value = keyValuePair[1];
- this.appState.set( key, value );
+ this.appState[ key ] = value;
key = null;
value = null;
}, this );
@@ -590,11 +654,11 @@ mop.util.HistoryManager = new Class({
},
registerEvent: function( eventKey, eventString ){
- this.registeredEvents.set( eventKey, eventString );
+ this.registeredEvents[ eventKey ] = eventString;
},
changeState: function( key, value ){
- this.appState.set( key, value );
+ this.appState[ key ] = value;
this.updateHash();
},
@@ -610,7 +674,7 @@ mop.util.HistoryManager = new Class({
},
getValue: function( key ){
- return ( this.appState.get( key ) ) ? this.appState.get( key ) : null;
+ return ( this.appState[ key ] ) ? this.appState[ key ] : null;
},
fireEvents: function(){
@@ -682,7 +746,7 @@ mop.util.LoginMonitor = new Class({
clearInterval( this.inactivityTimeout );
clearInterval( this.logoutTimeout );
this.inactivityTimeout = this.onInactivity.periodical( this.secondsOfInactivityTilPrompt, this );
- new Request.JSON( { url: mop.util.getAppURL()+"keepalive" } ).post();
+ new Request.JSON( { url:"keepalive" } ).post();
},
logout: function(){
@@ -692,7 +756,7 @@ mop.util.LoginMonitor = new Class({
delete this.status;
window.removeEvents();
this.dialogue.destroy();
- window.location = mop.util.getAppURL()+"auth/logout";
+ window.location = "auth/logout".toURI().toAbsolute();
}
});
View
@@ -3,7 +3,6 @@
mop Modules
*/
mop.modules = {};
-
/*
Class: mop.modules.Module
Base module
@@ -20,12 +19,12 @@ mop.modules.Module = new Class({
Variable: UIElements
list of this module's UIElements
*/
- UIElements: new Hash(),
+ UIElements: {},
/*
Variable: childModules
Modules loaded within this module
*/
- childModules: null, //new Hash(),
+ childModules: {},
initialize: function( anElementOrId, aMarshal, options ){
// console.log( "Constructing", this.toString(), this.childModules );
@@ -77,23 +76,18 @@ mop.modules.Module = new Class({
initModules: function( anElement ){
var descendantModules = ( anElement )? anElement.getElements(".module") : this.element.getElements(".module");
var filteredOutModules = [];
- console.log( "\tinitModules", this.toString(), anElement );
descendantModules.each( function( aDescendant ){
descendantModules.each( function( anotherDescendant ){
- console.log( this.toString(), "\tdescendantloop", aDescendant, anotherDescendant, aDescendant.contains( anotherDescendant ) );
if( aDescendant.contains( anotherDescendant ) && aDescendant != anotherDescendant ) filteredOutModules.push( anotherDescendant );
}, this );
}, this );
- console.log( this.toString(), "\t\tfilteredOutModules", filteredOutModules );
descendantModules.each( function( aDescendant ){
if( !filteredOutModules.contains( aDescendant ) ){
- if( !this.childModules ) this.childModules = new Hash();
var module = this.initModule( aDescendant );
var instanceName = module.instanceName;
- this.childModules.set( instanceName, module );
+ this.childModules[ instanceName ] = module;
}
}, this );
- console.log( "childModules", this.toString(), this.childModules );
delete filteredOutModules, descendantModules;
filteredOutModules = descendantModules = null;
},
@@ -108,16 +102,16 @@ mop.modules.Module = new Class({
*/
initModule: function( element ){
var classPath = mop.util.getValueFromClassName( "classPath", element.get( "class" ) ).split( "_" );
- console.log( "\t\tinitModule", this.toString(), element.get( "class" ), classPath );
+// console.log( "\t\tinitModule", this.toString(), element.get( "class" ), classPath );
ref = null;
classPath.each( function( node ){
ref = ( !ref )? this[node] : ref[node];
- console.log( ref, node );
+// console.log( ref, node );
});
var newModule = new ref( element, this );
return newModule;
},
-
+
/*
Function: getModuleUIElements
*/
@@ -150,7 +144,7 @@ mop.modules.Module = new Class({
UIElements.each( function( anElement ){
var UIElement = new mop.ui[ mop.util.getValueFromClassName( "ui", anElement.get( "class" ) ) ]( anElement, this, this.options );
- this.UIElements.set( UIElement.fieldName, UIElement );
+ this.UIElements[ UIElement.fieldName ] = UIElement;
}, this );
if( this.postInitUIHook ) this.postInitUIHook();
@@ -164,11 +158,11 @@ mop.modules.Module = new Class({
@TODO, this shouldnt necessarily be a part of module, but rather something more like an ModuleInstantiator interface */
destroyChildModules: function( whereToLook ){
// console.log( "destroyChildModules", this.toString(), this.childModules );
- if( !this.childModules || this.childModules.getLength() == 0 ) return;
+ if( !this.childModules || Object.getLength( this.childModules ) == 0 ) return;
var possibleTargets = ( whereToLook )? whereToLook.getElements( ".module" ) : this.element.getElements( ".module" );
- this.childModules.each( function( aModule ){
+ Object.each( this.childModules, function( aModule ){
if( possibleTargets.contains( aModule.element ) ){
var key = aModule.instanceName;
aModule.destroy();
@@ -221,7 +215,7 @@ mop.modules.Cluster = new Class({
Extends: mop.modules.Module,
initialize: function( anElementOrId, aMarshal, options ){
this.parent( anElementOrId, aMarshal, options );
-// console.log( "Cluster objectId", this.getObjectId() );
+ // console.log( "Cluster objectId", this.getObjectId() );
},
getSubmissionController: function(){
return this.marshal.getSubmissionController();
View
@@ -131,10 +131,10 @@ mop.ui.navigation.BreadCrumbTrail = new Class({
className: "BreadCrumbTrail",
- initialize: function( anElement, onBreadCrumbClickedCallback ){
+ initialize: function( anElement, onCrumbClickedCallback ){
this.element = anElement;
- this.onBreadCrumbClickedCallback = onBreadCrumbClickedCallback;
- console.log( "BreadCrumbTrail", this, this.element )
+ this.onCrumbClickedCallback = onCrumbClickedCallback;
+// console.log( "BreadCrumbTrail", this, this.element );
},
toString: function(){
@@ -151,28 +151,25 @@ mop.ui.navigation.BreadCrumbTrail = new Class({
},
addCrumb: function( obj ){
- var crumb = new Element( "a", {
- "text": obj.label,
- "events":{
- "click": this.onBreadCrumbClicked.bindWithEvent( this, obj )
- }
- });
- var listItem = new Element( "li" );
- crumb.inject( listItem );
- if( this.element.getChildren("li")[ obj.index ] ){
- listItem.replaces( this.element.getChildren("li")[ obj.index ] );
- }
+// console.log( "::::::::", obj );
+ var newCrumb = new Element( "li" ).adopt(
+ new Element( "a", { "text": obj.label, "events":{ "click": this.onCrumbClicked.bindWithEvent( this, obj ) } } )
+ );
+ var crumbs = this.element.getElements("li");
+ this.element.getElement("ul").adopt( newCrumb );
+// console.log( "addCrumb >>>>>> ", newCrumb );
},
- onBreadCrumbClicked: function( e, obj ){
- mop.util.stopEvent();
-// console.log( this.toString(), "onBreadCrumbClicked", obj );
- this.onBreadCrumbClickedCallback( obj );
+ onCrumbClicked: function( e, obj ){
+ mop.util.stopEvent( e );
+// console.log( "::::: \t onBreadCrumbClicked", obj );
+ this.onCrumbClickedCallback( obj );
},
- removeBreadCrumb: function( anIndex ){
- var crumb = this.element.getChildren( "li" )[ anIndex ];
- crumb.destroy();
+ removeCrumb: function( anIndex ){
+ console.log( "removeCrumb", anIndex );
+ var crumb = this.element.getElements( "li" )[ anIndex ];
+ if( crumb ) crumb.destroy();
},
destroy: function(){
@@ -2281,7 +2278,7 @@ mop.ui.FileElement = new Class({
},
getSubmitURL: function(){
- var url = mop.util.getAppURL() + "ajax/data/" + this.marshal.getSubmissionController() + "/" + this.action + "/" + this.marshal.getObjectId();
+ var url = "ajax/data/" + this.marshal.getSubmissionController() + "/" + this.action + "/" + this.marshal.getObjectId();
// console.log( ":::: ", this.toString(), "getSubmitURL: ", url );
return url;
},
@@ -2967,7 +2964,7 @@ mop.ui.PulldownNav = new Class({
redirect: function(){
if( this.getValue() == null || this.getValue() == "" ) return;
- var url = mop.util.getAppURL() + this.getValue();
+ var url = this.getValue();
window.location.href = url;
}
@@ -3066,7 +3063,7 @@ mop.ui.CheckBox = new Class({
if( this.showSaving ) this.showSaving();
- var url = mop.util.getAppURL() + "ajax/data/" + this.marshal.getSubmissionController() + "/" + this.action + "/" + this.marshal.getObjectId();
+ var url = "ajax/data/" + this.marshal.getSubmissionController() + "/" + this.action + "/" + this.marshal.getObjectId();
var submittedVars = { field: this.fieldName, value: val };
console.log( this.toString(), "submit", url, submittedVars );
mop.util.JSONSend( url, submittedVars, { onComplete: this.onResponse.bind( this ) } );
@@ -4018,7 +4015,7 @@ mop.ui.PaginationControls = new Class({
}else{
this.spinner.removeClass( "hidden" );
var marshalId = ( this.marshal.instanceName )? this.marshal.instanceName : this.marshal.get("id");
- var url = mop.util.getAppURL() + "ajax/data/" + marshalId + "/" + this.method + "/" + this.listId + "/" + this.currentPage;
+ var url = "ajax/data/" + marshalId + "/" + this.method + "/" + this.listId + "/" + this.currentPage;
var postData = ( this.marshal.getPaginationPostData )? this.marshal.getPaginationPostData() : null ; //getGeneratedDataQueryString() : null;
// console.log( this.toString(), "paginate uncached page >> ", url, postData );
mop.util.JSONSend( url, postData, { onComplete: this.onPagination.bind( this ) } );
Oops, something went wrong.

0 comments on commit 7038775

Please sign in to comment.