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

Commit

Permalink
Fix EZP-28657: Link to content object should redirect to the main loc…
Browse files Browse the repository at this point in the history
…ation of content (#933)
  • Loading branch information
adamwojs authored and Łukasz Serwatka committed Dec 22, 2017
1 parent 595b9ee commit fbe6ddb
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Resources/config/yui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ system:
- 'ez-sectionserversideviewservice'
- 'ez-roleserversideview'
- 'ez-roleserversideviewservice'
- 'ez-linkviewserversideview'
- 'ez-linkviewserversideviewservice'
- 'ez-navigationhubviewservice'
- 'ez-navigationhubview'
- 'ez-discoverybarviewservice'
Expand Down Expand Up @@ -349,6 +351,9 @@ system:
ez-roleserversideviewservice:
requires: ['ez-serversideviewservice', 'parallel', 'ez-translator']
path: "%ez_platformui.public_dir%/js/views/services/ez-roleserversideviewservice.js"
ez-linkviewserversideviewservice:
requires: ['ez-serversideviewservice', 'parallel', 'ez-translator']
path: "%ez_platformui.public_dir%/js/views/services/ez-linkviewserversideviewservice.js"
ez-view:
requires: ['view', 'base-pluginhost', 'ez-pluginregistry']
path: "%ez_platformui.public_dir%/js/views/ez-view.js"
Expand Down Expand Up @@ -1295,6 +1300,9 @@ system:
ez-roleserversideview:
requires: ['ez-serversideview', 'event-tap']
path: "%ez_platformui.public_dir%/js/views/serverside/ez-roleserversideview.js"
ez-linkviewserversideview:
requires: ['ez-serversideview', 'event-tap']
path: "%ez_platformui.public_dir%/js/views/serverside/ez-linkviewserversideview.js"
ez-texthelper:
requires: ['handlebars']
path: "%ez_platformui.public_dir%/js/helpers/ez-texthelper.js"
Expand Down
12 changes: 12 additions & 0 deletions Resources/public/js/apps/ez-platformuiapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ YUI.add('ez-platformuiapp', function (Y) {
contentTypeEditServerSideView: {
type: Y.eZ.ContentTypeEditServerSideView,
},
linkViewServerSideView: {
type: Y.eZ.LinkViewServerSideView,
},
},

/**
Expand Down Expand Up @@ -978,6 +981,15 @@ YUI.add('ez-platformuiapp', function (Y) {
view: "searchView",
sideViews: {'navigationHub': true, 'discoveryBar': true},
callbacks: ['open', 'checkUser', 'handleSideViews', 'handleMainView'],
}, {
name: "viewLink",
regex: /\/admin\/(pjax%2Flink-management%2Fview%2F.*)/,
keys: ['uri'],
path: "/admin/:uri",
sideViews: {'navigationHub': true, 'discoveryBar': false},
service: Y.eZ.LinkViewServerSideViewService,
view: "linkViewServerSideView",
callbacks: ['open', 'checkUser', 'handleSideViews', 'handleMainView']
}, {
name: "adminSection",
regex: /\/admin\/(pjax%2Fsection%2F.*)/,
Expand Down
99 changes: 99 additions & 0 deletions Resources/public/js/views/serverside/ez-linkviewserversideview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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-linkviewserversideview', function (Y) {
"use strict";

/**
* Provides the link view server side view
*
* @module ez-linkviewserversideview
*/
Y.namespace('eZ');

var events = {
'.ez-view-link-usage': {
'tap': '_viewLinkUsage'
},
'.ez-edit-link-usage': {
'tap': '_editLinkUsage'
},
},
CONTENT_ID = 'data-content-id',
LANGUAGE_CODE = 'data-language-code';

/**
* The link view server side view.
*
* @namespace eZ
* @class LinkViewServerSideView
* @constructor
* @extends eZ.ServerSideView
*/
Y.eZ.LinkViewServerSideView = Y.Base.create('linkViewServerSideView', Y.eZ.ServerSideView, [], {
initializer: function () {
this._addDOMEventHandlers(events);
},

/**
* 'tap' event handler on the content view link.
*
* @method _viewLinkUsage
* @protected
* @param {EventFacade} e
*/
_viewLinkUsage: function(e) {
var contentId = e.target.getAttribute(CONTENT_ID),
languageCode = e.target.getAttribute(LANGUAGE_CODE);

e.preventDefault();
this._fireViewLinkUsage(contentId, languageCode);
},

/**
* 'tap' event handler on the content edit button.
*
* @method _viewLinkUsage
* @protected
* @param {EventFacade} e
*/
_editLinkUsage: function(e) {
var contentId = e.target.getAttribute(CONTENT_ID),
languageCode = e.target.getAttribute(LANGUAGE_CODE);

e.preventDefault();
this._fireEditLinkUsage(contentId, languageCode);
},

/**
* Fire viewLinkUsage event which redirects user to main location of content.
*
* @method _fireViewLinkUsage
* @protected
* @param {String} contentId
* @param {String} languageCode
*/
_fireViewLinkUsage: function(contentId, languageCode) {
this.fire('viewLinkUsage', {
contentId: contentId,
languageCode: languageCode
});
},

/**
* Fire editLinkUsage event which redirects user to the content edit form.
*
* @method _fireViewLinkUsage
* @protected
* @param {String} contentId
* @param {String} languageCode
*/
_fireEditLinkUsage: function(contentId, languageCode) {
this.fire('editLinkUsage', {
contentId: contentId,
languageCode: languageCode
});
}
});
});
Original file line number Diff line number Diff line change
@@ -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-linkviewserversideviewservice', function (Y) {
"use strict";

/**
* Provides the link view server side view service class
*
* @method ez-linkviewserversideviewservice
*/
Y.namespace('eZ');

/**
* The Link View Server Side View Service class.
*
* @namespace eZ
* @class LinkViewServerSideViewService
* @constructor
* @extends eZ.ServerSideViewService
*/
Y.eZ.LinkViewServerSideViewService = Y.Base.create('linkViewServerSideViewService', Y.eZ.ServerSideViewService, [], {
initializer: function () {
this.on('*:viewLinkUsage', this._handleViewLinkUsage);
this.on('*:editLinkUsage', this._handleEditLinkUsage);
},

/**
* Redirects user to the main location of content.
*
* @method _handleViewLinkUsage
* @protected
* @param {Object} e event facade
*/
_handleViewLinkUsage: function(e) {
var app = this.get('app'),
content = null;

app.set('loading', true);

content = new Y.eZ.ContentInfo({id: e.contentId});
content.load({api: this.get('capi')}, function(error, response) {
if (error) {
app.set('loading', false);
return ;
}

app.navigateTo('viewLocation', {
id: content.get('resources').MainLocation,
languageCode: e.languageCode
});
});
},

/**
* Redirects user to the content edit form
*
* @method _handleViewLinkUsage
* @protected
* @param {Object} e event facade
*/
_handleEditLinkUsage: function(e) {
var app = this.get('app');

app.navigateTo('editContent', {
id: e.contentId,
languageCode: e.languageCode
});
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ YUI.add('ez-navigationhubviewservice', function (Y) {
this.get('rootMediaLocation').get('contentInfo').get('mainLanguageCode')
),
this._getNavigationItem(
Y.eZ.trans('navigationhub.linkmanager.list', {}, 'navigationhub'), "navigationhub",
Y.eZ.trans('navigationhub.linkmanager.list', {}, 'navigationhub'),
"link-manager",
'adminGenericRoute', {uri: "pjax/link-management"}
),
];
Expand Down
11 changes: 5 additions & 6 deletions Resources/views/LinkManager/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@
</thead>
<tbody>
{% for content in usages %}
{# TODO: Should be handled by ServerSideView #}
{% set view_url = '' %}
{% set edit_url = '#/edit/' ~ (('/api/ezp/v2/content/objects/' ~ content.id) | url_encode) ~ '/' ~ content.mainLanguageCode %}

{% set content_rest_id = '/api/ezp/v2/content/objects/' ~ content.id %}
<tr>
<td>
<a href="{{ view_url }}">
<a href="#" class="ez-view-link-usage"
data-content-id="{{ content_rest_id }}" data-language-code="{{ content.mainLanguageCode }}">
{{ ez_content_name(content) }}
</a>
</td>
Expand All @@ -102,7 +100,8 @@
{% endif %}
</td>
<td>
<a href="{{ edit_url }}" class="pure-button ez-button" data-icon="&#xe606;">
<a href="#" class="ez-edit-link-usage pure-button ez-button" data-icon="&#xe606;"
data-content-id="{{ content_rest_id }}" data-language-code="{{ content.mainLanguageCode }}">
{{ 'url.usages.content.edit'|trans }}
</a>
</td>
Expand Down

0 comments on commit fbe6ddb

Please sign in to comment.