Liferay.FirmsSelector  = new Class({
/*
params.instanceVar: the instance variable for this class
params.hiddenInput: the hidden input used to pass in the current tags
params.textInput: the text input for users to add tags
params.summarySpan: the summary span tos how the current tags
params.curTags: comma delimited string of current tags
params.focus: true if the text input should be focused
*/
initialize: function(params) {
var instance = this;
instance._curTags = [];
instance.params = params;
var hiddenInput = jQuery('#' + params.hiddenInput);
hiddenInput.attr('name', hiddenInput.attr('id'));
var textInput = jQuery('#' + params.textInput);
textInput.Autocomplete(
{
source: instance._getTags,
delay: 0,
fx: {
type: 'slide',
duration: 700
},
autofill: true,
dataSourceType: 'json',
helperClass: 'autocomplete-box',
selectClass: 'autocomplete-selected',
multiple: false,
mutipleSeparator: ',',
minchars: 2,
onSelect: function(option) {
if (this.createTextRange) {
var value = this.value;
var textRange = this.createTextRange();
textRange.moveStart('character', value.length);
textRange.select();
}
},
onShow: function() {
jQuery(this).addClass('showing-list');
},
onHide: function() {
jQuery(this).removeClass('showing-list');
}
}
);
instance._popupVisible = false;
instance._setupSelectTags();
if (params.focus) {
textInput.focus();
}
if (params.curTags != '') {
instance._curTags = params.curTags.split(',');
instance._update();
}
Liferay.Util.actsAsAspect(window);
window.before(
'submitForm',
function() {
var val = jQuery.trim(textInput.val());
if (val.length) {
addTagButton.trigger('click');
}
}
);
},
_getTags: function(data) {
data.value = data.value || '';
return Liferay.Service.feedback.Firm.searchAutocomplete(
{
name: "" + data.value + "%",
end: 15
}
);
},
_setupSelectTags: function() {
var instance = this;
var params = instance.params;
var ns = params.instanceVar;
var input = jQuery('#' + ns + 'selectTag');
input.click(
function() {
instance._showSelectPopup();
}
);
}
});