From 73008199091a68be4f6380d0b4164efea1033526 Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Tue, 23 Aug 2016 14:04:15 +0200 Subject: [PATCH 1/4] EZS-851: Can't edit old content versions using the eZ Studio interface --- Resources/config/yui.yml | 2 + Resources/public/js/views/ezs-browserview.js | 17 +- .../js/views/popups/ezs-versionspopupview.js | 9 +- .../js/views/services/ezs-browserviewservice.js | 51 +++++- Tests/js/apps/plugins/ezs-browserplugin.html | 15 +- Tests/js/views/assets/ezs-browserview-tests.js | 18 ++- .../assets/ezs-browserviewservice-tests.js | 180 ++++++++++++++++++++- .../js/views/services/ezs-browserviewservice.html | 18 ++- 8 files changed, 282 insertions(+), 28 deletions(-) diff --git a/Resources/config/yui.yml b/Resources/config/yui.yml index 1903dd5..2ccbe87 100644 --- a/Resources/config/yui.yml +++ b/Resources/config/yui.yml @@ -143,6 +143,8 @@ system: - 'ez-contentmodel' - 'ez-contenttypemodel' - 'ez-versionmodel' + - 'ez-versionsplugin' + - 'ez-pluginregistry' - 'ezs-versionmodellist' - 'ezs-errorhandler' - 'io-base' diff --git a/Resources/public/js/views/ezs-browserview.js b/Resources/public/js/views/ezs-browserview.js index 667d788..52f2756 100644 --- a/Resources/public/js/views/ezs-browserview.js +++ b/Resources/public/js/views/ezs-browserview.js @@ -98,20 +98,29 @@ YUI.add('ezs-browserview', function (Y) { * @method _checkHasLandingPageFieldType */ _checkHasLandingPageFieldType: function () { + var status = this.get('previewedVersion').get('status'); + this._toggleLoadingOverlay(null, true); if (!this.get('hasLandingPageFieldType')) { /** * Fired when a user clicks on "Edit" button in the top action bar. - * It is listened by the browserViewService. Redirects a user to the Content Editor or Landing Page Editor view of PlatformUI + * Redirects a user to the Version Editor of PlatformUI. + * It is listened by the Y.eZS.BrowserViewService. * - * @event editContent + * @event editVersion + * @param versionId {String} version id + * @param status {String} status of the version */ - this.fire('editContent'); + this.fire('editVersion', { + versionId: this.get('previewedVersion').get('id'), + status: status + }); } else { /** * Fired when a user clicks on "Edit" button in the top action bar. - * It is listened by the browserViewService. Redirects a user to the Content Editor or Landing Page Editor view of PlatformUI + * Redirects a user to the Landing Page Editor view. + * It is listened by the Y.eZS.BrowserViewService. * * @event editLandingPage */ diff --git a/Resources/public/js/views/popups/ezs-versionspopupview.js b/Resources/public/js/views/popups/ezs-versionspopupview.js index 86ed016..6cc4560 100644 --- a/Resources/public/js/views/popups/ezs-versionspopupview.js +++ b/Resources/public/js/views/popups/ezs-versionspopupview.js @@ -546,7 +546,9 @@ YUI.add('ezs-versionspopupview', function (Y) { * @param versionId {String} version id */ _editVersion: function (versionId) { - this.set('previewedContent', this._findVersion(versionId)); + var previewedContent = this._findVersion(versionId); + + this.set('previewedContent', previewedContent); this.set('displayed', false); this._showLoadingScreen(); /** @@ -555,8 +557,11 @@ YUI.add('ezs-versionspopupview', function (Y) { * * @event editVersion * @param versionId {String} version REST id + * @param status {String} status of the version */ - this.fire('editVersion', {versionId: versionId}); + this.fire('editVersion', { + versionId: versionId, + status: previewedContent.get('status')}); }, /** diff --git a/Resources/public/js/views/services/ezs-browserviewservice.js b/Resources/public/js/views/services/ezs-browserviewservice.js index 018b35d..3b5c679 100644 --- a/Resources/public/js/views/services/ezs-browserviewservice.js +++ b/Resources/public/js/views/services/ezs-browserviewservice.js @@ -15,8 +15,15 @@ YUI.add('ezs-browserviewservice', function (Y) { BLOCK_TYPE_SCHEDULE = 'schedule', INSITE_URL_HASH = '#/studio/insite/', IFRAME_LOADED_PREFIX = 'iframe-loaded-', + VERSION_STATUS_PUBLISHED = 'published', + VERSION_STATUS_ARCHIVED = 'archived', + VERSION_STATUS_DRAFT = 'draft', SLASH = '/'; + Y.eZ.PluginRegistry.registerPlugin( + Y.eZ.Plugin.Versions, ['browserViewService'] + ); + /** * The StudioUI browser view service * @@ -27,12 +34,11 @@ YUI.add('ezs-browserviewservice', function (Y) { */ Y.eZS.BrowserViewService = Y.Base.create('browserViewService', Y.eZ.ViewService, [Y.eZS.ErrorHandler], { initializer: function () { - this.on('*:editContent', this._redirectToContentEdit, this); this.on('*:editLandingPage', this._redirectToLandingPageEdit, this); this.on('*:iframePreviewLoad', this._handlerIframePreviewLoad, this); this.on('*:renderPreview', this._getPreview, this); this.on('*:previewVersion', this._loadPreviewVersionData, this); - this.on('*:editVersion', this._redirectToLandingPageVersionEdit, this); + this.on('*:editVersion', this._redirectToVersionEdit, this); this.on('*:versionPreviewEnabledChange', this._toggleFetchingIframePreviewData, this); }, @@ -85,14 +91,20 @@ YUI.add('ezs-browserviewservice', function (Y) { }, /** - * Redirects a user to the landing page editor to edit a selected version + * Redirects a user to edit a selected version * - * @method _redirectToLandingPageVersionEdit + * @method _redirectToVersionEdit * @protected * @param event {Object} event facade * @param event.versionId {String} version REST id + * @param event.status {String} status of the version */ - _redirectToLandingPageVersionEdit: function (event) { + _redirectToVersionEdit: function (event) { + var app = this.get('app'), + siteaccessesConfig = app.get('config.studioSiteaccesses'), + activeSiteaccess = app.get('studioActiveSiteaccess'), + status = event.status.toLowerCase(); + if (!event.versionId) { /** * Displays a loading screen @@ -106,9 +118,36 @@ YUI.add('ezs-browserviewservice', function (Y) { return; } + if (!this.get('hasLandingPageFieldType') && status === VERSION_STATUS_PUBLISHED) { + this._redirectToContentEdit(); + + return; + } + this._loadPreviewVersionData({versionId: event.versionId}) .then(Y.bind(function () { - this.get('app').navigateTo('dynamicLandingPageEditor', {url: this.get('previewUrl')}); + if (!this.get('hasLandingPageFieldType') && status === VERSION_STATUS_ARCHIVED) { + /** + * Creates draft from archived version and redirect user to edit content + * + * @event createDraft + * @param content {eZ.Content} content + * @param versionNo {String} versionNo of the archived version. Ex: 42 + */ + this.fire('createDraft', { + content: this.get('content'), + versionNo: this.get('version').get('versionNo'), + }); + } else if (!this.get('hasLandingPageFieldType') && status === VERSION_STATUS_DRAFT) { + app.navigateTo('editContentVersion', { + id: this.get('content').get('id'), + languageCode: siteaccessesConfig[activeSiteaccess].languages[0], + versionId: event.versionId + }); + } else { + app.navigateTo('dynamicLandingPageEditor', {url: this.get('previewUrl')}); + } + }, this)); }, diff --git a/Tests/js/apps/plugins/ezs-browserplugin.html b/Tests/js/apps/plugins/ezs-browserplugin.html index 7e9204a..5b87946 100644 --- a/Tests/js/apps/plugins/ezs-browserplugin.html +++ b/Tests/js/apps/plugins/ezs-browserplugin.html @@ -44,9 +44,22 @@ fullpath: '../../../../vendor/ezsystems/platform-ui-bundle/Resources/public/js/extensions/ez-height-fit.js' }, 'ezs-browserviewservice': { - requires: ['ez-viewservice', 'io-base', 'promise', 'ez-locationmodel', 'ez-contentcreateplugin', 'ezs-errorhandler'], + requires: [ + 'ez-viewservice', + 'ez-versionsplugin', + 'ez-pluginregistry', + 'io-base', + 'promise', + 'ez-locationmodel', + 'ez-contentcreateplugin', + 'ezs-errorhandler' + ], fullpath: '../../../../Resources/public/js/views/services/ezs-browserviewservice.js' }, + 'ez-versionsplugin': { + requires: ['ez-viewservicebaseplugin', 'ez-pluginregistry'], + fullpath: '../../../../vendor/ezsystems/platform-ui-bundle/Resources/public/js/views/services/plugins/ez-versionsplugin.js' + }, 'ezs-errorhandler': { requires: ['base', 'ezs-loadingscreentoggler'], fullpath: '../../../../Resources/public/js/helpers/ezs-errorhandler.js' diff --git a/Tests/js/views/assets/ezs-browserview-tests.js b/Tests/js/views/assets/ezs-browserview-tests.js index 5cffbed..28a50d0 100644 --- a/Tests/js/views/assets/ezs-browserview-tests.js +++ b/Tests/js/views/assets/ezs-browserview-tests.js @@ -7,7 +7,8 @@ YUI.add('ezs-browserview-tests', function (Y) { eventsTest, SCHEDULE_BLOCK_ID = 'b-5d5a0808-bd49-0e85-650c-c915e73b51cd', SELECTOR_APP_TIMELINE = '.ezs-appview__workspace__timeline', - SELECTOR_APP_PREVIEW = '.ezs-appview__workspace__preview'; + SELECTOR_APP_PREVIEW = '.ezs-appview__workspace__preview', + VERSION_STATUS_DRAFT = 'DRAFT'; Y.eZS.TimelineView = Y.View; @@ -143,22 +144,27 @@ YUI.add('ezs-browserview-tests', function (Y) { view.fire('editAction'); }, - 'Should navigate to content edit when user is on non-pagefieldtype page': function () { + 'Should navigate to version edit when user is on non-pagefieldtype page': function () { var view = this.view, isEventFired = false, - previewContentId = 'test'; + expectedPreviewedVersionId = 'test', + previewedVersion = view.get('previewedVersion'); view.set('hasLandingPageFieldType', false); - view.set('previewContentId', previewContentId); + previewedVersion.set('id', expectedPreviewedVersionId); + previewedVersion.set('status', VERSION_STATUS_DRAFT); view = view.render(); - view.on('editContent', function (event) { + view.on('editVersion', function (event) { isEventFired = true; + + Y.Assert.areSame(expectedPreviewedVersionId, event.versionId, 'Should pass correct version id'); + Y.Assert.areSame(VERSION_STATUS_DRAFT, event.status, 'Should pass correct version status'); }); view.fire('editAction'); - Y.Assert.isTrue(isEventFired, 'The `editContent` event should be fired'); + Y.Assert.isTrue(isEventFired, 'The `editVersion` event should be fired'); }, 'Should set up view properties correctly when iframe content is loaded': function () { diff --git a/Tests/js/views/services/assets/ezs-browserviewservice-tests.js b/Tests/js/views/services/assets/ezs-browserviewservice-tests.js index 02a879c..ab72ace 100644 --- a/Tests/js/views/services/assets/ezs-browserviewservice-tests.js +++ b/Tests/js/views/services/assets/ezs-browserviewservice-tests.js @@ -16,6 +16,9 @@ YUI.add('ezs-browserviewservice-tests', function (Y) { LANDING_PAGE_DATA = "{\"page\":{\"layout\":\"1\",\"title\":\"Home\",\"zones\":[{\"id\":\"first\",\"name\":\"First zone\",\"blocks\":[{\"id\":\"b-5d5a0808-bd49-0e85-650c-c915e73b51cd\",\"type\":\"schedule\",\"name\":\"Main Story\",\"view\":\"schedule_hero\",\"ttl\":\"0\",\"attributes\":{\"queue\":[{\"contentId\":73,\"airtime\":\"1453734840\",\"name\":\"Santo Domingo, Dominican Republic\"},{\"contentId\":71,\"airtime\":\"1453718520\",\"name\":\"Valencia, Spain\"},{\"contentId\":72,\"airtime\":\"1453716060\",\"name\":\"Kochin, India\"},{\"contentId\":77,\"airtime\":\"1453375380\",\"name\":\"Ethiopian Cuisine\"},{\"contentId\":62,\"airtime\":\"1453268040\",\"name\":\"Mexican Cuisine\"}],\"validItems\":[{\"contentId\":68,\"airtime\":\"1453142340\",\"name\":\"Why we love NYC\"}],\"history\":[{\"contentId\":65,\"airtime\":\"1453124760\",\"name\":\"Where we get our best writing done\"},{\"contentId\":75,\"airtime\":\"1441887589\",\"name\":\"Brooklyn, New York\"}],\"slots\":1}},{\"id\":\"b-83fc6e49-d87f-9387-e4e1-b0951a3d9055\",\"type\":\"schedule\",\"name\":\"Editorial teasers\",\"view\":\"schedule_grid\",\"ttl\":\"0\",\"attributes\":{\"queue\":[],\"validItems\":[{\"contentId\":72,\"airtime\":\"1441887643\",\"name\":\"Kochin, India\"},{\"contentId\":74,\"airtime\":\"1441887620\",\"name\":\"Anchorage, Alaska\"},{\"contentId\":62,\"airtime\":\"1441705522\",\"name\":\"Mexican Cuisine\"},{\"contentId\":68,\"airtime\":\"1441705511\",\"name\":\"Why we love NYC\"},{\"contentId\":73,\"airtime\":\"1441705508\",\"name\":\"Santo Domingo, Dominican Republic\"},{\"contentId\":71,\"airtime\":\"1441705507\",\"name\":\"Valencia, Spain\"},{\"contentId\":79,\"airtime\":\"1441705500\",\"name\":\"Israeli Cuisine\"}],\"history\":[],\"slots\":8}},{\"id\":\"b-294fbffd-744a-6ac6-3f29-9783799c10f6\",\"type\":\"banner\",\"name\":\"Banner Block\",\"view\":\"banner_container\",\"ttl\":\"0\",\"attributes\":{\"contentId\":\"83\",\"url\":\"http:\\/\\/ez.no\"}},{\"id\":\"b-96ba244b-c72d-740d-0ccd-fdcec4e23af4\",\"type\":\"embed\",\"name\":\"Embed Block\",\"view\":\"embed\",\"ttl\":\"0\",\"attributes\":{\"contentId\":\"84\"}},{\"id\":\"b-b27742d1-628f-0c8c-a48b-0b1dd0d7e5f9\",\"type\":\"gallery\",\"name\":\"Gallery Block\",\"view\":\"gallery\",\"ttl\":\"0\",\"attributes\":{\"contentId\":\"85\"}},{\"id\":\"b-bf850b3f-e770-6e8f-46d0-ceff8d0c94f4\",\"type\":\"embed\",\"name\":\"Embed Block\",\"view\":\"embed\",\"ttl\":\"0\",\"attributes\":{\"contentId\":\"90\"}},{\"id\":\"b-b3a66965-cec8-8c27-bb5c-a773e26bad3a\",\"type\":\"places\",\"name\":\"Places Block\",\"view\":\"map\",\"ttl\":\"0\",\"attributes\":{\"contentId\":\"70\"}}]}]}}", // jshint ignore:line LANDING_PAGE_VERSIONS = "[{\"Version\":{\"_href\":\"/api/ezp/v2/content/objects/94/versions/14\"},\"VersionInfo\":{\"id\":655,\"versionNo\":14,\"status\":\"ARCHIVED\",\"modificationDate\":\"2016-04-06T14:55:42+02:00\",\"Creator\":{\"_href\":\"/api/ezp/v2/user/users/14\"},\"creationDate\":\"2015-10-02T23:20:43+02:00\",\"initialLanguageCode\":\"eng-GB\",\"languageCodes\":\"eng-GB\",\"names\":{\"value\":[{\"_languageCode\":\"eng-GB\",\"#text\":\"Places & Tastes\"}]},\"Content\":{\"_href\":\"/api/ezp/v2/content/objects/94\"}}},{\"Version\":{\"_href\":\"/api/ezp/v2/content/objects/94/versions/15\"},\"VersionInfo\":{\"id\":681,\"versionNo\":15,\"status\":\"PUBLISHED\",\"modificationDate\":\"2016-04-06T14:55:42+02:00\",\"Creator\":{\"_href\":\"/api/ezp/v2/user/users/105\"},\"creationDate\":\"2016-04-06T14:55:41+02:00\",\"initialLanguageCode\":\"eng-GB\",\"languageCodes\":\"eng-GB\",\"names\":{\"value\":[{\"_languageCode\":\"eng-GB\",\"#text\":\"Places & Tastes\"}]},\"Content\":{\"_href\":\"/api/ezp/v2/content/objects/94\"}}}]", //jshint ignore:line PREFIX_AJAX_GET = 'Tests/js/views/services/echo/get/json/?response=', + VERSION_STATUS_PUBLISHED = 'published', + VERSION_STATUS_ARCHIVED = 'archived', + VERSION_STATUS_DRAFT = 'draft', revertTestUrl = function () { window.history.pushState( '', @@ -477,7 +480,8 @@ YUI.add('ezs-browserviewservice-tests', function (Y) { }, 'Should redirect a user to the content edit view': function () { - var contentId = '/api/ezp/v2/content/objects/57'; + var contentId = '/api/ezp/v2/content/objects/57', + versionId = '/api/ezp/v2/content/objects/57/version/1'; Y.Mock.expect(this.app, { method: 'navigateTo', @@ -500,11 +504,11 @@ YUI.add('ezs-browserviewservice-tests', function (Y) { return properties[paramName] || Y.fail('Unexpected app\'s property is used: ' + paramName); }, - callCount: 2 + callCount: 4 }); this.service.get('content').set('id', contentId); - this.service.fire('editContent'); + this.service.fire('editVersion', {versionId: versionId, status: VERSION_STATUS_PUBLISHED}); Y.Mock.verify(this.app); }, @@ -547,12 +551,82 @@ YUI.add('ezs-browserviewservice-tests', function (Y) { this.resume(function () { Y.Assert.areEqual(previewUrl, params.url, 'The url info should passed correctly'); + Y.Assert.isTrue(isIdUpdated, 'The version model ID should be updated'); + Y.Assert.isTrue(isModelLoaded, 'Should load model data'); + + Y.Mock.verify(this.app); + return previewUrl; }); }, this) }); + Y.Mock.expect(this.app, { + method: 'get', + args: [Y.Mock.Value.String], + run: function (paramName) { + var properties = Y.merge(APP_ATTRS, {'studioActiveSiteaccess': 'site'}); + + return properties[paramName] || Y.fail('Unexpected app\'s property is used: ' + paramName); + }, + callCount: 2 + }); + service.set('previewUrl', previewUrl); + service.set('hasLandingPageFieldType', true); + view.addTarget(service); + + versionModel.on('idChange', function (event) { + isIdUpdated = true; + }); + + versionModel.load = function (config, callback) { + isModelLoaded = true; + callback(); + }; + + view.fire('editVersion', {versionId: versionId, status: VERSION_STATUS_PUBLISHED}); + this.wait(); + }, + + 'Should redirect a user to the version edit view when version has status draft': function () { + var service = this.service, + previewUrl = 'west/ham/anthem', + versionId = 'bubbles/in/the/air', + view = new Y.View(), + versionModel = service.get('version'), + isIdUpdated = false, + isModelLoaded = false; + + Y.Mock.expect(this.app, { + method: 'navigateTo', + args: ['editContentVersion', Y.Mock.Value.Object], + run: Y.bind(function (route, params) { + this.resume(function () { + + + Y.Assert.isTrue(isIdUpdated, 'The version model ID should be updated'); + Y.Assert.isTrue(isModelLoaded, 'Should load model data'); + + Y.Mock.verify(this.app); + + return previewUrl; + }); + }, this) + }); + + Y.Mock.expect(this.app, { + method: 'get', + args: [Y.Mock.Value.String], + run: function (paramName) { + var properties = Y.merge(APP_ATTRS, {'studioActiveSiteaccess': 'site'}); + + return properties[paramName] || Y.fail('Unexpected app\'s property is used: ' + paramName); + }, + callCount: 2 + }); + + service.set('hasLandingPageFieldType', false); view.addTarget(service); versionModel.on('idChange', function (event) { @@ -564,15 +638,96 @@ YUI.add('ezs-browserviewservice-tests', function (Y) { callback(); }; - view.fire('editVersion', {versionId: versionId}); + view.fire('editVersion', {versionId: versionId, status: VERSION_STATUS_DRAFT}); this.wait(); + }, - Y.Assert.isTrue(isIdUpdated, 'The version model ID should be updated'); - Y.Assert.isTrue(isModelLoaded, 'Should load model data'); + 'Should redirect a user to the content edit view when version has status published': function () { + var service = this.service, + contentId = '/api/ezp/v2/content/objects/57', + versionId = '/api/ezp/v2/content/objects/57/version/1'; + + Y.Mock.expect(this.app, { + method: 'navigateTo', + args: ['editContent', Y.Mock.Value.Object], + run: function (route, params) { + Y.Assert.areSame( + contentId, + params.id, + 'Content ID should be passed correctly' + ); + return contentId; + } + }); + + Y.Mock.expect(this.app, { + method: 'get', + args: [Y.Mock.Value.String], + run: function (paramName) { + var properties = Y.merge(APP_ATTRS, {'studioActiveSiteaccess': 'site'}); + + return properties[paramName] || Y.fail('Unexpected app\'s property is used: ' + paramName); + }, + callCount: 4 + }); + + service.get('content').set('id', contentId); + service.set('hasLandingPageFieldType', false); + + service.fire('editVersion', {versionId: versionId, status: VERSION_STATUS_PUBLISHED}); Y.Mock.verify(this.app); }, + 'Should create new draft when user edit archived version': function () { + var service = this.service, + versionId = 'bubbles/in/the/air', + view = new Y.View(), + versionModel = service.get('version'), + expectedVersionNo = 5, + isIdUpdated = false, + isModelLoaded = false; + + Y.Mock.expect(this.app, { + method: 'get', + args: [Y.Mock.Value.String], + run: function (paramName) { + var properties = Y.merge(APP_ATTRS, {'studioActiveSiteaccess': 'site'}); + + return properties[paramName] || Y.fail('Unexpected app\'s property is used: ' + paramName); + }, + callCount: 2 + }); + + service.set('hasLandingPageFieldType', false); + versionModel.set('versionNo', expectedVersionNo); + view.addTarget(service); + + service.on('createDraft', Y.bind(function (event) { + this.resume(function () { + Y.Assert.areSame(service.get('content'), event.content, 'Should pass correct content model'); + Y.Assert.areSame(expectedVersionNo, event.versionNo, 'Should pass correct version number'); + + Y.Assert.isTrue(isIdUpdated, 'The version model ID should be updated'); + Y.Assert.isTrue(isModelLoaded, 'Should load model data'); + + Y.Mock.verify(this.app); + }); + }, this)); + + versionModel.on('idChange', function (event) { + isIdUpdated = true; + }); + + versionModel.load = function (config, callback) { + isModelLoaded = true; + callback(); + }; + + view.fire('editVersion', {versionId: versionId, status: VERSION_STATUS_ARCHIVED}); + this.wait(); + }, + 'Should not redirect a user to the landing page version edit view when version ID is missing': function () { var service = this.service, previewUrl = 'west/ham/anthem', @@ -581,6 +736,17 @@ YUI.add('ezs-browserviewservice-tests', function (Y) { isIdUpdated = false, isModelLoaded = false; + Y.Mock.expect(this.app, { + method: 'get', + args: [Y.Mock.Value.String], + run: function (paramName) { + var properties = Y.merge(APP_ATTRS, {'studioActiveSiteaccess': 'site'}); + + return properties[paramName] || Y.fail('Unexpected app\'s property is used: ' + paramName); + }, + callCount: 2 + }); + service.set('previewUrl', previewUrl); view.addTarget(service); @@ -593,7 +759,7 @@ YUI.add('ezs-browserviewservice-tests', function (Y) { callback(); }; - view.fire('editVersion'); + view.fire('editVersion', {status: VERSION_STATUS_PUBLISHED}); Y.Assert.isFalse(isIdUpdated, 'The version model ID should not be updated'); Y.Assert.isFalse(isModelLoaded, 'Should not load model data'); diff --git a/Tests/js/views/services/ezs-browserviewservice.html b/Tests/js/views/services/ezs-browserviewservice.html index 17da3f9..bf6831e 100644 --- a/Tests/js/views/services/ezs-browserviewservice.html +++ b/Tests/js/views/services/ezs-browserviewservice.html @@ -24,7 +24,9 @@ 'ez-viewservice', 'ezs-errorhandler', 'io-base', - 'promise' + 'promise', + 'ez-versionsplugin', + 'ez-pluginregistry' ], fullpath: '../../../../Resources/public/js/views/services/ezs-browserviewservice.js' }, @@ -36,10 +38,22 @@ requires: ['base'], fullpath: '../../../../Resources/public/js/helpers/ezs-loadingscreentoggler.js' }, + 'ez-versionsplugin': { + requires: ['ez-viewservicebaseplugin', 'ez-pluginregistry'], + fullpath: '../../../../vendor/ezsystems/platform-ui-bundle/Resources/public/js/views/services/plugins/ez-versionsplugin.js' + }, + 'ez-viewservicebaseplugin': { + requires: ['base', 'plugin'], + fullpath: '../../../../vendor/ezsystems/platform-ui-bundle/Resources/public/js/views/services/plugins/ez-viewservicebaseplugin.js' + }, 'ez-viewservice': { requires: ['base', 'parallel'], fullpath: '../../../../vendor/ezsystems/platform-ui-bundle/Resources/public/js/views/services/ez-viewservice.js' - } + }, + 'ez-pluginregistry': { + requires: ['array-extras'], + fullpath: '../../../../../vendor/ezsystems/platform-ui-bundle/Resources/public/js/services/ez-pluginregistry.js' + }, } }).use('ezs-browserviewservice-tests', function (Y) { Y.Test.Runner.run(); From 4c092c94cba782c43423afaef300ca9a4d92392f Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Thu, 25 Aug 2016 10:00:08 +0200 Subject: [PATCH 2/4] change event name bacause Platform use the same event --- Resources/public/js/views/ezs-browserview.js | 4 ++-- Resources/public/js/views/popups/ezs-versionspopupview.js | 7 ++++--- Resources/public/js/views/services/ezs-browserviewservice.js | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Resources/public/js/views/ezs-browserview.js b/Resources/public/js/views/ezs-browserview.js index 52f2756..80a1610 100644 --- a/Resources/public/js/views/ezs-browserview.js +++ b/Resources/public/js/views/ezs-browserview.js @@ -108,11 +108,11 @@ YUI.add('ezs-browserview', function (Y) { * Redirects a user to the Version Editor of PlatformUI. * It is listened by the Y.eZS.BrowserViewService. * - * @event editVersion + * @event studioEditVersion * @param versionId {String} version id * @param status {String} status of the version */ - this.fire('editVersion', { + this.fire('studioEditVersion', { versionId: this.get('previewedVersion').get('id'), status: status }); diff --git a/Resources/public/js/views/popups/ezs-versionspopupview.js b/Resources/public/js/views/popups/ezs-versionspopupview.js index 6cc4560..15aee93 100644 --- a/Resources/public/js/views/popups/ezs-versionspopupview.js +++ b/Resources/public/js/views/popups/ezs-versionspopupview.js @@ -555,13 +555,14 @@ YUI.add('ezs-versionspopupview', function (Y) { * Notifies a service about selected content version to edit it. * Listened by Y.eZS.BrowserViewService * - * @event editVersion + * @event studioEditVersion * @param versionId {String} version REST id * @param status {String} status of the version */ - this.fire('editVersion', { + this.fire('studioEditVersion', { versionId: versionId, - status: previewedContent.get('status')}); + status: previewedContent.get('status') + }); }, /** diff --git a/Resources/public/js/views/services/ezs-browserviewservice.js b/Resources/public/js/views/services/ezs-browserviewservice.js index 3b5c679..5e3fd6b 100644 --- a/Resources/public/js/views/services/ezs-browserviewservice.js +++ b/Resources/public/js/views/services/ezs-browserviewservice.js @@ -38,7 +38,7 @@ YUI.add('ezs-browserviewservice', function (Y) { this.on('*:iframePreviewLoad', this._handlerIframePreviewLoad, this); this.on('*:renderPreview', this._getPreview, this); this.on('*:previewVersion', this._loadPreviewVersionData, this); - this.on('*:editVersion', this._redirectToVersionEdit, this); + this.on('*:studioEditVersion', this._redirectToVersionEdit, this); this.on('*:versionPreviewEnabledChange', this._toggleFetchingIframePreviewData, this); }, From ebb213396c668959522d12a7b59a001604e052c0 Mon Sep 17 00:00:00 2001 From: Piotr Nalepa Date: Fri, 26 Aug 2016 15:18:14 +0200 Subject: [PATCH 3/4] Fixed the issue with removing content on discard draft --- Resources/public/js/views/ezs-browserview.js | 21 +++++++++++++++++++++ .../js/views/services/ezs-browserviewservice.js | 13 ------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Resources/public/js/views/ezs-browserview.js b/Resources/public/js/views/ezs-browserview.js index 80a1610..ec7b34d 100644 --- a/Resources/public/js/views/ezs-browserview.js +++ b/Resources/public/js/views/ezs-browserview.js @@ -44,6 +44,7 @@ YUI.add('ezs-browserview', function (Y) { var previewedVersion = this.get('previewedVersion'); + this.before('*:editVersion', this._detachPreviewVersionLoadHandler, this); this.on('previewContentInfoChange', this._updateInformationPanel, this); this.on('timelineDataChange', this._updateTimelineIndicators, this); this.on('hasLandingPageFieldTypeChange', this._toggleTimeline, this); @@ -65,6 +66,26 @@ YUI.add('ezs-browserview', function (Y) { return this; }, + _detachPreviewVersionLoadHandler: function (event) { + if (!event.versionId) { + /** + * Displays a loading screen + * It is listened by the {eZS.Plugin.LoadingSwitcher}. + * + * @event toggleLoadingOverlay + * @param show {Boolean} should the loading screen be displayed? + */ + this.fire('toggleLoadingOverlay', {show: false}); + + event.stopPropagation(); + event.preventDefault(); + + return; + } + + this.get('previewedVersion').detach('load', this._updateVersionPreview, this); + }, + /** * Updates the timeline indicators with new data. * diff --git a/Resources/public/js/views/services/ezs-browserviewservice.js b/Resources/public/js/views/services/ezs-browserviewservice.js index 5e3fd6b..4b5fb89 100644 --- a/Resources/public/js/views/services/ezs-browserviewservice.js +++ b/Resources/public/js/views/services/ezs-browserviewservice.js @@ -105,19 +105,6 @@ YUI.add('ezs-browserviewservice', function (Y) { activeSiteaccess = app.get('studioActiveSiteaccess'), status = event.status.toLowerCase(); - if (!event.versionId) { - /** - * Displays a loading screen - * It is listened by the {eZS.Plugin.LoadingSwitcher}. - * - * @event toggleLoadingOverlay - * @param show {Boolean} should the loading screen be displayed? - */ - this.fire('toggleLoadingOverlay', {show: false}); - - return; - } - if (!this.get('hasLandingPageFieldType') && status === VERSION_STATUS_PUBLISHED) { this._redirectToContentEdit(); From 0ac344bf56a8d56cb180cf33802ed18c903f132d Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Fri, 26 Aug 2016 15:25:33 +0200 Subject: [PATCH 4/4] fix event name --- Resources/public/js/views/ezs-browserview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/public/js/views/ezs-browserview.js b/Resources/public/js/views/ezs-browserview.js index ec7b34d..260df5e 100644 --- a/Resources/public/js/views/ezs-browserview.js +++ b/Resources/public/js/views/ezs-browserview.js @@ -44,7 +44,7 @@ YUI.add('ezs-browserview', function (Y) { var previewedVersion = this.get('previewedVersion'); - this.before('*:editVersion', this._detachPreviewVersionLoadHandler, this); + this.before('*:studioEditVersion', this._detachPreviewVersionLoadHandler, this); this.on('previewContentInfoChange', this._updateInformationPanel, this); this.on('timelineDataChange', this._updateTimelineIndicators, this); this.on('hasLandingPageFieldTypeChange', this._toggleTimeline, this);