From 57498d8649a4f6ce2bffed054ec8794dfb453667 Mon Sep 17 00:00:00 2001 From: Damien Pobel Date: Mon, 18 Sep 2017 15:11:44 +0200 Subject: [PATCH] EZP-27869: Added a restore link on archived version/lang --- .../tabs/ez-locationviewversionstabview.js | 19 +++++++++ Resources/public/templates/tabs/versions.hbt | 6 ++- Resources/translations/locationview.en.xlf | 8 +++- .../ez-locationviewversionstabview-tests.js | 41 +++++++++++++++++++ .../tabs/ez-locationviewversionstabview.html | 1 + 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/Resources/public/js/views/tabs/ez-locationviewversionstabview.js b/Resources/public/js/views/tabs/ez-locationviewversionstabview.js index aef85aa47..900ba12bb 100644 --- a/Resources/public/js/views/tabs/ez-locationviewversionstabview.js +++ b/Resources/public/js/views/tabs/ez-locationviewversionstabview.js @@ -27,6 +27,9 @@ YUI.add('ez-locationviewversionstabview', function (Y) { '.ez-draft-version-checkbox': { 'change': '_setDraftButtonsState' }, + '.ez-version-in-language-restore': { + 'tap': '_restoreVersionInLanguage', + } }; /** @@ -96,6 +99,22 @@ YUI.add('ez-locationviewversionstabview', function (Y) { return versionsToDisplay; }, + /** + * Tap event handler to restore a version in a given language. + * + * @param {EventFacade} e + */ + _restoreVersionInLanguage: function (e) { + var versionNo = e.target.getAttribute('data-version'), + languageCode = e.target.getAttribute('data-version-language-code'); + + this.fire('restoreVersionInLanguage', { + content: this.get('content'), + versionNo: versionNo, + languageCode: languageCode, + }); + }, + /** * Fire the `loadVersions` event to retrieve the versions * diff --git a/Resources/public/templates/tabs/versions.hbt b/Resources/public/templates/tabs/versions.hbt index 7d170a2a1..d3d85a305 100644 --- a/Resources/public/templates/tabs/versions.hbt +++ b/Resources/public/templates/tabs/versions.hbt @@ -156,7 +156,11 @@ {{ formatTime modificationDate day="numeric" month="short" year="numeric" hour="2-digit" minute="2-digit" }} - {{languageCodes}} + {{/each}} diff --git a/Resources/translations/locationview.en.xlf b/Resources/translations/locationview.en.xlf index 177053e90..c65ce3e8d 100644 --- a/Resources/translations/locationview.en.xlf +++ b/Resources/translations/locationview.en.xlf @@ -1,6 +1,6 @@ - +
The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message. @@ -518,6 +518,12 @@ key: locationview.versions.remove.selected.archived.version Resources/public/templates/tabs/versions.hbt + + restore + restore + key: locationview.versions.restore + Resources/public/templates/tabs/versions.hbt + Version Version diff --git a/Tests/js/views/tabs/assets/ez-locationviewversionstabview-tests.js b/Tests/js/views/tabs/assets/ez-locationviewversionstabview-tests.js index 84228804a..7295eadcf 100644 --- a/Tests/js/views/tabs/assets/ez-locationviewversionstabview-tests.js +++ b/Tests/js/views/tabs/assets/ez-locationviewversionstabview-tests.js @@ -11,6 +11,7 @@ YUI.add('ez-locationviewversionstabview-tests', function (Y) { fireEditVersionEventTest, selectArchivedVersionTest, selectDeleteDraftVersionTest, + restoreVersionInLanguageTest, Assert = Y.Assert, Mock = Y.Mock, createCheckableVersionMock = function (versionId, versionNo, checked) { @@ -759,6 +760,45 @@ YUI.add('ez-locationviewversionstabview-tests', function (Y) { }, }); + restoreVersionInLanguageTest = new Y.Test.Case({ + name: "ViewVersionsTabView restore version in language test", + setUp: function () { + this.contentMock = new Mock(); + + this.view = new Y.eZ.LocationViewVersionsTabView({ + content: {}, + container: '.container', + }); + this.view.render(); + }, + + tearDown: function () { + this.view.destroy(); + delete this.view; + }, + + "Should fire the `restoreVersionInLanguage` event": function () { + var link = this.view.get('container').one('.ez-version-in-language-restore'); + + this.view.on('restoreVersionInLanguage', this.next(function (e) { + Assert.areSame( + this.view.get('content'), e.content, + "The content should be provided" + ); + Assert.areEqual( + link.getAttribute('data-version'), e.versionNo, + "The version number should be provided" + ); + Assert.areEqual( + link.getAttribute('data-version-language-code'), e.languageCode, + "The language code should be provided" + ); + }, this)); + link.simulateGesture('tap'); + this.wait(); + }, + }); + Y.Test.Runner.setName("eZ Location View Versions Tab View tests"); Y.Test.Runner.add(attributesTest); Y.Test.Runner.add(renderTest); @@ -768,4 +808,5 @@ YUI.add('ez-locationviewversionstabview-tests', function (Y) { Y.Test.Runner.add(selectDeleteDraftVersionTest); Y.Test.Runner.add(fireDeleteVersionEventTest); Y.Test.Runner.add(fireEditVersionEventTest); + Y.Test.Runner.add(restoreVersionInLanguageTest); }, '', {requires: ['test', 'ez-locationviewversionstabview', 'node-event-simulate']}); diff --git a/Tests/js/views/tabs/ez-locationviewversionstabview.html b/Tests/js/views/tabs/ez-locationviewversionstabview.html index 88e17c0b5..af90c43a3 100644 --- a/Tests/js/views/tabs/ez-locationviewversionstabview.html +++ b/Tests/js/views/tabs/ez-locationviewversionstabview.html @@ -43,6 +43,7 @@ {{/each}} + restore