Skip to content

Commit

Permalink
Merge pull request #36 from adamwojs/Fix-EZP-27541_unable_to_change_l…
Browse files Browse the repository at this point in the history
…anguage_in_embeded_content_create_view

Fix EZP-27541: Unable to change language in embed content create view
  • Loading branch information
lserwatka authored Jul 24, 2017
2 parents 8effdf8 + f4bca22 commit 14f95e0
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bundle/Resources/public/js/views/cof-contentcreationview.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,26 @@ YUI.add('cof-contentcreationview', function (Y) {
.removeClass(CLASS_HIDDEN);

createContentView.set('active', true);

createContentView.after('versionChange', this._setContentLanguage.bind(this, createContentView));
Y.one(SELECTOR_UDW_CONTAINER).addClass(CLASS_INDEX_FORCED);

this._hideButtons(createContentView);
},

/**
* Updates the content language.
*
* @protected
* @method _setContentLanguage
* @param createContentView {Object} the view instance
* @param event {Object} event facade
*/
_setContentLanguage: function (createContentView, event) {
this.get('contentTypeSelectorView')
.set('languageCode', createContentView.get('languageCode'));
this._hideButtons(createContentView);
},

/**
* Hides buttons besides publish.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ YUI.add('cof-createcontent-universaldiscoveryserviceplugin', function (Y) {
this.onHostEvent('*:setParentLocation', this._setParentLocation, this);
this.onHostEvent('*:publishedDraft', this._loadContentLocation, this);
this.onHostEvent('*:deleteContent', this._deleteContent, this);
this.onHostEvent('*:changeLanguage', this._selectLanguage, this);
},

/**
Expand Down Expand Up @@ -297,6 +298,96 @@ YUI.add('cof-createcontent-universaldiscoveryserviceplugin', function (Y) {
_deleteContent: function (event) {
event.content.delete({api: this.get('host').get('capi')}, function () {});
},

/**
* Opens the LanguageSelectionBox view instance that allows to select a created content language.
*
* @protected
* @method _selectLanguage
* @param event {Object} event facade
*/
_selectLanguage: function (event) {
var host = this.get('host');

event.preventDefault();

/**
* Fired to opens languageSelectionBox for selecting language of created content
* Listened in the eZ.Plugin.LanguageSelectionBox
*
* @event languageSelect
* @param config {Object} the configuration of language selection box
* @param config.title {String} title of the languageSelectionBox
* @param config.languageSelectedHandler {Function|Null} languageSelected event handler
* @param config.cancelLanguageSelectionHandler {Function|Null} cancelLanguageSelection event handler
* @param config.canBaseTranslation {Boolean} enables or disables possibility of based new translation on already existing one
* @param config.translationMode {Boolean} translation mode flag
* @param config.referenceLanguageList {Array|Null} list of languages used as reference for new translation.
*/
host.get('app').fire('languageSelect', {
config: {
title: Y.eZ.trans('change.language.to', {}, 'contentedit'),
languageSelectedHandler: this._setLanguage.bind(this, event.target, event.fields),
cancelLanguageSelectionHandler: null,
canBaseTranslation: false,
translationMode: true,
referenceLanguageList: [host.get('languageCode')]
},
});
},

/**
* Sets language of created content to one given in event facade. After that notification is fired.
*
* @method _setLanguage
* @protected
* @param view {Y.eZ.View} the view which triggered language selection box
* @param fields {Object} object containing fields of current language version
* @param event {Object} the event facade
* @param event.selectedLanguageCode {String} language code to which created content will be switched
*/
_setLanguage: function (view, fields, event) {
var host = this.get('host'),
app = host.get('app'),
version = host.get('version'),
selectedLanguageCode = event.selectedLanguageCode,
formFields = {};

Y.Object.each(fields, function (field) {
formFields[field.fieldDefinitionIdentifier] = {
fieldDefinitionIdentifier: field.fieldDefinitionIdentifier,
fieldValue: field.fieldValue,
};
});

host.set('languageCode', selectedLanguageCode);
version.setFieldsIn(formFields, selectedLanguageCode);

view.setAttrs({
languageCode: selectedLanguageCode,
version: version,
});

/**
* Displays a notification bar with error message.
* Listened by eZ.PlatformUIApp
*
* @event notify
* @param notification {Object} notification data
*/
app.fire('notify', {
notification: {
text: Y.eZ.trans(
'language.changed.to',
{name: app.getLanguageName(selectedLanguageCode)},
'contentedit'
),
identifier: 'create-content-change-language-to-' + selectedLanguageCode,
state: 'done',
timeout: 5,
}
});
},
}, {
NS: 'CreateContentUniversalDiscoveryServicePlugin',
ATTRS: {
Expand Down

0 comments on commit 14f95e0

Please sign in to comment.