X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/19c20b239f9d88f6fd4dab542524143f24cc8536..95c228e25cd1a483ec391a9b2c5d6fb048f620f1:/apps/workbench/app/assets/javascripts/select_modal.js
diff --git a/apps/workbench/app/assets/javascripts/select_modal.js b/apps/workbench/app/assets/javascripts/select_modal.js
index 0a6aad311f..19cf3cd927 100644
--- a/apps/workbench/app/assets/javascripts/select_modal.js
+++ b/apps/workbench/app/assets/javascripts/select_modal.js
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
$(document).on('click', '.selectable', function() {
var any;
var $this = $(this);
@@ -8,14 +12,19 @@ $(document).on('click', '.selectable', function() {
removeClass('active');
}
$this.toggleClass('active');
- any = ($container.
+
+ if (!$this.hasClass('use-preview-selection')) {
+ any = ($container.
find('.selectable.active').length > 0)
- $this.
+ }
+
+ if (!$container.hasClass('preview-selectable-container')) {
+ $this.
closest('.modal').
find('[data-enable-if-selection]').
prop('disabled', !any);
- if ($this.hasClass('active')) {
+ if ($this.hasClass('active')) {
var no_preview_available = '
(No preview available)';
if (!$this.attr('data-preview-href')) {
$(".modal-dialog-preview-pane").html(no_preview_available);
@@ -30,27 +39,60 @@ $(document).on('click', '.selectable', function() {
fail(function(data, status, jqxhr) {
$(".modal-dialog-preview-pane").html(no_preview_available);
});
+ }
+ } else {
+ any = ($container.
+ find('.preview-selectable.active').length > 0)
+ $(this).
+ closest('.modal').
+ find('[data-enable-if-selection]').
+ prop('disabled', !any);
}
}).on('click', '.modal button[data-action-href]', function() {
var selection = [];
var data = [];
var $modal = $(this).closest('.modal');
+ var http_method = $(this).attr('data-method').toUpperCase();
var action_data = $(this).data('action-data');
+ var action_data_from_params = $(this).data('action-data-from-params');
var selection_param = action_data.selection_param;
$modal.find('.modal-error').removeClass('hide').hide();
- $modal.find('.selectable.active[data-object-uuid]').each(function() {
+
+ var $preview_selections = $modal.find('.preview-selectable.active');
+ if ($preview_selections.length > 0) {
+ data.push({name: selection_param, value: $preview_selections.first().attr('href')});
+ }
+
+ if (data.length == 0) { // not using preview selection option
+ $modal.find('.selectable.active[data-object-uuid]').each(function() {
var val = $(this).attr('data-object-uuid');
data.push({name: selection_param, value: val});
- });
- $.each(action_data, function(key, value) {
- data.push({name: key, value: value});
- });
+ });
+ }
+ $.each($.extend({}, action_data, action_data_from_params),
+ function(key, value) {
+ if (value instanceof Array && key[-1] != ']') {
+ for (var i in value) {
+ data.push({name: key + '[]', value: value[i]});
+ }
+ } else {
+ data.push({name: key, value: value});
+ }
+ });
+ if (http_method === 'PATCH') {
+ // Some user agents do not support HTTP PATCH (notably,
+ // phantomjs silently ignores our "data" and sends an empty
+ // request body) so we use POST instead, and supply a
+ // _method=PATCH param to tell Rails what we really want.
+ data.push({name: '_method', value: http_method});
+ http_method = 'POST';
+ }
$.ajax($(this).attr('data-action-href'),
{dataType: 'json',
- type: $(this).attr('data-method'),
+ type: http_method,
data: data,
- traditional: true,
+ traditional: false,
context: {modal: $modal, action_data: action_data}}).
fail(function(jqxhr, status, error) {
if (jqxhr.readyState == 0 || jqxhr.status == 0) {
@@ -61,8 +103,9 @@ $(document).on('click', '.selectable', function() {
message = "Request failed.";
}
this.modal.find('.modal-error').
- html('' + message + '
').
- show();
+ html('').
+ show().
+ children().text(message);
}).
done(function(data, status, jqxhr) {
var event_name = this.action_data.success;
@@ -72,12 +115,16 @@ $(document).on('click', '.selectable', function() {
});
}).on('click', '.chooser-show-project', function() {
var params = {};
+ var project_uuid = $(this).attr('data-project-uuid');
$(this).attr('href', '#'); // Skip normal click handler
- if ($(this).attr('data-project-uuid')) {
- params = {'filters[]': JSON.stringify(['owner_uuid',
- '=',
- $(this).attr('data-project-uuid')])};
+ if (project_uuid) {
+ params = {'filters': [['owner_uuid',
+ '=',
+ project_uuid]],
+ 'project_uuid': project_uuid
+ };
}
+ $(".modal-dialog-preview-pane").html("");
// Use current selection as dropdown button label
$(this).
closest('.dropdown-menu').
@@ -85,32 +132,37 @@ $(document).on('click', '.selectable', function() {
html($(this).text() + ' ');
// Set (or unset) filter params and refresh filterable rows
$($(this).closest('[data-filterable-target]').attr('data-filterable-target')).
- data('infinite-content-params', params).
+ data('infinite-content-params-from-project-dropdown', params).
trigger('refresh-content');
}).on('ready', function() {
- $('form[data-search-modal] *').on('click keyup paste', function() {
- // When user types, pastes, or clicks the top nav Search
- // input, ask the server for a Search modal. When it arrives,
- // copy the search string from the top nav input into the
- // modal's search query field.
- var $form = $(this).closest('form');
- var $a;
+ $('form[data-search-modal] a').on('click', function() {
+ $(this).closest('form').submit();
+ return false;
+ });
+ $('form[data-search-modal]').on('submit', function() {
+ // Ask the server for a Search modal. When it arrives, copy
+ // the search string from the top nav input into the modal's
+ // search query field.
+ var $form = $(this);
+ var searchq = $form.find('input').val();
+ var is_a_uuid = /^([0-9a-f]{32}(\+\S+)?|[0-9a-z]{5}-[0-9a-z]{5}-[0-9a-z]{15})$/;
+ if (searchq.trim().match(is_a_uuid)) {
+ window.location = '/actions?uuid=' + encodeURIComponent(searchq.trim());
+ // Show the "loading" indicator. TODO: better page transition hook
+ $(document).trigger('ajax:send');
+ return false;
+ }
if ($form.find('a[data-remote]').length > 0) {
// A search dialog is already loading.
- return;
+ return false;
}
- $a = $('').
- attr('href', $form.attr('data-search-modal')).
+ $('').
+ attr('data-remote-href', $form.attr('data-search-modal')).
attr('data-remote', 'true').
attr('data-method', 'GET').
hide().
appendTo($form).
on('ajax:success', function(data, status, xhr) {
- // Move the dialog to the top of the window to prevent
- // a well timed click on the top nav search box from
- // closing the dialog as soon as it opens.
- $('body > .modal-container .modal-dialog').
- css('margin-top', '0');
$('body > .modal-container input[type=text]').
val($form.find('input').val()).
focus();