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

Commit

Permalink
EZP-27869: Added a restore link on archived version/lang
Browse files Browse the repository at this point in the history
  • Loading branch information
dpobel committed Sep 18, 2017
1 parent ef96fd3 commit 57498d8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Resources/public/js/views/tabs/ez-locationviewversionstabview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ YUI.add('ez-locationviewversionstabview', function (Y) {
'.ez-draft-version-checkbox': {
'change': '_setDraftButtonsState'
},
'.ez-version-in-language-restore': {
'tap': '_restoreVersionInLanguage',
}
};

/**
Expand Down Expand Up @@ -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
*
Expand Down
6 changes: 5 additions & 1 deletion Resources/public/templates/tabs/versions.hbt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@
{{ formatTime modificationDate day="numeric" month="short" year="numeric" hour="2-digit" minute="2-digit" }}
</td>
<td>
{{languageCodes}}
<ul class="ez-version-language-list">
{{#each languageCodeList}}
<li>{{.}} (<a href="#" class="ez-version-in-language-restore" data-version="{{ ../versionNo }}" data-version-language-code="{{ . }}">{{ translate 'locationview.versions.restore' 'locationview' }}</a>)</li>
{{/each}}
</ul>
</td>
</tr>
{{/each}}
Expand Down
8 changes: 7 additions & 1 deletion Resources/translations/locationview.en.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2017-03-09T16:35:22Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<file date="2017-09-18T15:09:42Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>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.</note>
Expand Down Expand Up @@ -518,6 +518,12 @@
<note>key: locationview.versions.remove.selected.archived.version</note>
<jms:reference-file>Resources/public/templates/tabs/versions.hbt</jms:reference-file>
</trans-unit>
<trans-unit id="375d6b33f75515f798fc72ae01d58a73dbb8bd15" resname="locationview.versions.restore">
<source>restore</source>
<target>restore</target>
<note>key: locationview.versions.restore</note>
<jms:reference-file>Resources/public/templates/tabs/versions.hbt</jms:reference-file>
</trans-unit>
<trans-unit id="199990450f06a84725d61f91a899166d0d3305c4" resname="locationview.versions.version">
<source>Version</source>
<target>Version</target>
Expand Down
41 changes: 41 additions & 0 deletions Tests/js/views/tabs/assets/ez-locationviewversionstabview-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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']});
1 change: 1 addition & 0 deletions Tests/js/views/tabs/ez-locationviewversionstabview.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
{{/each}}
</div>

<a href="#" class="ez-version-in-language-restore" data-version="42" data-version-language-code="fre-FR">restore</a>
</script>

<script type="text/javascript" src="../../../../Resources/public/vendors/yui3/build/yui/yui.js"></script>
Expand Down

0 comments on commit 57498d8

Please sign in to comment.