Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const rest = confirmationRequired.slice(5);
const body = displayedMessages.map(warning => warning.Message);
if (rest.length) {
body.push(
i18n.inject(
i18n._t(
'AssetAdmin.BULK_OWNED_WARNING_REMAINING',
'And {count} other file(s)'
),
{ count: rest.length },
)
);
}
if (displayedMessages.length) {
const alertMessage = [
i18n.inject(
i18n._t(
'AssetAdmin.BULK_OWNED_WARNING_HEADING',
'{count} file(s) are being used by other published content.'
),
{ count: confirmationRequired.length },
),
body.join('\n'),
i18n._t(
'AssetAdmin.BULK_OWNED_WARNING_FOOTER',
'Unpublishing will only remove files from the published version of the content. They will remain on the draft version. Unpublish anyway?'
)
];
// eslint-disable-next-line no-alert
.then(() => {
// Update the Apollo query cache with the new form data
const { apolloClient } = window.ss;
// @todo optimistically update the data for the current element instead of
// rerunning the whole query
apolloClient.queryManager.reFetchObservableQueries();
reinitialiseForm(formData);
const preview = $('.cms-preview');
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));
const newTitle = formData[`PageElements_${element.ID}_Title`];
$.noticeAdd({
text: i18n.inject(
i18n._t(
'ElementSaveAction.SUCCESS_NOTIFICATION',
'Saved \'{title}\' successfully'
),
{ title: newTitle || noTitle }
),
stay: false,
type: 'success'
});
})
.catch(() => {
getInputProps() {
const placeholder = i18n.inject(
i18n._t('Admin.FormatExample', 'Example: {format}'),
{ format: this.moment().endOf('month').format(localFormat) }
);
const value = this.asHTML5()
? this.props.value
: this.getLocalisedValue();
const type = this.asHTML5() ? 'date' : 'text';
const props = {
...super.getInputProps(),
type,
// `parse()` of redux-form `Field` should be used for parsing the
// localised input value to iso format to pass to redux store but `Field`
// is not accessible in this context.
value,
placeholder,
.then(({ data: { unpublishFiles } }) => {
const successes = unpublishFiles.filter(result => result.__typename === 'File');
const confirmationRequired = unpublishFiles.filter(result => (
result.__typename === 'PublicationNotice' && result.Type === 'HAS_OWNERS'
));
const successful = successes.map(file => {
this.resetFile(file);
return file;
});
const displayedMessages = confirmationRequired.slice(0, 4);
const rest = confirmationRequired.slice(5);
const body = displayedMessages.map(warning => warning.Message);
if (rest.length) {
body.push(
i18n.inject(
i18n._t(
'AssetAdmin.BULK_OWNED_WARNING_REMAINING',
'And {count} other file(s)'
),
{ count: rest.length },
)
);
}
if (displayedMessages.length) {
const alertMessage = [
i18n.inject(
i18n._t(
'AssetAdmin.BULK_OWNED_WARNING_HEADING',
'{count} file(s) are being used by other published content.'
),
{ count: confirmationRequired.length },
renderBody() {
const { usedOn, loading, error } = this.props;
if (error || !usedOn || !usedOn.length) {
let message = null;
let classState = null;
if (error) {
message = i18n.inject(
i18n._t('Admin.LOADING_ERROR', 'As error occured when loading the data: {message}'),
{ message: error },
);
classState = 'error';
} else if (loading) {
message = i18n._t('Admin.LOADING', 'Loading...');
classState = 'loading';
} else {
message = i18n._t('Admin.NOT_USED', 'This is not used anywhere');
classState = 'empty';
}
const className = classnames([
'used-on__message',
`used-on__message--${classState}`,
]);
this.register('delete', function(ids) {
var confirmed = confirm(
i18n.inject(
i18n._t(
"Admin.BATCH_DELETE_PROMPT",
"You have {num} page(s) selected.\n\nAre you sure you want to delete these pages?\n\nThese pages and all of their children pages will be deleted and sent to the archive."
),
{'num': ids.length}
)
);
return (confirmed) ? ids : false;
});
render() {
const { content, fieldTitle, icon, id, importance } = this.props;
const { open } = this.state;
const { iconColor, type } = tipImportanceMap[importance];
const label = i18n.inject(i18n._t('Admin.TIP_LABEL', '{type} for {fieldTitle}'), {
type,
fieldTitle
});
return [
(
<button aria-expanded="{open}" aria-label="{label}" id="{`${id}-tip`}" color="outline-secondary">
),</button>
onClick(e, nameOrID) {
const { owners } = props.data;
let message = null;
if (owners && parseInt(owners, 10) > 0) {
message = [
i18n.inject(
i18n._t(
'AssetAdmin.SINGLE_OWNED_WARNING_1',
'This file is being used in {count} other published section(s).',
),
{ count: owners }
),
i18n._t(
'AssetAdmin.SINGLE_OWNED_WARNING_2',
'Ensure files are removed from content areas prior to unpublishing them. Otherwise, they will appear as broken links.'
),
i18n._t(
'AssetAdmin.SINGLE_OWNED_WARNING_3',
'Do you want to unpublish this file anyway?'
)
].join('\n\n');
} else {
onclick: function(e) {
var owners = this.data('owners');
if (owners && parseInt(owners) > 0) {
var message = [
i18n.inject(
i18n._t(
'Admin.OWNED_WARNING_1',
'You are unpublishing content that is being used in {count} other published section(s).'
),
{ count: owners }
),
i18n._t(
'Admin.OWNED_WARNING_2',
'This could cause a published page to have missing components on the live site.'
),
i18n._t(
'Admin.OWNED_WARNING_3',
'Do you want to unpublish anyway?'
)
];
if (window.confirm(message.join('\n\n'))) {
getInputProps() {
const placeholder = i18n.inject(
i18n._t('Admin.FormatExample', 'Example: {format}'),
{ format: moment().endOf('month').format(localFormat) }
);
const type = this.asHTML5() ? 'time' : 'text';
return {
...super.getInputProps(),
type,
placeholder,
};
}