diff --git a/scripts/apps/authoring-react/authoring-angular-template-integration.tsx b/scripts/apps/authoring-react/authoring-angular-template-integration.tsx index 70839178f3..e85db92689 100644 --- a/scripts/apps/authoring-react/authoring-angular-template-integration.tsx +++ b/scripts/apps/authoring-react/authoring-angular-template-integration.tsx @@ -24,6 +24,7 @@ export class AuthoringAngularTemplateIntegration extends React.PureComponent ); diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index 05b1bb19fd..826c94f554 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -239,6 +239,8 @@ interface IPropsWrapper extends IProps { fieldsData: IFieldsData, computeLatestEntity: IExposedFromAuthoring['getLatestItem'], ): IFieldsData; + + autoFocus?: boolean; // defaults to true } /** @@ -488,6 +490,7 @@ export class AuthoringIntegrationWrapper extends React.PureComponent { return getWidgetsFromExtensions(article)[index]._id; }} + autoFocus={this.props.autoFocus} /> ); }} diff --git a/scripts/apps/authoring-react/authoring-react.tsx b/scripts/apps/authoring-react/authoring-react.tsx index c3fbe4f097..4ea040f28d 100644 --- a/scripts/apps/authoring-react/authoring-react.tsx +++ b/scripts/apps/authoring-react/authoring-react.tsx @@ -564,7 +564,7 @@ export class AuthoringReact extends React.PureCo this.setState(initialState); - if (this.componentRef != null) { + if (this.componentRef != null && this.props.autoFocus !== false) { this.cleanupFunctionsToRunBeforeUnmounting.push(focusFirstChildInput(this.componentRef).cancel); } }); diff --git a/scripts/apps/authoring-react/multi-edit-modal.tsx b/scripts/apps/authoring-react/multi-edit-modal.tsx index 411e91925d..8a15e9751f 100644 --- a/scripts/apps/authoring-react/multi-edit-modal.tsx +++ b/scripts/apps/authoring-react/multi-edit-modal.tsx @@ -241,6 +241,7 @@ export class MultiEditModal extends React.PureComponent { getInlineToolbarActions={(options) => this.getInlineToolbarActions(options, availableArticles) } + autoFocus={false} /> diff --git a/scripts/apps/authoring/authoring/directives/AuthoringDirective.ts b/scripts/apps/authoring/authoring/directives/AuthoringDirective.ts index 350c5cb09f..c08c10103d 100644 --- a/scripts/apps/authoring/authoring/directives/AuthoringDirective.ts +++ b/scripts/apps/authoring/authoring/directives/AuthoringDirective.ts @@ -1056,6 +1056,10 @@ export function AuthoringDirective( if (event.detail.itemId === $scope.item._id) { angular.extend($scope.item, {[event.detail.field.key]: event.detail.field.value}); + if ($scope.item.fields_meta != null) { + delete $scope.item.fields_meta[event.detail.field.key]; + } + $scope.dirty = true; $scope.$applyAsync(); $scope.refresh(); diff --git a/scripts/apps/authoring/authoring/directives/AuthoringHeaderDirective.ts b/scripts/apps/authoring/authoring/directives/AuthoringHeaderDirective.ts index ce60b37d69..29758a9234 100644 --- a/scripts/apps/authoring/authoring/directives/AuthoringHeaderDirective.ts +++ b/scripts/apps/authoring/authoring/directives/AuthoringHeaderDirective.ts @@ -23,6 +23,7 @@ AuthoringHeaderDirective.$inject = [ 'features', 'TranslationService', 'authoringWorkspace', + '$location', ]; export function AuthoringHeaderDirective( api, @@ -36,6 +37,7 @@ export function AuthoringHeaderDirective( features, TranslationService, authoringWorkspace: AuthoringWorkspaceService, + $location, ) { return { templateUrl: 'scripts/apps/authoring/views/authoring-header.html', @@ -307,52 +309,57 @@ export function AuthoringHeaderDirective( const loadingStartTimestamp = Date.now(); let lastElementCount = null; - /** - * Use interval to approximately determine when fields have loaded. - */ - const interval = setInterval(() => { - if (Date.now() - loadingStartTimestamp > 5000) { - // stop trying after 5s - // there might not be inputs in authoring header configured - clearInterval(interval); - } else { - const elements = [...elem[0].querySelectorAll('input, textarea, [contenteditable]')]; - - if (elements.length < 1) { - return; - } else if (lastElementCount == null) { - lastElementCount = elements.length; + // authoring-angular specific workaround + const autofocus = $location.url() !== '/settings/templates' && $location.url() !== '/multiedit'; + + if (autofocus) { + /** + * Use interval to approximately determine when fields have loaded. + */ + const interval = setInterval(() => { + if (Date.now() - loadingStartTimestamp > 5000) { + // stop trying after 5s + // there might not be inputs in authoring header configured + clearInterval(interval); + } else { + const elements = [...elem[0].querySelectorAll('input, textarea, [contenteditable]')]; - return; - } else if (lastElementCount !== elements.length) { - lastElementCount = elements.length; + if (elements.length < 1) { + return; + } else if (lastElementCount == null) { + lastElementCount = elements.length; - return; - } else { - clearInterval(interval); - } + return; + } else if (lastElementCount !== elements.length) { + lastElementCount = elements.length; - if (scope.action === 'correct') { - elem.find('#ednote').focus(); - } else { - const sorted = elements - .map((el) => { - const orderEl = el.closest('[order]'); - - return { - input: el, - order: orderEl == null ? null : parseInt(orderEl.getAttribute('order'), 10), - }; - }) - .filter(({order}) => order != null) - .sort((a, b) => a.order - b.order); - - if (sorted.length > 0) { - sorted[0].input.focus(); + return; + } else { + clearInterval(interval); + } + + if (scope.action === 'correct') { + elem.find('#ednote').focus(); + } else { + const sorted = elements + .map((el) => { + const orderEl = el.closest('[order]'); + + return { + input: el, + order: orderEl == null ? null : parseInt(orderEl.getAttribute('order'), 10), + }; + }) + .filter(({order}) => order != null) + .sort((a, b) => a.order - b.order); + + if (sorted.length > 0) { + sorted[0].input.focus(); + } } } - } - }, 100); + }, 100); + } }, }; } diff --git a/scripts/apps/users/views/user-preferences.html b/scripts/apps/users/views/user-preferences.html index 540d19a657..ea495731f9 100644 --- a/scripts/apps/users/views/user-preferences.html +++ b/scripts/apps/users/views/user-preferences.html @@ -78,6 +78,14 @@

+
+ + +
+
+ + +
diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index a88fc99160..c0866c7b91 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -234,6 +234,8 @@ declare module 'superdesk-api' { headerCollapsed?: boolean; // initial value themingEnabled?: boolean; // only works with article; default false + + autoFocus?: boolean; // defaults to true; will focus first input } // AUTHORING-REACT FIELD TYPES - attachments