Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

EZP-23147: As a developer, I want to be able to write plugins for the apps #100

Merged
merged 4 commits into from Jul 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion Resources/config/yui.yml
Expand Up @@ -9,7 +9,6 @@ parameters:
- 'app-transitions'
- 'node-screen'
- 'parallel'
- 'handlebars'
- 'ez-capi'
- 'ez-loginformviewservice'
- 'ez-loginformview'
Expand All @@ -25,6 +24,9 @@ parameters:
- 'ez-errorview'
- 'ez-usermodel'
- 'ez-pluginregistry'
- 'ez-registerpartialsplugin'
- 'ez-registerurlhelpersplugin'
- 'ez-domstateplugin'
path: js/apps/ez-platformuiapp.js
ez-viewservice:
requires: ['base', 'parallel']
Expand Down Expand Up @@ -220,6 +222,15 @@ parameters:
ez-pluginregistry:
requires: ['array-extras']
path: js/services/ez-pluginregistry.js
ez-domstateplugin:
requires: ['plugin', 'base', 'node', 'ez-pluginregistry']
path: js/apps/plugins/ez-domstateplugin.js
ez-registerpartialsplugin:
requires: ['plugin', 'handlebars', 'base', 'node', 'ez-pluginregistry']
path: js/apps/plugins/ez-registerpartialsplugin.js
ez-registerurlhelpersplugin:
requires: ['plugin', 'handlebars', 'base', 'ez-pluginregistry']
path: js/apps/plugins/ez-registerurlhelpersplugin.js
ez-viewservicebaseplugin:
requires: ['plugin', 'base']
path: js/views/services/plugins/ez-viewservicebaseplugin.js
Expand Down
75 changes: 0 additions & 75 deletions Resources/public/js/apps/ez-platformuiapp.js
Expand Up @@ -15,9 +15,7 @@ YUI.add('ez-platformuiapp', function (Y) {
var L = Y.Lang,
APP_OPEN = 'is-app-open',
APP_LOADING = 'is-app-loading',
MINIMIZE_DISCOVERY_BAR_CLASS = 'is-discoverybar-minimized',
ERROR_VIEW_CONTAINER = '.ez-errorview-container',
PARTIALS_SEL = '.ez-platformui-app-partial',

/**
* Fired whenever a fatal error occurs and application is not able to continue current action
Expand Down Expand Up @@ -137,46 +135,8 @@ YUI.add('ez-platformuiapp', function (Y) {
this.set('loading', true);
});

this.on('*:minimizeDiscoveryBarAction', this._minimizeDiscoveryBar);

this.on('*:navigationModeChange', this._uiSetNavigationModeClass);

// Listening for events fired on child views
this.views.errorView.instance.addTarget(this);

// Registering handlebars partials
this._registerPartials();
this._registerUrlHelpers();
},

/**
* navigationModeChange event handler, it sets or unsets the navigation
* mode class provided in the event facade to handle the fact that the
* navigation hub can be fixed or not.
*
* @method _uiSetNavigationModeClass
* @protected
* @param {Object} e navigation mode event facade
*/
_uiSetNavigationModeClass: function (e) {
if ( e.navigation.value ) {
this.get('container').addClass(e.navigation.modeClass);
} else {
this.get('container').removeClass(e.navigation.modeClass);
}
},

/**
* minimizeDiscoveryBarAction event handler, toggles the discovery bar
* mininized class on the app container to minimize/maximize the
* discovery bar
*
* @method _minimizeDiscoveryBar
* @protected
* @param {Object} e event facade of the minimizeDiscoveryBarAction
*/
_minimizeDiscoveryBar: function (e) {
this.get('container').toggleClass(MINIMIZE_DISCOVERY_BAR_CLASS);
},

/**
Expand Down Expand Up @@ -532,41 +492,6 @@ YUI.add('ez-platformuiapp', function (Y) {
}
},

/**
* Register any handlebar partials situated in the DOM and sporting
* PARTIALS_SEL class
*
* @method _registerPartials
* @protected
*/
_registerPartials: function () {
Y.all(PARTIALS_SEL).each(function (partial) {
Y.Handlebars.registerPartial(partial.get('id'), partial.getHTML());
});
},

/**
* Registers the URL related handlebars helpers, ie:
*
* * `path`: to generate an URL from its name and its parameters
* * `asset` : to generate the URL to an asset available in the
* `assetRoot` directory
*
* @method _registerUrlHelpers
* @protected
*/
_registerUrlHelpers: function () {
var that = this;

Y.Handlebars.registerHelper('path', function (routeName, options) {
return that.routeUri(routeName, options.hash);
});

Y.Handlebars.registerHelper('asset', function (uri) {
return that.get('assetRoot').replace(/\/+$/, '') + '/' + uri.replace(/^\/+/, '');
});
},

/*
* Overrides the default implementation to make sure the view `active`
* attribute is set to true after the view is attached to the
Expand Down
72 changes: 72 additions & 0 deletions Resources/public/js/apps/plugins/ez-domstateplugin.js
@@ -0,0 +1,72 @@
/*
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
YUI.add('ez-domstateplugin', function (Y) {
"user strict";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

/**
* Provides the DOM state plugin
*
* @module ez-domstateplugin
*/
Y.namespace('eZ.Plugin');

var MINIMIZE_DISCOVERY_BAR_CLASS = 'is-discoverybar-minimized';

/**
* DOM State plugin. Reflects the application state in the DOM by setting
* some classes depending on the events.
*
* @namespace eZ.Plugin
* @class DomState
* @constructor
* @extends Plugin.Base
*/
Y.eZ.Plugin.DomState = Y.Base.create('domStatePlugin', Y.Plugin.Base, [], {
initializer: function () {
this.onHostEvent(
'*:minimizeDiscoveryBarAction', this._uiMinimizeDiscoveryBar
);
this.onHostEvent(
'*:navigationModeChange', this._uiNavigationModeChange
);
},

/**
* `minimizeDiscoveryBarAction` event handler. It toggles the discovery
* bar mininized class on the app container to minimize/maximize it.
*
* @method _uiMinimizeDiscoveryBar
* @protected
* @param {Object} e minimizeDiscoveryBarAction event facade
*/
_uiMinimizeDiscoveryBar: function (e) {
this.get('host').get('container').toggleClass(MINIMIZE_DISCOVERY_BAR_CLASS);
},

/**
* `navigationModeChange` event handler. it sets or unsets the
* navigation mode class provided in the event facade to handle the fact
* that the navigation hub can be fixed or not.
*
* @method _uiNavigationModeChange
* @protected
* @param {Object} e navigationModeChange event facade
*/
_uiNavigationModeChange: function (e) {
var container = this.get('host').get('container');

if ( e.navigation.value ) {
container.addClass(e.navigation.modeClass);
} else {
container.removeClass(e.navigation.modeClass);
}
},
}, {
NS: 'domState',
});

Y.eZ.PluginRegistry.registerPlugin(
Y.eZ.Plugin.DomState, ['platformuiApp']
);
});
51 changes: 51 additions & 0 deletions Resources/public/js/apps/plugins/ez-registerpartialsplugin.js
@@ -0,0 +1,51 @@
/*
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
YUI.add('ez-registerpartialsplugin', function (Y) {
"user strict";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

/**
* Provides the register partials plugin
*
* @module ez-registerpartialsplugin
*/
Y.namespace('eZ.Plugin');

var PARTIALS_SEL = '.ez-platformui-app-partial';

/**
* Register partial plugin. It's a plugin for the PlatformUI application to
* automatically register Handlebars partials found in the DOM.
*
* @namespace eZ.Plugin
* @class RegisterPartials
* @constructor
* @extends Plugin.Base
*/
Y.eZ.Plugin.RegisterPartials = Y.Base.create('registerPartialsPlugin', Y.Plugin.Base, [], {
initializer: function () {
this._registerPartials();
},

/**
* Register the handlebar partials available in the DOM. The content of
* any element with the class `ez-platformui-app-partial` is considered
* as a handlebars partial and is registered with its `id` as the
* partial name.
*
* @method _registerPartials
* @protected
*/
_registerPartials: function () {
Y.all(PARTIALS_SEL).each(function (partial) {
Y.Handlebars.registerPartial(partial.get('id'), partial.getHTML());
});
},
}, {
NS: 'registerPartials',
});

Y.eZ.PluginRegistry.registerPlugin(
Y.eZ.Plugin.RegisterPartials, ['platformuiApp']
);
});
68 changes: 68 additions & 0 deletions Resources/public/js/apps/plugins/ez-registerurlhelpersplugin.js
@@ -0,0 +1,68 @@
/*
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
YUI.add('ez-registerurlhelpersplugin', function (Y) {
"user strict";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

/**
* Provides the register url helpers plugin
*
* @module ez-registerhelpersplugin
*/
Y.namespace('eZ.Plugin');

/**
* Register Url Helpers plugin for the Platform UI application. It registers
* two handlebars helpers to deal with the url:
*
* * `path` is meant to build link to application routes. It takes the
* name of a route and the expected route parameters as a literal object
* * `asset` is meant to build url to a static file provided by the
* PlatformUIBundle (typically an image)
*
* @namespace eZ.Plugin
* @class RegisterUrlHelpers
* @constructor
* @extends Plugin.Base
*/
Y.eZ.Plugin.RegisterUrlHelpers = Y.Base.create('registerUrlHelpersPlugin', Y.Plugin.Base, [], {
initializer: function () {
this._registerPath();
this._registerAsset();
},

/**
* Registers the `path` handlebars helper.
*
* @method _registerPath
* @protected
*/
_registerPath: function () {
var app = this.get('host');

Y.Handlebars.registerHelper('path', function (routeName, options) {
return app.routeUri(routeName, options.hash);
});
},

/**
* Registers the `asset` handlebars helper.
*
* @method _registerAsset
* @protected
*/
_registerAsset: function () {
var app = this.get('host');

Y.Handlebars.registerHelper('asset', function (uri) {
return app.get('assetRoot').replace(/\/+$/, '') + '/' + uri.replace(/^\/+/, '');
});
},
}, {
NS: 'registerUrlHelpers',
});

Y.eZ.PluginRegistry.registerPlugin(
Y.eZ.Plugin.RegisterUrlHelpers, ['platformuiApp']
);
});
1 change: 1 addition & 0 deletions Resources/views/PlatformUI/shell.html.twig
Expand Up @@ -137,6 +137,7 @@
viewContainer: '.ez-view-container',
root: "{{ app.request.attributes.get( 'semanticPathinfo' ) }}",
assetRoot: "{{ asset( '/' ) }}",
plugins: Y.eZ.PluginRegistry.getPlugins(Y.eZ.PlatformUIApp.NAME),
capi: new Y.eZ.CAPI(
"{{ app.request.uriForPath('/')|trim('/') }}",
new Y.eZ.SessionAuthAgent()
Expand Down