window.REDMINE_EXTENSIONS = {
toggleDiv: function (el_or_id) {
var el;
if (typeof(el_or_id) === 'string') {
el = $('#' + el_or_id);
} else {
el = el_or_id;
}
el.toggleClass('collapsed').slideToggle('fast');
},
toggleDivAndChangeOpen: function (toggleElementId, changeOpenElement) {
REDMINE_EXTENSIONS.toggleDiv(toggleElementId);
$(changeOpenElement).toggleClass('open');
},
toggleFilterButtons: function (elButtonsID, elFilter1ID, elFilter2ID) {
var elButtons = $('#' + elButtonsID);
var elFilter1 = $('#' + elFilter1ID);
var elFilter2 = $('#' + elFilter2ID);
if (elFilter1.hasClass('collapsed') && elFilter2.hasClass('collapsed')) {
elButtons.slideUp('slow');
} else {
elButtons.slideDown('slow');
}
}
};
window.showFlashMessage = (function (type, message, delay) {
var $content = $("#content");
$content.find(".flash").remove();
var element = document.createElement("div");
element.className = 'fixed flash ' + type;
element.style.position = 'fixed';
element.style.zIndex = '10001';
element.style.right = '5px';
element.style.top = '5px';
element.setAttribute("onclick", "closeFlashMessage($(this))");
var close = document.createElement("a");
close.className = 'icon-close close-icon';
close.setAttribute("href", "javascript:void(0)");
close.style.float = 'right';
close.style.marginLeft = '5px';
// close.setAttribute("onclick", "closeFlashMessage($(this))");
var span = document.createElement("span");
span.innerHTML = message;
element.appendChild(close);
element.appendChild(span);
$content.prepend(element);
var $element = $(element);
if (delay) {
setTimeout(function () {
window.requestAnimationFrame(function () {
closeFlashMessage($element);
});
}, delay);
}
return $element;
});
window.closeFlashMessage = (function ($element) {
$element.closest('.flash').fadeOut(500, function () {
$element.remove();
});
});
EasyGem.schedule.require(function () {
$.widget('easy.easymultiselect', {
options: {
source: null,
rootElement: null, // rootElement in the response from source
selected: null,
multiple: true, // multiple values can be selected
preload: true, // load all possible values
position: {collision: 'flip'},
autofocus: false,
combo: false,
inputName: null, // defaults to element prop name
render_item: function (ul, item) {
return $("
")
.data("item.autocomplete", item)
.text(item.label)
.appendTo(ul);
},
activate_on_input_click: true,
load_immediately: false,
show_toggle_button: true,
select_first_value: true,
autocomplete_options: {},
multiselectOnChange: null // onchange of multiselect input function
},
_create: function () {
this.selectedValues = this.options.selected;
this._createUI();
this.expanded = false;
this.valuesLoaded = false;
this.afterLoaded = [];
if (Array.isArray(this.options.source)) {
this.options.preload = true;
this._initData(this.options.source);
} else if (this.options.preload && this.options.load_immediately) {
this.load();
} else if (this.selectedValues) {
this.setValue(this.selectedValues);
}
},
_createUI: function () {
var that = this;
this.element.wrap('');
this.tag = this.element.parent();
this.inputName = this.options.inputName || this.element.prop('name');
if (this.options.multiple) { // multiple values
this.valueElement = $('');
this.tag.after(this.valueElement);
if (this.options.show_toggle_button)
this._createToggleButton();
this.valueElement.entityArray({
inputNames: this.inputName,
afterRemove: function (entity) {
that.element.trigger('change');
}
});
} else { //single value
this.valueElement = $('', {type: 'hidden', name: this.inputName});
this.element.after(this.valueElement);
}
this._createAutocomplete();
if (!this.options.multiple) {
this.element.css('margin-right', 0);
}
},
setMultiselectOnChange: function (fn) {
this.options.multiselectOnChange = fn;
},
multiselectOnChange: function(select, fn) {
if (fn) select.on("change", fn);
},
_createToggleButton: function () {
var that = this;
this.link_ac_toggle = $('').attr('class', 'icon icon-add clear-link');
this.link_ac_toggle.click(function (evt) {
var $elem = $(this);
evt.preventDefault();
that.load(function () {
var select = $('