2017-01-12 00:38:39 -05:00
|
|
|
/* 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 */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global GitLab */
|
|
|
|
/* global UsersSelect */
|
|
|
|
/* global ZenMode */
|
|
|
|
/* global Autosave */
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
2017-01-11 23:27:41 -05:00
|
|
|
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; };
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
this.IssuableForm = (function() {
|
|
|
|
IssuableForm.prototype.issueMoveConfirmMsg = 'Are you sure you want to move this issue to another project?';
|
|
|
|
|
|
|
|
IssuableForm.prototype.wipRegex = /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i;
|
|
|
|
|
|
|
|
function IssuableForm(form) {
|
|
|
|
var $issuableDueDate;
|
|
|
|
this.form = form;
|
|
|
|
this.toggleWip = bind(this.toggleWip, this);
|
|
|
|
this.renderWipExplanation = bind(this.renderWipExplanation, this);
|
|
|
|
this.resetAutosave = bind(this.resetAutosave, this);
|
|
|
|
this.handleSubmit = bind(this.handleSubmit, this);
|
2016-10-12 23:33:09 -04:00
|
|
|
gl.GfmAutoComplete.setup();
|
2016-07-24 16:45:11 -04:00
|
|
|
new UsersSelect();
|
|
|
|
new ZenMode();
|
|
|
|
this.titleField = this.form.find("input[name*='[title]']");
|
|
|
|
this.descriptionField = this.form.find("textarea[name*='[description]']");
|
|
|
|
this.issueMoveField = this.form.find("#move_to_project_id");
|
|
|
|
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();
|
|
|
|
this.initMoveDropdown();
|
|
|
|
$issuableDueDate = $('#issuable-due-date');
|
|
|
|
if ($issuableDueDate.length) {
|
|
|
|
$('.datepicker').datepicker({
|
|
|
|
dateFormat: 'yy-mm-dd',
|
|
|
|
onSelect: function(dateText, inst) {
|
|
|
|
return $issuableDueDate.val(dateText);
|
|
|
|
}
|
|
|
|
}).datepicker('setDate', $.datepicker.parseDate('yy-mm-dd', $issuableDueDate.val()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IssuableForm.prototype.initAutosave = function() {
|
|
|
|
new Autosave(this.titleField, [document.location.pathname, document.location.search, "title"]);
|
|
|
|
return new Autosave(this.descriptionField, [document.location.pathname, document.location.search, "description"]);
|
|
|
|
};
|
|
|
|
|
|
|
|
IssuableForm.prototype.handleSubmit = function() {
|
2016-09-09 13:36:48 -04:00
|
|
|
var fieldId = (this.issueMoveField != null) ? this.issueMoveField.val() : null;
|
2017-01-12 00:38:39 -05:00
|
|
|
if ((parseInt(fieldId, 10) || 0) > 0) {
|
2016-07-24 16:45:11 -04:00
|
|
|
if (!confirm(this.issueMoveConfirmMsg)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.resetAutosave();
|
|
|
|
};
|
|
|
|
|
|
|
|
IssuableForm.prototype.resetAutosave = function() {
|
|
|
|
this.titleField.data("autosave").reset();
|
|
|
|
return this.descriptionField.data("autosave").reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
IssuableForm.prototype.initWip = function() {
|
|
|
|
this.$wipExplanation = this.form.find(".js-wip-explanation");
|
|
|
|
this.$noWipExplanation = this.form.find(".js-no-wip-explanation");
|
|
|
|
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() {
|
|
|
|
return this.wipRegex.test(this.titleField.val());
|
|
|
|
};
|
|
|
|
|
|
|
|
IssuableForm.prototype.renderWipExplanation = function() {
|
|
|
|
if (this.workInProgress()) {
|
|
|
|
this.$wipExplanation.show();
|
|
|
|
return this.$noWipExplanation.hide();
|
|
|
|
} else {
|
|
|
|
this.$wipExplanation.hide();
|
|
|
|
return this.$noWipExplanation.show();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IssuableForm.prototype.toggleWip = function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
if (this.workInProgress()) {
|
|
|
|
this.removeWip();
|
|
|
|
} else {
|
|
|
|
this.addWip();
|
|
|
|
}
|
|
|
|
return this.renderWipExplanation();
|
|
|
|
};
|
|
|
|
|
|
|
|
IssuableForm.prototype.removeWip = function() {
|
|
|
|
return this.titleField.val(this.titleField.val().replace(this.wipRegex, ""));
|
|
|
|
};
|
|
|
|
|
|
|
|
IssuableForm.prototype.addWip = function() {
|
|
|
|
return this.titleField.val("WIP: " + (this.titleField.val()));
|
|
|
|
};
|
|
|
|
|
|
|
|
IssuableForm.prototype.initMoveDropdown = function() {
|
2016-08-05 09:29:20 -04:00
|
|
|
var $moveDropdown, pageSize;
|
2016-07-24 16:45:11 -04:00
|
|
|
$moveDropdown = $('.js-move-dropdown');
|
|
|
|
if ($moveDropdown.length) {
|
2016-08-05 09:29:20 -04:00
|
|
|
pageSize = $moveDropdown.data('page-size');
|
2016-07-24 16:45:11 -04:00
|
|
|
return $('.js-move-dropdown').select2({
|
|
|
|
ajax: {
|
|
|
|
url: $moveDropdown.data('projects-url'),
|
2016-08-05 09:29:20 -04:00
|
|
|
quietMillis: 125,
|
|
|
|
data: function(term, page, context) {
|
2016-07-24 16:45:11 -04:00
|
|
|
return {
|
2016-08-05 09:29:20 -04:00
|
|
|
search: term,
|
|
|
|
offset_id: context
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
},
|
2016-08-05 09:29:20 -04:00
|
|
|
results: function(data) {
|
|
|
|
var context,
|
|
|
|
more;
|
|
|
|
|
|
|
|
if (data.length >= pageSize)
|
|
|
|
more = true;
|
|
|
|
|
|
|
|
if (data[data.length - 1])
|
|
|
|
context = data[data.length - 1].id;
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return {
|
2016-08-05 09:29:20 -04:00
|
|
|
results: data,
|
|
|
|
more: more,
|
|
|
|
context: context
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
formatResult: function(project) {
|
|
|
|
return project.name_with_namespace;
|
|
|
|
},
|
|
|
|
formatSelection: function(project) {
|
|
|
|
return project.name_with_namespace;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return IssuableForm;
|
|
|
|
})();
|
|
|
|
}).call(this);
|