Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented copy locale feature #73

Merged
merged 5 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Resources/public/dist/components/articles/edit/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/dist/components/articles/list/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/public/dist/services/manager.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 47 additions & 30 deletions Resources/public/js/components/articles/edit/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ define([
title: this.sandbox.translate('toolbar.copy-locale'),
callback: function() {
CopyLocale.startCopyLocalesOverlay.call(this).then(function(newLocales) {
// reload form when the current locale is in newLocales
if (_.contains(newLocales, this.options.locale)) {
this.toEdit(this.options.locale);

return;
}

// save new created locales to data and show success label
this.data.concreteLanguages = _.uniq(this.data.concreteLanguages.concat(newLocales));
this.sandbox.emit('sulu.labels.success.show', 'labels.success.copy-locale-desc', 'labels.success');
}.bind(this));
Expand Down Expand Up @@ -186,6 +194,7 @@ define([
this.setHeaderBar(true);
this.loadLocalizations();

// the open ghost overlay component needs the current locale in `this.options.language`
this.options.language = this.options.locale;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment why we add this option

},

Expand All @@ -196,34 +205,44 @@ define([
this.sandbox.on('sulu.tab.data-changed', this.setData.bind(this));
this.sandbox.on('sulu.article.error', this.handleError.bind(this));
this.sandbox.on('husky.tabs.header.item.select', this.tabChanged.bind(this));
this.sandbox.on('sulu.header.language-changed', this.languageChanged.bind(this));
},

this.sandbox.on('sulu.header.language-changed', function(item) {
this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey, item.id);

if (-1 === _(this.data.concreteLanguages).indexOf(item.id)) {
OpenGhost.openGhost.call(this, this.data).then(function(copy, src) {
if (!!copy) {
CopyLocale.copyLocale.call(
this,
this.data.id,
src,
[item.id],
function() {
this.toEdit(item.id);
}.bind(this)
);
} else {
// new article will be created
this.toEdit(item.id);
}
}.bind(this)).fail(function() {
// the open-ghost page got canceled, so reset the language changer
this.sandbox.emit('sulu.header.change-language', this.options.language);
}.bind(this));
} else {
this.toEdit(item.id);
}
}.bind(this));
/**
* Language changed event.
*
* @param {Object} item
*/
languageChanged: function(item) {
if (item.id === this.options.locale) {
return;
}

this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey, item.id);

if (-1 === _(this.data.concreteLanguages).indexOf(item.id)) {
OpenGhost.openGhost.call(this, this.data).then(function(copy, src) {
if (!!copy) {
CopyLocale.copyLocale.call(
this,
this.data.id,
src,
[item.id],
function() {
this.toEdit(item.id);
}.bind(this)
);
} else {
// new article will be created
this.toEdit(item.id);
}
}.bind(this)).fail(function() {
// the open-ghost page got canceled, so reset the language changer
this.sandbox.emit('sulu.header.change-language', this.options.language);
}.bind(this));
} else {
this.toEdit(item.id);
}
},

/**
Expand Down Expand Up @@ -540,9 +559,7 @@ define([
* @returns {string}
*/
getCopyLocaleUrl: function(id, src, dest) {
return [
'/admin/api/articles/', id, '?locale=', src, '&dest=', dest, '&action=copy-locale'
].join('');
return ArticleManager.getCopyLocaleUrl(id,src,dest);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format this file

}
}
});
8 changes: 5 additions & 3 deletions Resources/public/js/components/articles/list/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ define([
* @returns {string}
*/
getCopyLocaleUrl: function(id, src, dest) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to service?

return [
'/admin/api/articles/', id, '?locale=', src, '&dest=', dest, '&action=copy-locale'
].join('');
return ArticleManager.getCopyLocaleUrl(id,src,dest);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format this file

},

bindCustomEvents: function() {
Expand All @@ -302,6 +300,10 @@ define([
}.bind(this));

this.sandbox.on('sulu.header.language-changed', function(item) {
if (item.id === this.options.locale) {
return;
}

this.sandbox.sulu.saveUserSetting(this.options.config.settingsKey, item.id);
this.toList(item.id);
}.bind(this));
Expand Down
15 changes: 15 additions & 0 deletions Resources/public/js/services/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ define(['jquery', 'services/husky/util'], function($, Util) {
templates.url({id: id, locale: locale, action: 'remove-draft'}),
'POST'
);
},

/**
* Returns copy article from a given locale to a array of other locales url.
*
* @param {string} id
* @param {string} src
* @param {string[]} dest
*
* @returns {string}
*/
getCopyLocaleUrl: function(id, src, dest) {
return [
templates.url({id: id, locale: src, action: 'copy-locale'}), '&dest=', dest
].join('');
}
};
});