Skip to content

Commit

Permalink
Update batch update paged display to submit correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lfarrell committed Feb 6, 2024
1 parent ffb5db1 commit d0a5061
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
22 changes: 11 additions & 11 deletions static/js/admin/src/PagedDisplayForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ define('PagedDisplayForm', [ 'jquery', 'jquery-ui', 'underscore', 'RemoteStateCh
'ModalLoadingOverlay', 'AbstractForm', 'AlertHandler'],
function($, ui, _, RemoteStateChangeMonitor, pagedDisplayForm, ModalLoadingOverlay, AbstractForm) {

var defaultOptions = {
let defaultOptions = {
title : 'Edit View Settings',
createFormTemplate : pagedDisplayForm,
submitMethod: 'PUT'
Expand All @@ -15,27 +15,27 @@ define('PagedDisplayForm', [ 'jquery', 'jquery-ui', 'underscore', 'RemoteStateCh
PagedDisplayForm.prototype.constructor = PagedDisplayForm;
PagedDisplayForm.prototype = Object.create(AbstractForm.prototype);

PagedDisplayForm.prototype.preprocessForm = function(resultObject) {
var newViewSetting = $("#view_settings_change", this.$form).val();
var pids = $("#paged_display_targets", this.$form).val();
this.action_url = "/services/api/edit/view_settings?targets=" + pids + "&direction=" + encodeURIComponent(newViewSetting);
PagedDisplayForm.prototype.preprocessForm = function() {
let newViewSetting = $('#view_settings_change', this.$form).val();
let pids = $('#paged_display_targets', this.$form).val();
this.action_url = `/services/api/edit/view_settings?targets=${encodeURIComponent(pids)}&direction=${encodeURIComponent(newViewSetting)}`;
};

PagedDisplayForm.prototype.validationErrors = function() {
var errors = [];
var viewSetting = $("#view_settings_change", this.$form).val();
PagedDisplayForm.prototype.validationErrors = function(resultObject) {
let errors = [];
let viewSetting = $('#view_settings_change', this.$form).val();
// Validate input
if (!viewSetting)
errors.push("You must specify a view setting.");
errors.push('You must specify a view setting.');
return errors;
};

PagedDisplayForm.prototype.getSuccessMessage = function(data) {
return "View settings settings have been successfully edited.";
return 'View settings settings have been successfully edited.';
};

PagedDisplayForm.prototype.getErrorMessage = function(data) {
return "An error occurred while editing the view settings";
return 'An error occurred while editing the view settings';
};

PagedDisplayForm.prototype.remove = function() {
Expand Down
35 changes: 28 additions & 7 deletions static/js/admin/src/action/UpdatePagedDisplayBatchAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ define('UpdatePagedDisplayBatchAction', [ 'jquery', 'AbstractBatchAction', "tpl!
};

UpdatePagedDisplayBatchAction.prototype.execute = function() {
let self = this;
let targets = this.getTargets();
var UpdatePagedDisplayForm = pagedDisplayTemplate({
let UpdatePagedDisplayForm = pagedDisplayTemplate({
options: { targets: this.formatTargets(targets) },
metadata: { viewSettings: 'individual' }
});

this.dialog = $("<div class='containingDialog'>" + UpdatePagedDisplayForm + "</div>");
this.dialog.dialog({
autoOpen: true,
Expand All @@ -27,20 +29,39 @@ define('UpdatePagedDisplayBatchAction', [ 'jquery', 'AbstractBatchAction', "tpl!
modal: true,
title: `Edit View Settings for ${targets.length} object(s)`
});

this.$form = this.dialog.first();
this.$form.submit(function(e) {
let newViewSetting = $('#view_settings_change', self.$form).val();
let pids = $('#paged_display_targets', self.$form).val();

$.ajax({
url: `/services/api/edit/view_settings?targets=${encodeURIComponent(pids)}&direction=${encodeURIComponent(newViewSetting)}`,
type: 'PUT',
contentType: 'application/json; charset=utf-8',
dataType: 'json'
}).done(function (response) {
self.context.view.$alertHandler.alertHandler('message', response.message);
self.dialog.remove();
}).fail(function () {
self.context.view.$alertHandler.alertHandler('error', `Failed to update view settings ${targets.length}objects`);
});

AbstractBatchAction.prototype.execute.call(this);
e.preventDefault();
});
}

UpdatePagedDisplayBatchAction.prototype.formatTargets = function(targets) {
return targets.filter(function(d) {
return d.metadata.type === 'Work';
}).map(function(d) {
return d.metadata.id;
}).join(',');
return targets.filter(d => d.metadata.type === 'Work')
.map(d => d.metadata.id)
.join(',');
}

UpdatePagedDisplayBatchAction.prototype.doWork = function() {
this.actionHandler.addEvent({
action : 'PagedDisplay',
confirm : false
});
};

return UpdatePagedDisplayBatchAction;
Expand Down

0 comments on commit d0a5061

Please sign in to comment.