Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure datasource url is complete and better handle insertions to chi… #2761

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 37 additions & 22 deletions frontend/app/assets/javascripts/archival_objects.crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ ParentPickingRenderer.prototype.get_new_node_template = function () {
return this.newNodeTemplate.clone(false);
};

ParentPickingRenderer.prototype.add_node_columns = function (row, node) {
ResourceRenderer.prototype.add_node_columns.call(this, row, node);
// undo the TreeIDs hash fragment inserted when the row was rendered
row.find('.record-title').attr('href', '#');
};

function TreeLinkingModal(config) {
var self = this;
self.config = config;
Expand All @@ -61,7 +67,7 @@ function TreeLinkingModal(config) {
self.$modal.find('#addSelectedButton').addClass('disabled');
self.position = 0;
let datasource_url =
'/resources/' + config.root_record_uri.replace(/.*\//, '') + '/tree';
RESOURCES_URL + '/' + config.root_record_uri.replace(/.*\//, '') + '/tree';
self.datasource = new TreeDataSource(datasource_url);
self.renderer = new ParentPickingRenderer();
self.$container = $('.linker-container');
Expand All @@ -72,7 +78,31 @@ function TreeLinkingModal(config) {
config.root_record_uri,
true,
self.renderer,
function () {
function (rootNode) {
self.$container.find('.record-title').attr('href', '#');
function menuSelectHandler(level) {
// remove any existing placeholder row
if (self.inserted_row != undefined) {
self.inserted_row.remove();
}
inserted_row = self.renderer.get_new_node_template();
inserted_row.addClass('largetree-node indent-level-' + level);
inserted_row.addClass('spawn-placeholder');
inserted_row.addClass('current');
inserted_row.find('button.expandme').css('visibility', 'hidden');
inserted_row.find('.title').append($(SPAWN_PLACEHOLDER_TEXT));
self.inserted_row = inserted_row;
self.$modal.find('#addSelectedButton').removeClass('disabled');
if (self.menu) {
self.menu.remove();
}
}
if (rootNode.child_count == 0) {
// this will be an only child of the root record, so no need to choose anything
menuSelectHandler(1);
self.$container.find('.root-row').after(self.inserted_row);
return;
}
self.$container.on('click', '.expandme', function (e) {
e.preventDefault();
e.stopPropagation();
Expand Down Expand Up @@ -145,24 +175,7 @@ function TreeLinkingModal(config) {
return true;
});

function menuSelectHandler(level) {
// remove any existing placeholder row
if (self.inserted_row != undefined) {
self.inserted_row.remove();
}
inserted_row = self.renderer.get_new_node_template();
inserted_row.addClass('largetree-node indent-level-' + level);
inserted_row.addClass('spawn-placeholder');
inserted_row.addClass('current');
inserted_row.find('button.expandme').css('visibility', 'hidden');
inserted_row.find('.title').append($(SPAWN_PLACEHOLDER_TEXT));
self.inserted_row = inserted_row;
self.$modal.find('#addSelectedButton').removeClass('disabled');
self.menu.remove();
}

self.menu.on('click', '.add-items-before', function () {
console.log('add items before');
menuSelectHandler(self.selected_row.data('level'));
self.selected_row.before(self.inserted_row);
if (
Expand Down Expand Up @@ -229,6 +242,7 @@ function TreeLinkingModal(config) {

self.$modal.on('click', '#addSelectedButton', function (event) {
event.preventDefault();
// parent_uri may be undef but position should always be an int
self.config.onLink(self.parent_uri, self.position);
// closing this way to get proper focus back in main window
$('.modal-header a', self.$modal).trigger('click');
Expand Down Expand Up @@ -495,6 +509,10 @@ function validateResourceAndParent() {
title: $parentInput.data('modal-title'),
primary_button_text: $parentInput.data('modal-title'),
onLink: function (parent_uri, position) {
$positionInput.val(position);
if (parent_uri == undefined) {
return;
}
let parent_id = parent_uri.replace(/.*\//, '');
let locationParams = location.href.split('?')[1];
locationParams = new URLSearchParams(locationParams);
Expand All @@ -506,9 +524,6 @@ function validateResourceAndParent() {
);
$parentInput.attr('name', 'archival_object[parent][ref]');
$parentInput.val(parent_uri);
$positionInput.val(position);

validateResourceAndParent();
},
});
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/assets/javascripts/largetree.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
this.errorHandler = $.noop;

this.initEventHandlers();
this.renderRoot(function () {
tree_loaded_callback();
this.renderRoot(function (rootNode) {
tree_loaded_callback(rootNode);
});
}

Expand Down Expand Up @@ -581,14 +581,14 @@

rootList.append(row);
self.appendWaypoints(row, null, rootNode.waypoints, rootNode.waypoint_size, 1);

/* Remove any existing table */
self.elt.find('div.root').remove();

self.elt.prepend(rootList);
self.renderer.add_root_columns(row, rootNode);
if (done_callback) {
done_callback();
/* Note that this will fire before the waypoint nodes are loaded */
done_callback(rootNode);
}
});
};
Expand Down
8 changes: 5 additions & 3 deletions frontend/app/views/archival_objects/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
end
%>

var ENUMERATION_TRANSLATIONS = <%== translations.to_json %>;
const ENUMERATION_TRANSLATIONS = <%== translations.to_json %>;

var EnumerationTranslations = {
const EnumerationTranslations = {
t : function(enumeration, enumeration_value) {
if (ENUMERATION_TRANSLATIONS.hasOwnProperty(enumeration)) {
if (ENUMERATION_TRANSLATIONS[enumeration].hasOwnProperty(enumeration_value)) {
Expand All @@ -31,7 +31,9 @@
}
};

var SPAWN_PLACEHOLDER_TEXT = <%== I18n.t("archival_object._frontend.messages.spawn_placeholder").to_json %>;
const SPAWN_PLACEHOLDER_TEXT = <%== I18n.t("archival_object._frontend.messages.spawn_placeholder").to_json %>;

const RESOURCES_URL = '<%= url_for(:controller => :resources, :action => :index) %>';

<%
spawn_menu = {
Expand Down