//= require jquery //= require jquery_ujs /** Javascript for selection. */ jQuery(function($){ $(document). on('change', '.persistent-selection:checkbox', function(e) { $(document).trigger('selections-updated'); }); $('#selection-form-content').on("click", function(e) { e.stopPropagation(); }); }); add_form_selection_sources = null; select_form_sources = null; (function() { var form_selection_sources = {}; add_form_selection_sources = function (src) { for (var i = 0; i < src.length; i++) { var t = form_selection_sources[src[i].type]; if (!t) { t = form_selection_sources[src[i].type] = {}; } if (!t[src[i].uuid]) { t[src[i].uuid] = src[i]; } } }; select_form_sources = function(type) { var ret = []; if (get_selection_list) { var lst = get_selection_list(); if (lst.length > 0) { var text = "― Selections ―"; var span = document.createElement('span'); span.innerHTML = text; ret.push({text: span.innerHTML, value: "***invalid***"}); for (var i = 0; i < lst.length; i++) { if (lst[i].type == type) { var n = lst[i].name; n = n.replace(/]*>/i, "["); n = n.replace(/<\/span>/i, "]"); ret.push({text: n, value: lst[i].uuid}) } } } } var text = "― Recent ―"; var span = document.createElement('span'); span.innerHTML = text; ret.push({text: span.innerHTML, value: "***invalid***"}); var t = form_selection_sources[type]; for (var key in t) { if (t.hasOwnProperty(key)) { var obj = t[key]; ret.push({text: obj.name, value: obj.uuid}) } } return ret; }; })(); function dispatch_selection_action() { // Build a new "href" attribute for this link by starting with the // "data-href" attribute and appending ?foo[]=bar&foo[]=baz (or // &foo=... as appropriate) to reflect the current object // selections. var data = []; var param_name = $(this).attr('data-selection-param-name'); var href = $(this).attr('data-href'); if ($(this).closest('.disabled').length > 0) { return false; } $(this). closest('.selection-action-container'). find(':checkbox:checked:visible'). each(function() { data.push({name: param_name, value: $(this).val()}); }); if (href.indexOf('?') >= 0) href += '&'; else href += '?'; href += $.param(data, true); $(this).attr('href', href); return true; } function enable_disable_selection_actions() { var $container = $(this).closest('.selection-action-container'); var $checked = $('.persistent-selection:checkbox:checked:visible', $container); $('[data-selection-action]'). closest('div.btn-group-sm'). find('ul li'). toggleClass('disabled', ($checked.length == 0)); $('[data-selection-action=compare]'). closest('li'). toggleClass('disabled', ($checked.filter('[value*=-d1hrv-]').length < 2) || ($checked.not('[value*=-d1hrv-]').length > 0)); <% unless Group.copies_to_projects? %> $('[data-selection-action=copy]'). closest('li'). toggleClass('disabled', ($checked.filter('[value*=-j7d0g-]').length > 0) || ($checked.length < 1)); <% end %> $('[data-selection-action=combine-project-contents]'). closest('li'). toggleClass('disabled', ($checked.filter('[value*=-4zz18-]').length < 1) || ($checked.length != $checked.filter('[value*=-4zz18-]').length)); } function update_selection_actions() { var $btn = $('[data-selection-action]'); $btn.click(dispatch_selection_action); enable_disable_selection_actions.call($btn); } $(document). on('selections-updated ready ajax:complete', function() { var $btn = $('[data-selection-action]'); $btn.click(dispatch_selection_action); enable_disable_selection_actions.call($btn); });