2017-01-11 22:49:57 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, quotes, consistent-return, no-new, prefer-arrow-callback, no-return-assign, one-var, one-var-declaration-per-line, object-shorthand, comma-dangle, no-else-return, newline-per-chained-call, no-shadow, vars-on-top, prefer-template, max-len */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global ProjectSelect */
|
|
|
|
|
2017-03-11 01:45:34 -05:00
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
|
|
|
this.Project = (function() {
|
|
|
|
function Project() {
|
2017-07-25 06:56:41 -04:00
|
|
|
const $cloneOptions = $('ul.clone-options-dropdown');
|
|
|
|
const $projectCloneField = $('#project_clone');
|
|
|
|
const $cloneBtnText = $('a.clone-dropdown-btn span');
|
|
|
|
|
2017-08-03 09:11:17 -04:00
|
|
|
const selectedCloneOption = $cloneBtnText.text().trim();
|
|
|
|
if (selectedCloneOption.length > 0) {
|
|
|
|
$(`a:contains('${selectedCloneOption}')`, $cloneOptions).addClass('is-active');
|
|
|
|
}
|
|
|
|
|
2017-07-25 06:56:41 -04:00
|
|
|
$('a', $cloneOptions).on('click', (e) => {
|
|
|
|
const $this = $(e.currentTarget);
|
|
|
|
const url = $this.attr('href');
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
2017-08-03 09:11:17 -04:00
|
|
|
$('.is-active', $cloneOptions).not($this).removeClass('is-active');
|
|
|
|
$this.toggleClass('is-active');
|
2017-07-25 06:56:41 -04:00
|
|
|
$projectCloneField.val(url);
|
|
|
|
$cloneBtnText.text($this.text());
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return $('.clone').text(url);
|
|
|
|
});
|
2016-07-26 23:32:10 -04:00
|
|
|
// Ref switcher
|
2016-07-24 16:45:11 -04:00
|
|
|
this.initRefSwitcher();
|
|
|
|
$('.project-refs-select').on('change', function() {
|
|
|
|
return $(this).parents('form').submit();
|
|
|
|
});
|
|
|
|
$('.hide-no-ssh-message').on('click', function(e) {
|
2016-10-24 17:54:38 -04:00
|
|
|
Cookies.set('hide_no_ssh_message', 'false');
|
2016-07-24 16:45:11 -04:00
|
|
|
$(this).parents('.no-ssh-key-message').remove();
|
|
|
|
return e.preventDefault();
|
|
|
|
});
|
|
|
|
$('.hide-no-password-message').on('click', function(e) {
|
2016-10-24 17:54:38 -04:00
|
|
|
Cookies.set('hide_no_password_message', 'false');
|
2016-07-24 16:45:11 -04:00
|
|
|
$(this).parents('.no-password-message').remove();
|
|
|
|
return e.preventDefault();
|
|
|
|
});
|
|
|
|
this.projectSelectDropdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
Project.prototype.projectSelectDropdown = function() {
|
|
|
|
new ProjectSelect();
|
|
|
|
$('.project-item-select').on('click', (function(_this) {
|
|
|
|
return function(e) {
|
|
|
|
return _this.changeProject($(e.currentTarget).val());
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
return $('.js-projects-dropdown-toggle').on('click', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return $('.js-projects-dropdown').select2('open');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Project.prototype.changeProject = function(url) {
|
|
|
|
return window.location = url;
|
|
|
|
};
|
|
|
|
|
|
|
|
Project.prototype.initRefSwitcher = function() {
|
2017-02-03 12:53:36 -05:00
|
|
|
var refListItem = document.createElement('li');
|
|
|
|
var refLink = document.createElement('a');
|
2016-11-02 07:31:00 -04:00
|
|
|
|
|
|
|
refLink.href = '#';
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return $('.js-project-refs-dropdown').each(function() {
|
|
|
|
var $dropdown, selected;
|
|
|
|
$dropdown = $(this);
|
|
|
|
selected = $dropdown.data('selected');
|
|
|
|
return $dropdown.glDropdown({
|
|
|
|
data: function(term, callback) {
|
|
|
|
return $.ajax({
|
|
|
|
url: $dropdown.data('refs-url'),
|
|
|
|
data: {
|
2016-11-02 07:11:47 -04:00
|
|
|
ref: $dropdown.data('ref'),
|
|
|
|
search: term
|
2016-08-01 18:07:08 -04:00
|
|
|
},
|
|
|
|
dataType: "json"
|
2016-07-24 16:45:11 -04:00
|
|
|
}).done(function(refs) {
|
|
|
|
return callback(refs);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
selectable: true,
|
|
|
|
filterable: true,
|
2016-11-02 07:11:47 -04:00
|
|
|
filterRemote: true,
|
2016-07-24 16:45:11 -04:00
|
|
|
filterByText: true,
|
2017-08-05 16:03:48 -04:00
|
|
|
inputFieldName: $dropdown.data('input-field-name'),
|
2016-08-01 18:07:08 -04:00
|
|
|
fieldName: $dropdown.data('field-name'),
|
2016-07-24 16:45:11 -04:00
|
|
|
renderRow: function(ref) {
|
2016-11-02 07:31:00 -04:00
|
|
|
var li = refListItem.cloneNode(false);
|
2016-11-02 07:11:47 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
if (ref.header != null) {
|
2016-11-02 07:11:47 -04:00
|
|
|
li.className = 'dropdown-header';
|
|
|
|
li.textContent = ref.header;
|
2016-07-24 16:45:11 -04:00
|
|
|
} else {
|
2016-11-02 07:31:00 -04:00
|
|
|
var link = refLink.cloneNode(false);
|
|
|
|
|
2016-11-03 08:25:08 -04:00
|
|
|
if (ref === selected) {
|
2016-11-02 07:31:00 -04:00
|
|
|
link.className = 'is-active';
|
|
|
|
}
|
|
|
|
|
2016-11-03 08:16:15 -04:00
|
|
|
link.textContent = ref;
|
|
|
|
link.dataset.ref = ref;
|
2016-11-02 07:11:47 -04:00
|
|
|
|
|
|
|
li.appendChild(link);
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2016-11-02 07:31:00 -04:00
|
|
|
|
2016-11-02 07:11:47 -04:00
|
|
|
return li;
|
2016-07-24 16:45:11 -04:00
|
|
|
},
|
|
|
|
id: function(obj, $el) {
|
|
|
|
return $el.attr('data-ref');
|
|
|
|
},
|
|
|
|
toggleLabel: function(obj, $el) {
|
|
|
|
return $el.text().trim();
|
|
|
|
},
|
2017-05-04 08:11:15 -04:00
|
|
|
clicked: function(options) {
|
|
|
|
const { e } = options;
|
2017-01-10 17:54:56 -05:00
|
|
|
e.preventDefault();
|
2016-08-03 04:08:24 -04:00
|
|
|
if ($('input[name="ref"]').length) {
|
2017-01-11 22:49:57 -05:00
|
|
|
var $form = $dropdown.closest('form');
|
2017-07-28 13:36:07 -04:00
|
|
|
|
|
|
|
var $visit = $dropdown.data('visit');
|
2017-08-15 15:53:41 -04:00
|
|
|
var shouldVisit = $visit ? true : $visit;
|
2017-01-11 22:49:57 -05:00
|
|
|
var action = $form.attr('action');
|
2017-02-25 07:43:26 -05:00
|
|
|
var divider = action.indexOf('?') === -1 ? '?' : '&';
|
2017-08-01 09:41:24 -04:00
|
|
|
if (shouldVisit) {
|
2017-08-15 14:16:42 -04:00
|
|
|
gl.utils.visitUrl(`${action}${divider}${$form.serialize()}`);
|
2017-07-28 13:36:07 -04:00
|
|
|
}
|
2016-08-03 04:08:24 -04:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return Project;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|