Commit 798125f7 authored by Mike Greiling's avatar Mike Greiling

Remove DueDateSelect reference from pages where it is not needed

The DueDateSelect class performes an elaborate setup involving our
deprecated jQuery dropdown class to create a date picker dropdown.
However most of the places that reference this only run this script
to initialize `pickaday` behaviors with the `datepicker` class.

This MR separates that specific behavior from the DueDateSelect class
definition so this unused class can be easily removed once the issue
boards sidebar feature flag is enabled.
parent f24ef52f
import $ from 'jquery';
import Pikaday from 'pikaday';
import { parsePikadayDate, pikadayToString } from '~/lib/utils/datetime_utility';
export default function initDatePickers() {
$('.datepicker').each(function initPikaday() {
const $datePicker = $(this);
const datePickerVal = $datePicker.val();
const calendar = new Pikaday({
field: $datePicker.get(0),
theme: 'gitlab-theme animate-picker',
format: 'yyyy-mm-dd',
container: $datePicker.parent().get(0),
parse: (dateString) => parsePikadayDate(dateString),
toString: (date) => pikadayToString(date),
onSelect(dateText) {
$datePicker.val(calendar.toString(dateText));
},
firstDay: gon.first_day_of_week,
});
calendar.setDate(parsePikadayDate(datePickerVal));
$datePicker.data('pikaday', calendar);
});
$('.js-clear-due-date,.js-clear-start-date').on('click', (e) => {
e.preventDefault();
const calendar = $(e.target).siblings('.datepicker').data('pikaday');
calendar.setDate(null);
});
}
......@@ -2,6 +2,7 @@
import dateFormat from 'dateformat';
import $ from 'jquery';
import Pikaday from 'pikaday';
import initDatePicker from '~/behaviors/date_picker';
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
import { __ } from '~/locale';
import boardsStore from './boards/stores/boards_store';
......@@ -168,40 +169,10 @@ class DueDateSelect {
export default class DueDateSelectors {
constructor() {
this.initMilestoneDatePicker();
initDatePicker();
this.initIssuableSelect();
}
// eslint-disable-next-line class-methods-use-this
initMilestoneDatePicker() {
$('.datepicker').each(function initPikadayMilestone() {
const $datePicker = $(this);
const datePickerVal = $datePicker.val();
const calendar = new Pikaday({
field: $datePicker.get(0),
theme: 'gitlab-theme animate-picker',
format: 'yyyy-mm-dd',
container: $datePicker.parent().get(0),
parse: (dateString) => parsePikadayDate(dateString),
toString: (date) => pikadayToString(date),
onSelect(dateText) {
$datePicker.val(calendar.toString(dateText));
},
firstDay: gon.first_day_of_week,
});
calendar.setDate(parsePikadayDate(datePickerVal));
$datePicker.data('pikaday', calendar);
});
$('.js-clear-due-date,.js-clear-start-date').on('click', (e) => {
e.preventDefault();
const calendar = $(e.target).siblings('.datepicker').data('pikaday');
calendar.setDate(null);
});
}
// eslint-disable-next-line class-methods-use-this
initIssuableSelect() {
const $loading = $('.js-issuable-update .due_date')
.find('.block-loading')
......
/* eslint-disable no-new */
import { mountSidebarLabels, getSidebarOptions } from '~/sidebar/mount_sidebar';
import DueDateSelectors from './due_date_select';
import IssuableContext from './issuable_context';
import LabelsSelect from './labels_select';
import MilestoneSelect from './milestone_select';
......@@ -19,7 +18,6 @@ export default () => {
});
new LabelsSelect();
new IssuableContext(sidebarOptions.currentUser);
new DueDateSelectors();
Sidebar.initialize();
mountSidebarLabels();
......
import initForm from '../../../../shared/milestones/form';
import initForm from '~/shared/milestones/form';
initForm();
import initForm from '../../../../shared/milestones/form';
import initForm from '~/shared/milestones/form';
initForm();
import DueDateSelectors from '~/due_date_select';
import initDatePicker from '~/behaviors/date_picker';
import initSettingsPanels from '~/settings_panels';
// Initialize expandable settings panels
initSettingsPanels();
new DueDateSelectors(); // eslint-disable-line no-new
// Used for deploy tokens "expires at" field
initDatePicker();
import initForm from '../../../../shared/milestones/form';
import initForm from '~/shared/milestones/form';
initForm();
/* eslint-disable no-new */
import initDatePicker from '~/behaviors/date_picker';
import initDeployKeys from '~/deploy_keys';
import DueDateSelectors from '~/due_date_select';
import fileUpload from '~/lib/utils/file_upload';
import ProtectedBranchCreate from '~/protected_branches/protected_branch_create';
import ProtectedBranchEditList from '~/protected_branches/protected_branch_edit_list';
......@@ -16,6 +16,6 @@ export default () => {
initSettingsPanels();
new ProtectedBranchCreate({ hasLicense: false });
new ProtectedBranchEditList();
new DueDateSelectors();
initDatePicker(); // Used for deploy token "expires at" field
fileUpload('.js-choose-file', '.js-object-map-input');
};
import $ from 'jquery';
import DueDateSelectors from '../../due_date_select';
import initDatePicker from '~/behaviors/date_picker';
import GLForm from '../../gl_form';
import ZenMode from '../../zen_mode';
export default (initGFM = true) => {
new ZenMode(); // eslint-disable-line no-new
new DueDateSelectors(); // eslint-disable-line no-new
initDatePicker();
// eslint-disable-next-line no-new
new GLForm($('.milestone-form'), {
emojis: true,
......
<script>
import { GlButton, GlForm, GlFormInput } from '@gitlab/ui';
import DueDateSelectors from '~/due_date_select';
import initDatePicker from '~/behaviors/date_picker';
import createFlash from '~/flash';
import { visitUrl } from '~/lib/utils/url_utility';
import { __ } from '~/locale';
......@@ -65,8 +65,8 @@ export default {
},
},
mounted() {
// eslint-disable-next-line no-new
new DueDateSelectors();
// TODO: utilize GlDatepicker instead of relying on this jQuery behavior
initDatePicker();
},
methods: {
save() {
......
......@@ -3,8 +3,8 @@ import ProtectedBranchEditList from 'ee/protected_branches/protected_branch_edit
import ProtectedTagCreate from 'ee/protected_tags/protected_tag_create';
import ProtectedTagEditList from 'ee/protected_tags/protected_tag_edit_list';
import initDatePicker from '~/behaviors/date_picker';
import initDeployKeys from '~/deploy_keys';
import DueDateSelectors from '~/due_date_select';
import fileUpload from '~/lib/utils/file_upload';
import ProtectedBranchCreate from '~/protected_branches/protected_branch_create';
import CEProtectedBranchEditList from '~/protected_branches/protected_branch_edit_list';
......@@ -39,7 +39,7 @@ if (document.querySelector('.js-protected-refs-for-users')) {
const pushPullContainer = document.querySelector('.js-mirror-settings');
if (pushPullContainer) new EEMirrorRepos(pushPullContainer).init();
new DueDateSelectors();
initDatePicker(); // Used for deploy token "expires at" field
fileUpload('.js-choose-file', '.js-object-map-input');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment