[Archivesspace_Users_Group] Plugin problems: want the Notes section to default to open

Nick Butler npwb2 at cam.ac.uk
Mon Jun 3 04:18:04 EDT 2019


Hi Blake,

Eventually I stumbled across some relevant code in the user_defined_in_basic plugin (https://github.com/hudmol/user_defined_in_basic/blob/master/frontend/assets/user_defined_in_basic.js, lines 17-18). I don't understand why the window.scrollTo(0,0); is necessary but adding it to my plugin after the .click() seems to prevent the problem - the button is clicked as if with a mouse. Would you happen to know whether this is expected behaviour, or why this seemingly (to someone with very limited JS knowledge) rather hacky fix works?

Many thanks,
Nick

-----Original Message-----
From: Blake Carver <blake.carver at lyrasis.org<mailto:Blake%20Carver%20%3cblake.carver at lyrasis.org%3e>>
Reply-To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org<mailto:Archivesspace%20Users%20Group%20%3carchivesspace_users_group at lyralists.lyrasis.org%3e>>
To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org<mailto:Archivesspace%20Users%20Group%20%3carchivesspace_users_group at lyralists.lyrasis.org%3e>>
Subject: Re: [Archivesspace_Users_Group] Plugin problems: want the Notes section to default to open
Date: Fri, 31 May 2019 16:56:03 +0000

Hi Nick,
Did you ever get this one figured out?
________________________________
From: archivesspace_users_group-bounces at lyralists.lyrasis.org <archivesspace_users_group-bounces at lyralists.lyrasis.org> on behalf of Nick Butler <npwb2 at cam.ac.uk>
Sent: Tuesday, May 21, 2019 10:10 AM
To: archivesspace_users_group at lyralists.lyrasis.org
Subject: [Archivesspace_Users_Group] Plugin problems: want the Notes section to default to open

Hi all,

We're trying to write a plugin to default the Notes section of the new and edit resources pages to being open (i.e. as if the "Add Note" button had been clicked automatically when the page loaded).

I've got a layout_head.html.erb file which loads the appropriate js file in the correct page, my difficulty just comes from getting the button to click without creating errors. Here are the contents of my js file:

$(function () {
  var click_the_button = function () {
    var button = document.querySelector('.btn.btn-sm.btn-default.pull-right.add-note');
    button.click();
  };
  click_the_button();
});

When the page loads I get the error messages seen in my attached screenshot. I've also tried requiring notes.crud.js and simply running the createTopLevelNote function, but this gives precisely the same error messages. Note that the URL for creating a new resource is https://arcspace-dev.lib.cam.ac.uk/staff/resources/new, but when the error messages appear this changes to https://arcspace-dev.lib.cam.ac.uk/staff/resources.

As a test I've changed the click_the_button function to perform another task instead:

var click_the_button = function () {
    var button = document.querySelector('.btn.btn-sm.btn-default.pull-right.add-note');
   button.style.backgroundColor = 'green';
  };

This works exactly as expected, changing the button colour to green. No error messages appear and the URL stays as expected.

I haven't found any other plugins that do something like this (and I know very little Javascript!) so I'm at a loss here. Any advice or links to relevant documentation would be greatly appreciated.

Many thanks,
Nick

--

Nick Butler
Software Developer
Digital Services
Cambridge University Library
West Road
Cambridge CB3 9DR, UK

npwb2 at cam.ac.uk<mailto:npwb2 at cam.ac.uk>

Internal tel: 33067

_______________________________________________

Archivesspace_Users_Group mailing list

Archivesspace_Users_Group at lyralists.lyrasis.org<mailto:Archivesspace_Users_Group at lyralists.lyrasis.org>

http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group


--

Nick Butler
Software Developer
Digital Services
Cambridge University Library
West Road
Cambridge CB3 9DR, UK

npwb2 at cam.ac.uk<mailto:npwb2 at cam.ac.uk>

Internal tel: 33067
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20190603/6763c5e7/attachment.html>


More information about the Archivesspace_Users_Group mailing list