2017-01-12 00:52:42 -05:00
|
|
|
/* eslint-disable no-param-reassign, func-names, no-var, camelcase, no-unused-vars, object-shorthand, space-before-function-paren, no-return-assign, comma-dangle, consistent-return, one-var, one-var-declaration-per-line, quotes, prefer-template, prefer-arrow-callback, wrap-iife, max-len */
|
2016-12-13 22:01:05 -05:00
|
|
|
/* global Issuable */
|
|
|
|
|
2016-12-15 10:07:41 -05:00
|
|
|
((global) => {
|
2016-07-24 16:45:11 -04:00
|
|
|
var issuable_created;
|
|
|
|
|
|
|
|
issuable_created = false;
|
|
|
|
|
2016-12-15 10:07:41 -05:00
|
|
|
global.Issuable = {
|
2016-07-24 16:45:11 -04:00
|
|
|
init: function() {
|
2016-08-12 05:10:59 -04:00
|
|
|
Issuable.initTemplates();
|
|
|
|
Issuable.initSearch();
|
|
|
|
Issuable.initChecks();
|
2016-08-24 07:46:07 -04:00
|
|
|
Issuable.initResetFilters();
|
2016-10-18 14:03:31 -04:00
|
|
|
Issuable.resetIncomingEmailToken();
|
2016-08-12 05:10:59 -04:00
|
|
|
return Issuable.initLabelFilterRemove();
|
2016-07-24 16:45:11 -04:00
|
|
|
},
|
|
|
|
initTemplates: function() {
|
|
|
|
return Issuable.labelRow = _.template('<% _.each(labels, function(label){ %> <span class="label-row btn-group" role="group" aria-label="<%- label.title %>" style="color: <%- label.text_color %>;"> <a href="#" class="btn btn-transparent has-tooltip" style="background-color: <%- label.color %>;" title="<%- label.description %>" data-container="body"> <%- label.title %> </a> <button type="button" class="btn btn-transparent label-remove js-label-filter-remove" style="background-color: <%- label.color %>;" data-label="<%- label.title %>"> <i class="fa fa-times"></i> </button> </span> <% }); %>');
|
|
|
|
},
|
|
|
|
initSearch: function() {
|
2016-10-07 08:03:01 -04:00
|
|
|
const $searchInput = $('#issuable_search');
|
|
|
|
|
|
|
|
Issuable.initSearchState($searchInput);
|
|
|
|
|
2016-08-26 09:02:25 -04:00
|
|
|
// `immediate` param set to false debounces on the `trailing` edge, lets user finish typing
|
2016-10-07 08:03:01 -04:00
|
|
|
const debouncedExecSearch = _.debounce(Issuable.executeSearch, 1000, false);
|
2016-08-26 09:02:25 -04:00
|
|
|
|
2016-10-07 08:03:01 -04:00
|
|
|
$searchInput.off('keyup').on('keyup', debouncedExecSearch);
|
2016-08-26 09:02:25 -04:00
|
|
|
|
|
|
|
// ensures existing filters are preserved when manually submitted
|
2016-10-07 08:03:01 -04:00
|
|
|
$('#issuable_search_form').on('submit', (e) => {
|
2016-08-26 09:02:25 -04:00
|
|
|
e.preventDefault();
|
|
|
|
debouncedExecSearch(e);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-10-07 08:03:01 -04:00
|
|
|
},
|
|
|
|
initSearchState: function($searchInput) {
|
|
|
|
const currentSearchVal = $searchInput.val();
|
|
|
|
|
|
|
|
Issuable.searchState = {
|
|
|
|
elem: $searchInput,
|
|
|
|
current: currentSearchVal
|
|
|
|
};
|
|
|
|
|
|
|
|
Issuable.maybeFocusOnSearch();
|
|
|
|
},
|
|
|
|
accessSearchPristine: function(set) {
|
|
|
|
// store reference to previous value to prevent search on non-mutating keyup
|
|
|
|
const state = Issuable.searchState;
|
|
|
|
const currentSearchVal = state.elem.val();
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
state.current = currentSearchVal;
|
|
|
|
} else {
|
|
|
|
return state.current === currentSearchVal;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
maybeFocusOnSearch: function() {
|
2016-10-25 04:49:18 -04:00
|
|
|
const currentSearchVal = Issuable.searchState.current;
|
2016-10-25 06:46:28 -04:00
|
|
|
if (currentSearchVal && currentSearchVal !== '') {
|
2016-10-25 04:49:18 -04:00
|
|
|
const queryLength = currentSearchVal.length;
|
|
|
|
const $searchInput = Issuable.searchState.elem;
|
|
|
|
|
|
|
|
/* The following ensures that the cursor is initially placed at
|
|
|
|
* the end of search input when focus is applied. It accounts
|
|
|
|
* for differences in browser implementations of `setSelectionRange`
|
|
|
|
* and cursor placement for elements in focus.
|
|
|
|
*/
|
|
|
|
$searchInput.focus();
|
|
|
|
if ($searchInput.setSelectionRange) {
|
|
|
|
$searchInput.setSelectionRange(queryLength, queryLength);
|
|
|
|
} else {
|
|
|
|
$searchInput.val(currentSearchVal);
|
|
|
|
}
|
2016-10-07 08:03:01 -04:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
},
|
2016-08-26 09:02:25 -04:00
|
|
|
executeSearch: function(e) {
|
|
|
|
const $search = $('#issuable_search');
|
|
|
|
const $searchName = $search.attr('name');
|
|
|
|
const $searchValue = $search.val();
|
|
|
|
const $filtersForm = $('.js-filter-form');
|
|
|
|
const $input = $(`input[name='${$searchName}']`, $filtersForm);
|
2016-10-07 08:03:01 -04:00
|
|
|
const isPristine = Issuable.accessSearchPristine();
|
|
|
|
|
|
|
|
if (isPristine) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-26 09:02:25 -04:00
|
|
|
|
|
|
|
if (!$input.length) {
|
|
|
|
$filtersForm.append(`<input type='hidden' name='${$searchName}' value='${_.escape($searchValue)}'/>`);
|
|
|
|
} else {
|
|
|
|
$input.val($searchValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
Issuable.filterResults($filtersForm);
|
|
|
|
},
|
2016-07-24 16:45:11 -04:00
|
|
|
initLabelFilterRemove: function() {
|
|
|
|
return $(document).off('click', '.js-label-filter-remove').on('click', '.js-label-filter-remove', function(e) {
|
|
|
|
var $button;
|
|
|
|
$button = $(this);
|
2016-07-26 23:32:10 -04:00
|
|
|
// Remove the label input box
|
2016-07-24 16:45:11 -04:00
|
|
|
$('input[name="label_name[]"]').filter(function() {
|
|
|
|
return this.value === $button.data('label');
|
|
|
|
}).remove();
|
2016-07-26 23:32:10 -04:00
|
|
|
// Submit the form to get new data
|
2016-07-24 16:45:11 -04:00
|
|
|
Issuable.filterResults($('.filter-form'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
filterResults: (function(_this) {
|
|
|
|
return function(form) {
|
|
|
|
var formAction, formData, issuesUrl;
|
2016-12-15 10:07:41 -05:00
|
|
|
formData = form.serializeArray();
|
|
|
|
formData = formData.filter(function(data) {
|
|
|
|
return data.value !== '';
|
|
|
|
});
|
|
|
|
formData = $.param(formData);
|
2016-07-24 16:45:11 -04:00
|
|
|
formAction = form.attr('action');
|
|
|
|
issuesUrl = formAction;
|
2017-02-25 07:43:26 -05:00
|
|
|
issuesUrl += "" + (formAction.indexOf('?') === -1 ? '?' : '&');
|
2016-07-24 16:45:11 -04:00
|
|
|
issuesUrl += formData;
|
2017-01-13 16:54:16 -05:00
|
|
|
return gl.utils.visitUrl(issuesUrl);
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
})(this),
|
2016-08-24 07:46:07 -04:00
|
|
|
initResetFilters: function() {
|
|
|
|
$('.reset-filters').on('click', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
const target = e.target;
|
|
|
|
const $form = $(target).parents('.js-filter-form');
|
|
|
|
const baseIssuesUrl = target.href;
|
|
|
|
|
|
|
|
$form.attr('action', baseIssuesUrl);
|
2017-01-13 16:54:16 -05:00
|
|
|
gl.utils.visitUrl(baseIssuesUrl);
|
2016-08-24 07:46:07 -04:00
|
|
|
});
|
|
|
|
},
|
2016-07-24 16:45:11 -04:00
|
|
|
initChecks: function() {
|
|
|
|
this.issuableBulkActions = $('.bulk-update').data('bulkActions');
|
|
|
|
$('.check_all_issues').off('click').on('click', function() {
|
|
|
|
$('.selected_issue').prop('checked', this.checked);
|
|
|
|
return Issuable.checkChanged();
|
|
|
|
});
|
|
|
|
return $('.selected_issue').off('change').on('change', Issuable.checkChanged.bind(this));
|
|
|
|
},
|
|
|
|
checkChanged: function() {
|
2016-08-24 07:46:07 -04:00
|
|
|
const $checkedIssues = $('.selected_issue:checked');
|
2016-09-06 08:49:49 -04:00
|
|
|
const $updateIssuesIds = $('#update_issuable_ids');
|
2016-08-24 07:46:07 -04:00
|
|
|
const $issuesOtherFilters = $('.issues-other-filters');
|
|
|
|
const $issuesBulkUpdate = $('.issues_bulk_update');
|
|
|
|
|
2016-11-29 02:47:02 -05:00
|
|
|
this.issuableBulkActions.willUpdateLabels = false;
|
|
|
|
this.issuableBulkActions.setOriginalDropdownData();
|
|
|
|
|
2016-08-24 07:46:07 -04:00
|
|
|
if ($checkedIssues.length > 0) {
|
2017-01-12 00:52:42 -05:00
|
|
|
const ids = $.map($checkedIssues, function(value) {
|
2016-07-24 16:45:11 -04:00
|
|
|
return $(value).data('id');
|
|
|
|
});
|
2016-08-24 07:46:07 -04:00
|
|
|
$updateIssuesIds.val(ids);
|
|
|
|
$issuesOtherFilters.hide();
|
|
|
|
$issuesBulkUpdate.show();
|
2016-07-24 16:45:11 -04:00
|
|
|
} else {
|
2016-08-24 07:46:07 -04:00
|
|
|
$updateIssuesIds.val([]);
|
|
|
|
$issuesBulkUpdate.hide();
|
|
|
|
$issuesOtherFilters.show();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
return true;
|
2016-10-18 14:03:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
resetIncomingEmailToken: function() {
|
|
|
|
$('.incoming-email-token-reset').on('click', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'PUT',
|
|
|
|
url: $('.incoming-email-token-reset').attr('href'),
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
$('#issue_email').val(response.new_issue_address).focus();
|
|
|
|
},
|
|
|
|
beforeSend: function() {
|
|
|
|
$('.incoming-email-token-reset').text('resetting...');
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
$('.incoming-email-token-reset').text('reset it');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
};
|
2016-12-15 10:07:41 -05:00
|
|
|
})(window);
|