diff --git a/Resources/public/css/theme/views/actions/translate.css b/Resources/public/css/theme/views/actions/translate.css
index 2328df560..1462d1700 100644
--- a/Resources/public/css/theme/views/actions/translate.css
+++ b/Resources/public/css/theme/views/actions/translate.css
@@ -50,6 +50,17 @@
font-weight: bold;
}
+.ez-view-translateactionview .ez-contenttranslation-delete-link {
+ color: #fff;
+ background: #498FE1;
+ border-radius: 0.5em;
+ font-weight: bold;
+}
+
+.ez-view-translateactionview .ez-contenttranslation-delete-link:before {
+ content: "\E615"
+}
+
.ez-view-translateactionview .ez-newtranslation-button {
background: #B8E986;
color: #333333;
diff --git a/Resources/public/css/views/actions/translate.css b/Resources/public/css/views/actions/translate.css
index 9a1f977d4..bf9ee2b7f 100644
--- a/Resources/public/css/views/actions/translate.css
+++ b/Resources/public/css/views/actions/translate.css
@@ -59,7 +59,7 @@
padding: 1em 1.5em;
}
-.ez-view-translateactionview .ez-contenttranslation-edit-link {
+.ez-view-translateactionview .ez-contenttranslation-actions {
display: none;
position: absolute;
z-index: 1;
@@ -67,8 +67,13 @@
top: 0.9em;
}
-.ez-view-translateactionview .ez-contenttranslation:hover .ez-contenttranslation-edit-link {
+.ez-view-translateactionview .ez-contenttranslation:hover .ez-contenttranslation-actions {
display: block;
+}
+
+.ez-view-translateactionview .ez-contenttranslation-actions .ez-contenttranslation-edit-link,
+.ez-view-translateactionview .ez-contenttranslation-actions .ez-contenttranslation-delete-link {
+ display: inline-block;
padding: 0.1em 0.5em;
}
diff --git a/Resources/public/js/models/ez-contentmodel.js b/Resources/public/js/models/ez-contentmodel.js
index 8a907af17..5fe450369 100644
--- a/Resources/public/js/models/ez-contentmodel.js
+++ b/Resources/public/js/models/ez-contentmodel.js
@@ -464,6 +464,22 @@ YUI.add('ez-contentmodel', function (Y) {
}
contentService.deleteContent(this.get('id'), callback);
},
+
+ /**
+ * Removes translation
+ *
+ * @method removeTranslation
+ * @param {Object} options
+ * @param {Object} options.api (required) the JS REST client instance
+ * @param {String} languageCode
+ * @param {Function} callback
+ */
+ removeTranslation: function (options, languageCode, callback) {
+ var capi = options.api,
+ contentService = capi.getContentService();
+
+ contentService.removeTranslation(this.get('id'), languageCode, callback);
+ },
}, {
REST_STRUCT_ROOT: "Content",
ATTRS_REST_MAP: [
diff --git a/Resources/public/js/views/actions/ez-translateactionview.js b/Resources/public/js/views/actions/ez-translateactionview.js
index e5a066717..381eb2da8 100644
--- a/Resources/public/js/views/actions/ez-translateactionview.js
+++ b/Resources/public/js/views/actions/ez-translateactionview.js
@@ -14,7 +14,10 @@ YUI.add('ez-translateactionview', function (Y) {
var events = {
'.ez-newtranslation-button': {
'tap': '_newTranslationLanguageSelectionBox',
- }
+ },
+ '.ez-contenttranslation-delete-link': {
+ 'tap': '_deleteTranslation',
+ },
};
/**
@@ -60,6 +63,7 @@ YUI.add('ez-translateactionview', function (Y) {
location: this.get('location').toJSON(),
content: this.get('content').toJSON(),
translations: translationsList,
+ canDeleteTranslations: translationsList.length > 1,
firstLanguagesCode: firstLanguageCodes,
moreTranslationCount: moreTranslationCount
}));
@@ -147,6 +151,31 @@ YUI.add('ez-translateactionview', function (Y) {
this._hideView();
},
+ /**
+ * Tap event handler on Delete Translation button.
+ *
+ * @method _deleteTranslation
+ * @protected
+ * @param {EventFacade} e
+ */
+ _deleteTranslation: function (e) {
+ var data = {
+ translation: e.target.getAttribute('data-translation'),
+ contentId: this.get('content').get('contentId')
+ };
+
+ e.preventDefault();
+
+ /**
+ * Fired when the translation is deleted
+ *
+ * @event deleteTranslation
+ * @param {data.translation} Language code of translation
+ * @param {data.contentId} The content Id
+ */
+ this.fire('deleteTranslation', data);
+ },
+
/**
* Fires `translate` event after making a selection on LanguageSelectionBox
*
diff --git a/Resources/public/js/views/services/ez-locationviewviewservice.js b/Resources/public/js/views/services/ez-locationviewviewservice.js
index b42ad329e..5213a72c6 100644
--- a/Resources/public/js/views/services/ez-locationviewviewservice.js
+++ b/Resources/public/js/views/services/ez-locationviewviewservice.js
@@ -30,6 +30,7 @@ YUI.add('ez-locationviewviewservice', function (Y) {
this.on('*:translateContent', this._translateContent);
this.on('*:sortUpdate', this._updateSorting);
this.on('*:updatePriority', this._updatePriority);
+ this.on('*:deleteTranslation', this._confirmDeleteTranslation);
this.after('*:requestChange', this._setLanguageCode);
this._setLanguageCode();
@@ -567,6 +568,74 @@ YUI.add('ez-locationviewviewservice', function (Y) {
this.set('languageCode', this.get('request').params.languageCode);
},
+ /**
+ * Removes translation from content.
+ *
+ * @method _deleteTranslation
+ * @protected
+ * @param {String} languageCode
+ */
+ _deleteTranslation: function (languageCode) {
+ var content = this.get('content'),
+ options = {
+ api: this.get('capi')
+ };
+
+ content.removeTranslation(options, languageCode, Y.bind(function(error) {
+ if (error) {
+ this._notify(
+ Y.eZ.trans('failed.delete.content.translation', { language: languageCode }, 'bar'),
+ 'content-delete-translation-' + content.get('id'), 'error', 0
+ );
+ return;
+ }
+
+ this._notify(
+ Y.eZ.trans('success.delete.content.translation', { language: languageCode }, 'bar'),
+ 'content-delete-translation-' + content.get('id'), 'done', 5
+ );
+
+ this.get('app').navigateTo('viewLocation', {
+ id: this.get('location').get('id'),
+ languageCode: content.get('mainLanguageCode')
+ });
+ }, this));
+ },
+
+ /**
+ * `deleteTranslation` event handler,
+ * it asks confirmation to the user before delete the translation item.
+ *
+ * @method _confirmDeleteTranslation
+ * @protected
+ * @param {Object} e event facade of the deleteAction event
+ */
+ _confirmDeleteTranslation: function (e) {
+ var content = this.get('content'),
+ languageCode = e.translation;
+
+ e.preventDefault();
+ if (languageCode === content.get('mainLanguageCode')) {
+ this._notify(
+ Y.eZ.trans('failed.delete.content.main.translation', {}, 'bar'),
+ 'content-delete-translation-' + content.get('id'), 'error', 0
+ );
+ } else {
+ /**
+ * Opens confirmation modal of deleting translation
+ *
+ * @event confirmBoxOpen
+ * @param {e.config} Modal configuration
+ */
+ this.fire('confirmBoxOpen', {
+ config: {
+ title: Y.eZ.trans('confirm.delete.translation', { language: languageCode }, 'bar'),
+ confirmHandler: Y.bind(this._deleteTranslation, this, languageCode),
+ }
+ });
+ }
+ },
+
_getViewParameters: function () {
return {
content: this.get('content'),
diff --git a/Resources/public/templates/translateaction.hbt b/Resources/public/templates/translateaction.hbt
index 306d75015..b1ea0829d 100644
--- a/Resources/public/templates/translateaction.hbt
+++ b/Resources/public/templates/translateaction.hbt
@@ -21,9 +21,15 @@
{{ language_name this }}
-
- {{translate 'translateaction.edit' 'bar'}}
-
+
+
+
+ {{translate 'translateaction.edit' 'bar'}}
+
+ {{#if ../canDeleteTranslations}}
+
+ {{/if}}
+
{{/each}}
diff --git a/Resources/translations/bar.en.xlf b/Resources/translations/bar.en.xlf
index 3388dba9e..2b47b976a 100644
--- a/Resources/translations/bar.en.xlf
+++ b/Resources/translations/bar.en.xlf
@@ -227,6 +227,30 @@
key: translateaction.edit
Resources/public/templates/translateaction.hbt
+
+ Are you sure you want to delete "%language%" translation?
+ Are you sure you want to delete "%language%" translation?
+ key: confirm.delete.translation
+ Resources/public/js/views/services/ez-locationviewviewservice.js
+
+
+ Translation "%language%" has been deleted.
+ Translation "%language%" has been deleted.
+ key: success.delete.content.translation
+ Resources/public/js/views/services/ez-locationviewviewservice.js
+
+
+ Cannot delete translation "%language%" from content.
+ Cannot delete translation "%language%" from content.
+ key: failed.delete.content.translation
+ Resources/public/js/views/services/ez-locationviewviewservice.js
+
+
+ Cannot delete main translation from content.
+ Cannot delete main translation from content.
+ key: failed.delete.content.main.translation
+ Resources/public/js/views/services/ez-locationviewviewservice.js
+
Existing Translations
Existing Translations
diff --git a/Tests/js/views/actions/assets/ez-translateactionview-tests.js b/Tests/js/views/actions/assets/ez-translateactionview-tests.js
index a5d9e58e4..1c6312902 100644
--- a/Tests/js/views/actions/assets/ez-translateactionview-tests.js
+++ b/Tests/js/views/actions/assets/ez-translateactionview-tests.js
@@ -14,7 +14,7 @@ YUI.add('ez-translateactionview-tests', function (Y) {
this.label = 'Translate test label';
this.translationsList = ['eng-GB', 'pol-PL'];
this.disabled = false;
- this.templateVariablesCount = 8;
+ this.templateVariablesCount = 9;
this.contentMock = new Mock();
this.locationMock = new Mock();
this.versionMock = new Mock();
diff --git a/composer.json b/composer.json
index 1b7e6013c..ab0da24f5 100644
--- a/composer.json
+++ b/composer.json
@@ -9,7 +9,7 @@
}
},
"require": {
- "ezsystems/platform-ui-assets-bundle": "^4.0.0",
+ "ezsystems/platform-ui-assets-bundle": "^4.1.0",
"ezsystems/repository-forms": "^1.11",
"ezsystems/ezpublish-kernel": "^6.13",
"ezsystems/ez-support-tools": "^0.2",