Remove issuable form from global namespace

This commit is contained in:
Filipa Lacerda 2017-10-26 23:21:55 +03:00
parent a665a35438
commit 94743e0e8f
No known key found for this signature in database
GPG Key ID: 9CA3FDE4D1E2F1C8
4 changed files with 88 additions and 92 deletions

View File

@ -1,5 +1,4 @@
/* eslint-disable comma-dangle, space-before-function-paren, no-new */ /* eslint-disable comma-dangle, space-before-function-paren, no-new */
import IssuableContext from '../../issuable_context';
/* global MilestoneSelect */ /* global MilestoneSelect */
/* global LabelsSelect */ /* global LabelsSelect */
/* global Sidebar */ /* global Sidebar */
@ -11,6 +10,7 @@ import AssigneeTitle from '../../sidebar/components/assignees/assignee_title';
import Assignees from '../../sidebar/components/assignees/assignees'; import Assignees from '../../sidebar/components/assignees/assignees';
import DueDateSelectors from '../../due_date_select'; import DueDateSelectors from '../../due_date_select';
import './sidebar/remove_issue'; import './sidebar/remove_issue';
import IssuableContext from '../../issuable_context';
const Store = gl.issueBoards.BoardsStore; const Store = gl.issueBoards.BoardsStore;

View File

@ -2,7 +2,7 @@
/* global ProjectSelect */ /* global ProjectSelect */
import IssuableIndex from './issuable_index'; import IssuableIndex from './issuable_index';
/* global Milestone */ /* global Milestone */
/* global IssuableForm */ import IssuableForm from './issuable_form';
/* global LabelsSelect */ /* global LabelsSelect */
/* global MilestoneSelect */ /* global MilestoneSelect */
/* global NewBranchForm */ /* global NewBranchForm */

View File

@ -1,4 +1,4 @@
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-use-before-define, no-useless-escape, no-new, quotes, object-shorthand, no-unused-vars, comma-dangle, no-alert, consistent-return, no-else-return, prefer-template, one-var, one-var-declaration-per-line, curly, max-len */ /* eslint-disable func-names, prefer-rest-params, wrap-iife, no-use-before-define, no-useless-escape, no-new, object-shorthand, no-unused-vars, comma-dangle, no-alert, consistent-return, no-else-return, prefer-template, one-var, one-var-declaration-per-line, curly, max-len */
/* global GitLab */ /* global GitLab */
/* global Autosave */ /* global Autosave */
@ -8,103 +8,100 @@ import GfmAutoComplete from './gfm_auto_complete';
import ZenMode from './zen_mode'; import ZenMode from './zen_mode';
import { parsePikadayDate, pikadayToString } from './lib/utils/datefix'; import { parsePikadayDate, pikadayToString } from './lib/utils/datefix';
(function() { export default class IssuableForm {
this.IssuableForm = (function() { constructor(form) {
IssuableForm.prototype.wipRegex = /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i; this.form = form;
this.toggleWip = this.toggleWip.bind(this);
this.renderWipExplanation = this.renderWipExplanation.bind(this);
this.resetAutosave = this.resetAutosave.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.wipRegex = /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i;
function IssuableForm(form) { new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources).setup();
var $issuableDueDate, calendar; new UsersSelect();
this.form = form; new ZenMode();
this.toggleWip = this.toggleWip.bind(this);
this.renderWipExplanation = this.renderWipExplanation.bind(this); this.titleField = this.form.find('input[name*="[title]"]');
this.resetAutosave = this.resetAutosave.bind(this); this.descriptionField = this.form.find('textarea[name*="[description]"]');
this.handleSubmit = this.handleSubmit.bind(this); if (!(this.titleField.length && this.descriptionField.length)) {
new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources).setup(); return;
new UsersSelect();
new ZenMode();
this.titleField = this.form.find("input[name*='[title]']");
this.descriptionField = this.form.find("textarea[name*='[description]']");
if (!(this.titleField.length && this.descriptionField.length)) {
return;
}
this.initAutosave();
this.form.on("submit", this.handleSubmit);
this.form.on("click", ".btn-cancel", this.resetAutosave);
this.initWip();
$issuableDueDate = $('#issuable-due-date');
if ($issuableDueDate.length) {
calendar = new Pikaday({
field: $issuableDueDate.get(0),
theme: 'gitlab-theme animate-picker',
format: 'yyyy-mm-dd',
container: $issuableDueDate.parent().get(0),
parse: dateString => parsePikadayDate(dateString),
toString: date => pikadayToString(date),
onSelect: function(dateText) {
$issuableDueDate.val(calendar.toString(dateText));
}
});
calendar.setDate(parsePikadayDate($issuableDueDate.val()));
}
} }
IssuableForm.prototype.initAutosave = function() { this.initAutosave();
new Autosave(this.titleField, [document.location.pathname, document.location.search, "title"]); this.form.on('submit', this.handleSubmit);
return new Autosave(this.descriptionField, [document.location.pathname, document.location.search, "description"]); this.form.on('click', '.btn-cancel', this.resetAutosave);
}; this.initWip();
IssuableForm.prototype.handleSubmit = function() { const $issuableDueDate = $('#issuable-due-date');
return this.resetAutosave();
};
IssuableForm.prototype.resetAutosave = function() { if ($issuableDueDate.length) {
this.titleField.data("autosave").reset(); const calendar = new Pikaday({
return this.descriptionField.data("autosave").reset(); field: $issuableDueDate.get(0),
}; theme: 'gitlab-theme animate-picker',
format: 'yyyy-mm-dd',
container: $issuableDueDate.parent().get(0),
parse: dateString => parsePikadayDate(dateString),
toString: date => pikadayToString(date),
onSelect: dateText => $issuableDueDate.val(calendar.toString(dateText)),
});
calendar.setDate(parsePikadayDate($issuableDueDate.val()));
}
}
IssuableForm.prototype.initWip = function() { initAutosave() {
this.$wipExplanation = this.form.find(".js-wip-explanation"); new Autosave(this.titleField, [document.location.pathname, document.location.search, 'title']);
this.$noWipExplanation = this.form.find(".js-no-wip-explanation"); return new Autosave(this.descriptionField, [document.location.pathname, document.location.search, 'description']);
if (!(this.$wipExplanation.length && this.$noWipExplanation.length)) { }
return;
}
this.form.on("click", ".js-toggle-wip", this.toggleWip);
this.titleField.on("keyup blur", this.renderWipExplanation);
return this.renderWipExplanation();
};
IssuableForm.prototype.workInProgress = function() { handleSubmit() {
return this.wipRegex.test(this.titleField.val()); return this.resetAutosave();
}; }
IssuableForm.prototype.renderWipExplanation = function() { resetAutosave() {
if (this.workInProgress()) { this.titleField.data('autosave').reset();
this.$wipExplanation.show(); return this.descriptionField.data('autosave').reset();
return this.$noWipExplanation.hide(); }
} else {
this.$wipExplanation.hide();
return this.$noWipExplanation.show();
}
};
IssuableForm.prototype.toggleWip = function(event) { initWip() {
event.preventDefault(); this.$wipExplanation = this.form.find('.js-wip-explanation');
if (this.workInProgress()) { this.$noWipExplanation = this.form.find('.js-no-wip-explanation');
this.removeWip(); if (!(this.$wipExplanation.length && this.$noWipExplanation.length)) {
} else { return;
this.addWip(); }
} this.form.on('click', '.js-toggle-wip', this.toggleWip);
return this.renderWipExplanation(); this.titleField.on('keyup blur', this.renderWipExplanation);
}; return this.renderWipExplanation();
}
IssuableForm.prototype.removeWip = function() { workInProgress() {
return this.titleField.val(this.titleField.val().replace(this.wipRegex, "")); return this.wipRegex.test(this.titleField.val());
}; }
IssuableForm.prototype.addWip = function() { renderWipExplanation() {
return this.titleField.val("WIP: " + (this.titleField.val())); if (this.workInProgress()) {
}; this.$wipExplanation.show();
return this.$noWipExplanation.hide();
} else {
this.$wipExplanation.hide();
return this.$noWipExplanation.show();
}
}
return IssuableForm; toggleWip(event) {
})(); event.preventDefault();
}).call(window); if (this.workInProgress()) {
this.removeWip();
} else {
this.addWip();
}
return this.renderWipExplanation();
}
removeWip() {
return this.titleField.val(this.titleField.val().replace(this.wipRegex, ''));
}
addWip() {
this.titleField.val(`WIP: ${(this.titleField.val())}`);
}
}

View File

@ -6,7 +6,6 @@ import '~/gl_dropdown';
import 'select2'; import 'select2';
import '~/api'; import '~/api';
import '~/create_label'; import '~/create_label';
import '~/issuable_context';
import '~/users_select'; import '~/users_select';
import '~/labels_select'; import '~/labels_select';