summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issuable.js.es6
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-10-03 09:10:20 +0100
committerPhil Hughes <me@iamphill.com>2016-10-03 09:10:20 +0100
commitcc88fa4d5be9ec0d5fb42f1bb5efa0b82f30a589 (patch)
tree1b9facaf15466aa7f5b0393e97cb1eabfdcafa7e /app/assets/javascripts/issuable.js.es6
parent69db604e55de2bdf1a28c274be6cc9131534517d (diff)
parentf2c0f8237124d2dc539120bd77f301f216453cb7 (diff)
downloadgitlab-ce-cc88fa4d5be9ec0d5fb42f1bb5efa0b82f30a589.tar.gz
Merge branch 'master' into revert-c676283b
Diffstat (limited to 'app/assets/javascripts/issuable.js.es6')
-rw-r--r--app/assets/javascripts/issuable.js.es6109
1 files changed, 109 insertions, 0 deletions
diff --git a/app/assets/javascripts/issuable.js.es6 b/app/assets/javascripts/issuable.js.es6
new file mode 100644
index 00000000000..57f7e4ef230
--- /dev/null
+++ b/app/assets/javascripts/issuable.js.es6
@@ -0,0 +1,109 @@
+(function() {
+ var issuable_created;
+
+ issuable_created = false;
+
+ this.Issuable = {
+ init: function() {
+ Issuable.initTemplates();
+ Issuable.initSearch();
+ Issuable.initChecks();
+ Issuable.initResetFilters();
+ return Issuable.initLabelFilterRemove();
+ },
+ 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() {
+ // `immediate` param set to false debounces on the `trailing` edge, lets user finish typing
+ const debouncedExecSearch = _.debounce(Issuable.executeSearch, 500, false);
+
+ $('#issuable_search').off('keyup').on('keyup', debouncedExecSearch);
+
+ // ensures existing filters are preserved when manually submitted
+ $('#issue_search_form').on('submit', (e) => {
+ e.preventDefault();
+ debouncedExecSearch(e);
+ });
+ },
+ 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);
+
+ if (!$input.length) {
+ $filtersForm.append(`<input type='hidden' name='${$searchName}' value='${_.escape($searchValue)}'/>`);
+ } else {
+ $input.val($searchValue);
+ }
+
+ Issuable.filterResults($filtersForm);
+ },
+ initLabelFilterRemove: function() {
+ return $(document).off('click', '.js-label-filter-remove').on('click', '.js-label-filter-remove', function(e) {
+ var $button;
+ $button = $(this);
+ // Remove the label input box
+ $('input[name="label_name[]"]').filter(function() {
+ return this.value === $button.data('label');
+ }).remove();
+ // Submit the form to get new data
+ Issuable.filterResults($('.filter-form'));
+ });
+ },
+ filterResults: (function(_this) {
+ return function(form) {
+ var formAction, formData, issuesUrl;
+ formData = form.serialize();
+ formAction = form.attr('action');
+ issuesUrl = formAction;
+ issuesUrl += "" + (formAction.indexOf('?') < 0 ? '?' : '&');
+ issuesUrl += formData;
+ return Turbolinks.visit(issuesUrl);
+ };
+ })(this),
+ 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);
+ Turbolinks.visit(baseIssuesUrl);
+ });
+ },
+ 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() {
+ const $checkedIssues = $('.selected_issue:checked');
+ const $updateIssuesIds = $('#update_issuable_ids');
+ const $issuesOtherFilters = $('.issues-other-filters');
+ const $issuesBulkUpdate = $('.issues_bulk_update');
+
+ if ($checkedIssues.length > 0) {
+ let ids = $.map($checkedIssues, function(value) {
+ return $(value).data('id');
+ });
+ $updateIssuesIds.val(ids);
+ $issuesOtherFilters.hide();
+ $issuesBulkUpdate.show();
+ } else {
+ $updateIssuesIds.val([]);
+ $issuesBulkUpdate.hide();
+ $issuesOtherFilters.show();
+ this.issuableBulkActions.willUpdateLabels = false;
+ }
+ return true;
+ }
+ };
+
+}).call(this);