+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').
+ 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', $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));
+ $('[data-selection-action=copy]').
+ closest('li').
+ toggleClass('disabled',
+ ($checked.filter('[value*=-j7d0g-]').length > 0) ||
+ ($checked.length < 1));
+ $('[data-selection-action=combine-project-contents]').
+ closest('li').
+ toggleClass('disabled',
+ ($checked.filter('[value*=-4zz18-]').length < 1) ||
+ ($checked.length != $checked.filter('[value*=-4zz18-]').length));
+}
+
+$(document).
+ on('selections-updated ready ajax:complete', function() {
+ var $btn = $('[data-selection-action]');
+ $btn.click(dispatch_selection_action);
+ enable_disable_selection_actions.call($btn);
+ });