2016-11-15 09:08:06 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, no-undef, no-new, padded-blocks, max-len */
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
|
|
|
this.GLForm = (function() {
|
|
|
|
function GLForm(form) {
|
|
|
|
this.form = form;
|
|
|
|
this.textarea = this.form.find('textarea.js-gfm-input');
|
2016-07-26 23:32:10 -04:00
|
|
|
// Before we start, we should clean up any previous data for this form
|
2016-07-24 16:45:11 -04:00
|
|
|
this.destroy();
|
2016-07-26 23:32:10 -04:00
|
|
|
// Setup the form
|
2016-07-24 16:45:11 -04:00
|
|
|
this.setupForm();
|
|
|
|
this.form.data('gl-form', this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLForm.prototype.destroy = function() {
|
2016-07-26 23:32:10 -04:00
|
|
|
// Clean form listeners
|
2016-07-24 16:45:11 -04:00
|
|
|
this.clearEventListeners();
|
|
|
|
return this.form.data('gl-form', null);
|
|
|
|
};
|
|
|
|
|
|
|
|
GLForm.prototype.setupForm = function() {
|
|
|
|
var isNewForm;
|
|
|
|
isNewForm = this.form.is(':not(.gfm-form)');
|
|
|
|
this.form.removeClass('js-new-note-form');
|
|
|
|
if (isNewForm) {
|
|
|
|
this.form.find('.div-dropzone').remove();
|
|
|
|
this.form.addClass('gfm-form');
|
2016-07-26 23:32:10 -04:00
|
|
|
// remove notify commit author checkbox for non-commit notes
|
2016-09-05 23:28:59 -04:00
|
|
|
gl.utils.disableButtonIfEmptyField(this.form.find('.js-note-text'), this.form.find('.js-comment-button'));
|
2016-07-31 21:37:15 -04:00
|
|
|
GitLab.GfmAutoComplete.setup(this.form.find('.js-gfm-input'));
|
2016-07-24 16:45:11 -04:00
|
|
|
new DropzoneInput(this.form);
|
|
|
|
autosize(this.textarea);
|
2016-07-26 23:32:10 -04:00
|
|
|
// form and textarea event listeners
|
2016-07-24 16:45:11 -04:00
|
|
|
this.addEventListeners();
|
|
|
|
gl.text.init(this.form);
|
|
|
|
}
|
2016-07-26 23:32:10 -04:00
|
|
|
// hide discard button
|
2016-07-24 16:45:11 -04:00
|
|
|
this.form.find('.js-note-discard').hide();
|
|
|
|
return this.form.show();
|
|
|
|
};
|
|
|
|
|
|
|
|
GLForm.prototype.clearEventListeners = function() {
|
|
|
|
this.textarea.off('focus');
|
|
|
|
this.textarea.off('blur');
|
|
|
|
return gl.text.removeListeners(this.form);
|
|
|
|
};
|
|
|
|
|
|
|
|
GLForm.prototype.addEventListeners = function() {
|
|
|
|
this.textarea.on('focus', function() {
|
|
|
|
return $(this).closest('.md-area').addClass('is-focused');
|
|
|
|
});
|
|
|
|
return this.textarea.on('blur', function() {
|
|
|
|
return $(this).closest('.md-area').removeClass('is-focused');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return GLForm;
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
}).call(this);
|