mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Add autohide controller to move code from legacy to stimulus
This commit is contained in:
@@ -31,7 +31,11 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
render(Primer::BaseComponent.new(
|
||||
tag: :div,
|
||||
classes: "op-primer-flash--item",
|
||||
data: { unique_key: @unique_key }.compact
|
||||
data: {
|
||||
"flash-target": "item",
|
||||
"autohide": @autohide,
|
||||
unique_key: @unique_key
|
||||
}.compact
|
||||
)) do
|
||||
render_parent
|
||||
end
|
||||
|
||||
@@ -39,6 +39,8 @@ module OpPrimer
|
||||
system_arguments[:dismiss_scheme] ||= :remove
|
||||
system_arguments[:dismiss_label] ||= I18n.t(:button_close)
|
||||
|
||||
@autohide = system_arguments[:scheme] == :success && system_arguments[:dismiss_scheme] != :none
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,3 +5,6 @@
|
||||
data-flash-autohide-value="<%= User.current.pref.auto_hide_popups? %>">
|
||||
<%= render_flash_messages %>
|
||||
</div>
|
||||
|
||||
<%# Flash modals render modal components %>
|
||||
<%= render_flash_modal %>
|
||||
|
||||
@@ -118,8 +118,6 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<div class="content-overlay"></div>
|
||||
<%= content_tag :main, id: "content-wrapper", class: initial_classes, data: stimulus_content_data do %>
|
||||
<%= render partial: "layouts/flashes" %>
|
||||
<%# Flash modals render modal components %>
|
||||
<%= render_flash_modal %>
|
||||
<% if show_onboarding_modal? %>
|
||||
<section data-augmented-model-wrapper
|
||||
data-modal-initialize-now="true"
|
||||
|
||||
@@ -5,8 +5,6 @@ export function setupServerResponse() {
|
||||
focusFirstErroneousField();
|
||||
activateFlashNotice();
|
||||
activateFlashError();
|
||||
autoHideFlashMessage();
|
||||
flashCloseHandler();
|
||||
|
||||
jQuery(document).ajaxComplete(activateFlashNotice);
|
||||
jQuery(document).ajaxComplete(activateFlashError);
|
||||
@@ -90,22 +88,6 @@ export function setupServerResponse() {
|
||||
});
|
||||
}
|
||||
|
||||
function flashCloseHandler() {
|
||||
jQuery('body').on('click keydown touchend', '.close-handler,.op-toast--close', function (e) {
|
||||
if (e.type === 'click' || e.which === 13) {
|
||||
jQuery(this).parent('.errorExplanation, .op-toast')
|
||||
.not('.persistent-toggle--notification')
|
||||
.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function autoHideFlashMessage() {
|
||||
setTimeout(() => {
|
||||
jQuery('.op-toast.autohide-toaster').remove();
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function addClickEventToAllErrorMessages() {
|
||||
jQuery('a.afocus').each(function () {
|
||||
const target = jQuery(this);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ApplicationController } from 'stimulus-use';
|
||||
|
||||
export const SUCCESS_AUTOHIDE_TIMEOUT = 5000;
|
||||
|
||||
export default class FlashController extends ApplicationController {
|
||||
static values = {
|
||||
autohide: Boolean,
|
||||
};
|
||||
|
||||
declare autohideValue:boolean;
|
||||
|
||||
static targets = [
|
||||
'item',
|
||||
];
|
||||
|
||||
declare readonly itemTargets:HTMLElement;
|
||||
|
||||
itemTargetConnected(element:HTMLElement) {
|
||||
const autohide = element.dataset.autohide === 'true';
|
||||
if (this.autohideValue && autohide) {
|
||||
setTimeout(() => element.remove(), SUCCESS_AUTOHIDE_TIMEOUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import PollForChangesController from './controllers/poll-for-changes.controller'
|
||||
import TableHighlightingController from './controllers/table-highlighting.controller';
|
||||
import OpShowWhenCheckedController from './controllers/show-when-checked.controller';
|
||||
import OpShowWhenValueSelectedController from './controllers/show-when-value-selected.controller';
|
||||
import FlashController from './controllers/flash.controller';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -31,6 +32,7 @@ instance.register('menus--main', MainMenuController);
|
||||
instance.register('show-when-checked', OpShowWhenCheckedController);
|
||||
instance.register('disable-when-checked', OpDisableWhenCheckedController);
|
||||
instance.register('show-when-value-selected', OpShowWhenValueSelectedController);
|
||||
instance.register('flash', FlashController);
|
||||
instance.register('print', PrintController);
|
||||
instance.register('refresh-on-form-changes', RefreshOnFormChangesController);
|
||||
instance.register('async-dialog', AsyncDialogController);
|
||||
|
||||
Reference in New Issue
Block a user