This PR enables the [`no-action-modifiers`](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-action-modifiers.md) template lint rule and removes all usages of the `{{action}}` modifier in core. In general, instances of `{{action "x"}}` have been replaced with `{{on "click" (action "x")}}`. In many cases, such as for `a` elements, we also need to prevent default event handling to avoid unwanted side effects. While the `{{action}}` modifier internally calls `event.preventDefault()`, we need to handle these cases more explicitly. For this purpose, this PR also adds the [ember-event-helpers](https://github.com/buschtoens/ember-event-helpers) dependency so we can use the `prevent-default` handler. For instance: ``` <a href {{on "click" (prevent-default (action "x"))}}>Do X</a> ``` Note that `action` has not in general been refactored away as a helper yet. In general, all event handlers should be methods on the corresponding component and referenced directly (e.g. `{{on "click" this.doSomething}}`). However, the `action` helper is used extensively throughout the codebase and often references methods in the `actions` hash on controllers or routes. Thus this refactor will also be extensive and probably deserves a separate PR. Note: This work was done to complement #17767 by minimizing the potential impact of the `action` modifier override, which uses private API and arguably should be replaced with an AST transform. This is a followup to #18333, which had to be reverted because it did not account for the default treatment of modifier keys by the {{action}} modifier. Commits: * Enable `no-action-modifiers` template lint rule * Replace {{action "x"}} with {{on "click" (action "x")}} * Remove unnecessary action helper usage * Remove ctl+click tests for user-menu These tests now break in Chrome when used with addEventListener. As per the comment, they can probably be safely removed. * Prevent default event handlers to avoid unwanted side effects Uses `event.preventDefault()` in event handlers to prevent default event handling. This had been done automatically by the `action` modifier, but is not always desirable or necessary. * Restore UserCardContents#showUser action to avoid regression By keeping the `showUser` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showUser` argument that's been passed. * Revert EditCategoryTab#selectTab -> EditCategoryTab#select Avoid potential breaking change in themes / plugins * Restore GroupCardContents#showGroup action to avoid regression By keeping the `showGroup` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showGroup` argument that's been passed. * Restore SecondFactorAddTotp#showSecondFactorKey action to avoid regression By keeping the `showSecondFactorKey` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showSecondFactorKey` property that's maintained on the controller. * Refactor away from `actions` hash in ChooseMessage component * Modernize EmojiPicker#onCategorySelection usage * Modernize SearchResultEntry#logClick usage * Modernize Discovery::Categories#showInserted usage * Modernize Preferences::Account#resendConfirmationEmail usage * Modernize MultiSelect::SelectedCategory#onSelectedNameClick usage * Favor fn over action in SelectedChoice component * Modernize WizardStep event handlers * Favor fn over action usage in buttons * Restore Login#forgotPassword action to avoid possible regression * Introduce modKeysPressed utility Returns an array of modifier keys that are pressed during a given `MouseEvent` or `KeyboardEvent`. * Don't interfere with click events on links with `href` values when modifier keys are pressed
170 lines
5.7 KiB
Handlebars
170 lines
5.7 KiB
Handlebars
<DModalBody @title="discourse_local_dates.title" @class="discourse-local-dates-create-modal" @style="overflow: auto">
|
|
|
|
<div class="form">
|
|
{{#if this.isValid}}
|
|
{{#if this.timezoneIsDifferentFromUserTimezone}}
|
|
<div class="preview alert alert-info">
|
|
{{i18n "discourse_local_dates.create.form.current_timezone"}}
|
|
<b>{{this.formattedCurrentUserTimezone}}</b>{{this.currentPreview}}
|
|
</div>
|
|
{{/if}}
|
|
{{else}}
|
|
<div class="validation-error alert alert-error">
|
|
{{i18n "discourse_local_dates.create.form.invalid_date"}}
|
|
</div>
|
|
{{/if}}
|
|
|
|
{{this.computeDate}}
|
|
|
|
<div class="date-time-configuration">
|
|
<div class="inputs-panel">
|
|
<div class="date-time-control from {{if this.fromSelected "is-selected"}} {{if this.fromFilled "is-filled"}}">
|
|
{{d-icon "calendar-alt"}}
|
|
<DButton
|
|
@id="from-date-time"
|
|
@action={{action "focusFrom"}}
|
|
@translatedLabel={{this.formattedFrom}}
|
|
@class="date-time" />
|
|
</div>
|
|
|
|
<div class="date-time-control to {{if this.toSelected "is-selected"}} {{if this.toFilled "is-filled"}}">
|
|
{{d-icon "calendar-alt"}}
|
|
<DButton
|
|
@action={{action "focusTo"}}
|
|
@translatedLabel={{this.formattedTo}}
|
|
@class="date-time" />
|
|
{{#if this.toFilled}}
|
|
<DButton @icon="times" @action={{action "eraseToDateTime"}} @class="delete-to-date" />
|
|
{{/if}}
|
|
</div>
|
|
|
|
{{#unless this.site.mobileView}}
|
|
<TimezoneInput
|
|
@options={{hash icon="globe"}}
|
|
@value={{this.timezone}}
|
|
@onChange={{action (mut this.timezone)}}
|
|
/>
|
|
{{/unless}}
|
|
</div>
|
|
|
|
<div class="picker-panel">
|
|
<Input class="fake-input" />
|
|
<div class="date-picker" id="picker-container-{{this.elementId}}"></div>
|
|
|
|
{{#if this.fromSelected}}
|
|
<div class="time-pickers">
|
|
{{d-icon "far-clock"}}
|
|
<Input maxlength={{5}} placeholder="hh:mm" @type="time" @value={{this.time}} class="time-picker" {{on "input" (action "setTime")}} />
|
|
</div>
|
|
{{/if}}
|
|
|
|
{{#if this.toSelected}}
|
|
{{#if this.toDate}}
|
|
<div class="time-pickers">
|
|
{{d-icon "far-clock"}}
|
|
<Input maxlength={{5}} placeholder="hh:mm" @type="time" @value={{this.toTime}} class="time-picker" {{on "input" (action "setToTime")}} />
|
|
</div>
|
|
{{/if}}
|
|
{{/if}}
|
|
</div>
|
|
|
|
{{#if this.site.mobileView}}
|
|
<TimezoneInput
|
|
@value={{this.timezone}}
|
|
@options={{hash icon="globe"}}
|
|
@onChange={{action (mut this.timezone)}}
|
|
/>
|
|
{{/if}}
|
|
</div>
|
|
|
|
{{#if this.advancedMode}}
|
|
<div class="advanced-options">
|
|
{{#unless this.isRange}}
|
|
<div class="control-group recurrence">
|
|
<label class="control-label">
|
|
{{i18n "discourse_local_dates.create.form.recurring_title"}}
|
|
</label>
|
|
<p>{{html-safe (i18n "discourse_local_dates.create.form.recurring_description")}}</p>
|
|
<div class="controls">
|
|
<ComboBox
|
|
@content={{this.recurringOptions}}
|
|
@class="recurrence-input"
|
|
@value={{this.recurring}}
|
|
@onChange={{action (mut this.recurring)}}
|
|
@options={{hash
|
|
none="discourse_local_dates.create.form.recurring_none"
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
{{/unless}}
|
|
|
|
<div class="control-group format">
|
|
<label>{{i18n "discourse_local_dates.create.form.format_title"}}</label>
|
|
<p>
|
|
{{i18n "discourse_local_dates.create.form.format_description"}}
|
|
<a target="_blank" href="https://momentjs.com/docs/#/parsing/string-format/" rel="noopener noreferrer">
|
|
{{d-icon "question-circle"}}
|
|
</a>
|
|
</p>
|
|
<div class="controls">
|
|
<TextField @value={{this.format}} @class="format-input" />
|
|
</div>
|
|
</div>
|
|
<div class="control-group">
|
|
<ul class="formats">
|
|
{{#each this.previewedFormats as |previewedFormat|}}
|
|
<li class="format">
|
|
<a class="moment-format" href {{on "click" (fn this.updateFormat previewedFormat.format)}}>
|
|
{{previewedFormat.format}}
|
|
</a>
|
|
<span class="previewed-format">
|
|
{{previewedFormat.preview}}
|
|
</span>
|
|
</li>
|
|
{{/each}}
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="control-group timezones">
|
|
<label>{{i18n "discourse_local_dates.create.form.timezones_title"}}</label>
|
|
<p>{{i18n "discourse_local_dates.create.form.timezones_description"}}</p>
|
|
<div class="controls">
|
|
<MultiSelect
|
|
@valueProperty={{null}}
|
|
@nameProperty={{null}}
|
|
@class="timezones-input"
|
|
@content={{this.allTimezones}}
|
|
@value={{this.timezones}}
|
|
@options={{hash
|
|
allowAny=false
|
|
maximum=5
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{{/if}}
|
|
</div>
|
|
</DModalBody>
|
|
|
|
<div class="modal-footer discourse-local-dates-create-modal-footer">
|
|
{{#if this.isValid}}
|
|
<DButton
|
|
@class="btn-primary"
|
|
@action={{action "save"}}
|
|
@label="discourse_local_dates.create.form.insert" />
|
|
{{/if}}
|
|
|
|
<DButton
|
|
@class="btn-flat"
|
|
@action={{action "cancel"}}
|
|
@translatedLabel={{i18n "cancel"}} />
|
|
|
|
<DButton
|
|
@class="btn-default advanced-mode-btn"
|
|
@action={{action "advancedMode"}}
|
|
@icon="cog"
|
|
@label={{this.toggleModeBtnLabel}} />
|
|
</div>
|