define('jira/autocomplete/user-autocomplete', ['jira/autocomplete/rest-autocomplete', 'jira/data/parse-options-from-fieldset', 'jira/util/browser', 'jira/util/elements', 'jira/util/objects', 'wrm/context-path', 'jquery'], function (RESTAutoComplete, parseOptionsFromFieldset, Browser, Elements, Objects, wrmContextPath, jQuery) { 'use strict'; var contextPath = wrmContextPath(); /** * User picker - converted from YUI based autocomplete. There is some code in here that probably isn't necessary, * if removed though selenium tests would need to be re-written. * @class UserAutoComplete * @extends RESTAutoComplete * @param {Object} options */ var UserAutoComplete = function UserAutoComplete(options) { /** @lends UserAutoComplete.prototype */ var that = Objects.begetObject(RESTAutoComplete); that.getAjaxParams = function () { return { url: contextPath + "/rest/api/1.0/users/picker", data: { fieldName: options.fieldID, fieldConfigId: options.fieldConfigID, projectId: options.projectId }, dataType: "json", type: "GET" }; }; /** * Returns true if the field's containing form has the 'submitted' class. * * @param field The reference to the field whose form to check for the 'submitted' class. * @return {Boolean} */ function fieldsFormHasBeenSubmitted(field) { var submitting = false; var form = field.closest("form"); if (form.length && form.hasClass("submitting")) { submitting = true; } return submitting; } /** * Create html elements from JSON object * @param {Object} response - JSON object * @returns {Array} Multidimensional array, one column being the html element and the other being its * corresponding complete value. */ that.renderSuggestions = function (response) { if (fieldsFormHasBeenSubmitted(this.field) || !Browser.isSelenium() && !Elements.elementIsFocused(this.field)) { return false; } var resultsContainer; var suggestionNodes = []; // remove previous results this.clearResponseContainer(); if (response && response.users && response.users.length > 0) { resultsContainer = jQuery("