Skip to content

Commit

Permalink
EZP-28003: Unable to go back to the Content structure after content m…
Browse files Browse the repository at this point in the history
…ove to the Media library (ezsystems#913)
  • Loading branch information
sunpietro authored and Łukasz Serwatka committed Oct 23, 2017
1 parent fbf6c16 commit 66b32a2
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 43 deletions.
124 changes: 82 additions & 42 deletions Resources/public/js/views/services/ez-locationviewviewservice.js
Expand Up @@ -2,6 +2,7 @@
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
/*jshint esversion: 6 */
YUI.add('ez-locationviewviewservice', function (Y) {
"use strict";
/**
Expand Down Expand Up @@ -273,53 +274,92 @@ YUI.add('ez-locationviewviewservice', function (Y) {
* @param {EventFacade} e
*/
_moveContent: function (e) {
var app = this.get('app'),
initialActiveView = app.get('activeView'),
parentLocationId = e.selection.location.get('id'),
oldParentLocationId = this.get('location').get('id'),
locationId = this.get('location').get('id'),
that = this,
content = this.get('content'),
contentName = content.get('name'),
parentContentName = e.selection.contentInfo.get('name'),
notificationIdentifier = 'move-notification-' + parentLocationId + '-' + locationId;
const parentLocationId = e.selection.location.get('id');
const locationId = this.get('location').get('id');
const identifier = 'move-notification-' + parentLocationId + '-' + locationId;
const initialActiveView = this.get('app').get('activeView');
const names = {
name: this.get('content').get('name'),
parentName: e.selection.contentInfo.get('name')
};

this._notify(
Y.eZ.trans('being.moved.under', {name: contentName, parentName: parentContentName}, 'locationview'),
notificationIdentifier,
'started', 5
this._notify(Y.eZ.trans('being.moved.under', names, 'locationview'), identifier, 'started', 5);

this.get('location').move(
{api: this.get('capi')},
parentLocationId,
this._handleAfterContentMoved.bind(this, {identifier, names, initialActiveView})
);
},

this.get('location').move({api: this.get('capi')}, parentLocationId, function (error, response) {
if (error) {
that._notify(
Y.eZ.trans('failed.moving', {}, 'locationview'),
notificationIdentifier, 'error', 0
);
return;
}
/**
* Handles action after moving a content into a new location
*
* @method _handleAfterContentMoved
* @protected
* @param {Object} config config hash containing: identifier, names and initialActiveView properties
* @param {Boolean} error
* @param {Object} response
*/
_handleAfterContentMoved: function ({identifier, names, initialActiveView}, error, response) {
const app = this.get('app');
const location = this.get('location');

that._notify(
Y.eZ.trans('moved.under', {name: contentName, parentName: parentContentName}, 'locationview'),
notificationIdentifier,
'done',
5
);
/**
* Fired when the content is moved
*
* @event movedContent
* @param {eZ.Location} location
* @param {String} oldParentLocationId
*/
that.fire('movedContent', {location: that.get('location'), oldParentLocationId: oldParentLocationId});
if ( app.get('activeView') === initialActiveView ) {
app.navigateTo(
'viewLocation',
{id: response.getHeader('location'), languageCode: content.get('mainLanguageCode')}
);
}
if (error) {
this._notify(Y.eZ.trans('failed.moving', {}, 'locationview'), identifier, 'error', 0);

return;
}

this._notify(Y.eZ.trans('moved.under', names, 'locationview'), identifier, 'done', 5);

/**
* Fired when the content is moved
*
* @event movedContent
* @param {eZ.Location} location
* @param {String} oldParentLocationId
*/
this.fire('movedContent', {
location,
oldParentLocationId: location.get('id')
});

if (app.get('activeView') === initialActiveView) {
const params = {
id: response.getHeader('location'),
languageCode: this.get('content').get('mainLanguageCode')
};

this._updatePrevHistory(params, () => {
/**
* Resets content navigation item link, in the top navigation bar - 'Content Structure'.
* Listened by Y.eZ.NavigationHubViewService
*
* @event updateContentNavigationItem
*/
this.fire('resetContentNavigationItem');

app.navigateTo('viewLocation', params);
});
}
},

/**
* Updates the browser history by removing a reference to a previous,
* already non-existent location of moved content.
*
* @method _updatePrevHistory
* @protected
* @param {Object} params params hash containing: id {String} and languageCode {String}
* @param {Function} callback
*/
_updatePrevHistory({id, languageCode}, callback) {
id = id.substr(0, id.lastIndexOf('/'));

window.location.replace(this.get('app').routeUri('viewLocation', {id, languageCode}));

callback();
},

/**
Expand Down
Expand Up @@ -2,6 +2,7 @@
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
/*jshint esversion: 6 */
YUI.add('ez-navigationhubviewservice', function (Y) {
"use strict";
/**
Expand All @@ -11,6 +12,8 @@ YUI.add('ez-navigationhubviewservice', function (Y) {
*/
Y.namespace('eZ');

const IDENTIFIER_CONTENT_STRUCTURE = 'content-structure';

/**
* Navigation hub view service.
*
Expand All @@ -23,6 +26,38 @@ YUI.add('ez-navigationhubviewservice', function (Y) {
initializer: function () {
this.on('*:logOut', this._logOut);
this.after('*:activeNavigationChange', this._navigateToFirstItemRoute);
this.get('app').on('*:resetContentNavigationItem', this._resetContentNavigationItem, this);
},

/**
* Updates content link in 'Content' navigation zone for current selected content
*
* @method _resetContentNavigationItem
* @protected
* @param {Event} event
*/
_resetContentNavigationItem: function () {
const contentItem = this.getNavigationItem(IDENTIFIER_CONTENT_STRUCTURE);

if (contentItem) {
const matchedRoute = this._matchedRoute();
const rootLocation = this.get('rootLocation');
const rootLocationId = rootLocation.get('id');
const rootLocationLang = rootLocation.get('contentInfo').get('mainLanguageCode');

contentItem.set('route.params.id', rootLocationId);
contentItem.set('route.params.languageCode', rootLocationLang);

matchedRoute.parameters.id = rootLocationId;
matchedRoute.parameters.languageCode = rootLocationLang;

/**
* Simulating matched route change event (the event from the navigation hub view)
*
* @event matchedRouteChange
*/
this.fire('matchedRouteChange', {newVal: matchedRoute});
}
},

/**
Expand Down Expand Up @@ -136,7 +171,7 @@ YUI.add('ez-navigationhubviewservice', function (Y) {
params.id = service.get('rootLocation').get('id');
params.languageCode = service.get('rootLocation').get('contentInfo').get('mainLanguageCode');

service.getNavigationItem('content-structure').set(
service.getNavigationItem(IDENTIFIER_CONTENT_STRUCTURE).set(
'route',
{name: 'viewLocation', params: params}
);
Expand Down

0 comments on commit 66b32a2

Please sign in to comment.