diff --git a/Resources/public/js/models/ez-versioninfomodel.js b/Resources/public/js/models/ez-versioninfomodel.js index aff41b702..d1e05d596 100644 --- a/Resources/public/js/models/ez-versioninfomodel.js +++ b/Resources/public/js/models/ez-versioninfomodel.js @@ -21,8 +21,6 @@ YUI.add('ez-versioninfomodel', function (Y) { * @extends eZ.RestModel */ Y.eZ.VersionInfo = Y.Base.create('versionInfoModel', Y.eZ.RestModel, [], { - - /** * sync implementation for the VersionInfo. For now, it supports deleting it. * @@ -202,6 +200,23 @@ YUI.add('ez-versioninfomodel', function (Y) { value: "" }, + /** + * The language code list. + * + * @readOnly + * @attribute languageCodeList + * @type Array + */ + languageCodeList: { + readOnly: true, + getter: function () { + if ( this.get('languageCodes') ) { + return this.get('languageCodes').split(','); + } + return []; + } + }, + /** * The initial language code * diff --git a/Resources/public/js/views/services/plugins/ez-versionsplugin.js b/Resources/public/js/views/services/plugins/ez-versionsplugin.js index d05f5dfe5..905e40196 100644 --- a/Resources/public/js/views/services/plugins/ez-versionsplugin.js +++ b/Resources/public/js/views/services/plugins/ez-versionsplugin.js @@ -38,6 +38,11 @@ YUI.add('ez-versionsplugin', function (Y) { this.onHostEvent('*:createDraft', this._createDraftFromArchivedVersion); this.onHostEvent('*:deleteVersion', this._confirmDeleteVersion); this.onHostEvent('*:editVersion', this._redirectToEditVersion); + this.onHostEvent('*:restoreVersionInLanguage', this._restoreVersionInLanguage); + }, + + _restoreVersionInLanguage: function (e) { + console.log('No API yet to do that', e); }, /** diff --git a/Resources/public/js/views/tabs/ez-locationviewversionstabview.js b/Resources/public/js/views/tabs/ez-locationviewversionstabview.js index aef85aa47..b0bcc4bed 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,24 @@ YUI.add('ez-locationviewversionstabview', function (Y) { return versionsToDisplay; }, + /** + * Tap event handler to restore a version in a given language. + * + * @method _restoreVersionInLanguage + * @protected + * @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/models/assets/ez-versioninfomodel-tests.js b/Tests/js/models/assets/ez-versioninfomodel-tests.js index 429ea2357..a9a632223 100644 --- a/Tests/js/models/assets/ez-versioninfomodel-tests.js +++ b/Tests/js/models/assets/ez-versioninfomodel-tests.js @@ -3,7 +3,7 @@ * For full copyright and license information view LICENSE file distributed with this source code. */ YUI.add('ez-versioninfomodel-tests', function (Y) { - var loadFromHashTest, removeTest, + var loadFromHashTest, removeTest, languageCodeListTest, Assert = Y.Assert; loadFromHashTest = new Y.Test.Case({ @@ -244,8 +244,55 @@ YUI.add('ez-versioninfomodel-tests', function (Y) { }, }); + languageCodeListTest = new Y.Test.Case({ + name: "eZ Version Model languageCodeList attribute tests", + + setUp: function () { + this.version = new Y.eZ.VersionInfo(); + }, + + tearDown: function () { + this.version.destroy(); + delete this.version; + }, + + "Should return the languages as an array": function () { + var languages = ['fre-FR', 'eng-GB'], + list; + + this.version.set('languageCodes', languages.join(',')); + list = this.version.get('languageCodeList'); + + Assert.isArray( + list, + "The list should be an array" + ); + Assert.areEqual( + languages.length, list.length, + "The list should contain the language codes" + ); + Y.Array.each(list, function (lang, i) { + Assert.areEqual(languages[i], lang); + }); + }, + + "Should return an empty array": function () { + var list = this.version.get('languageCodeList'); + + Assert.isArray( + list, + "The list should be an array" + ); + Assert.areEqual( + 0, list.length, + "The list should be an empty array" + ); + }, + + }); + Y.Test.Runner.setName("eZ Version Info Model tests"); Y.Test.Runner.add(loadFromHashTest); Y.Test.Runner.add(removeTest); - + Y.Test.Runner.add(languageCodeListTest); }, '', {requires: ['test', 'json', 'model-tests', 'ez-versioninfomodel', 'ez-restmodel']}); 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