<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Nick,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Did you ever get this one figured out?</div>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="color:rgb(0,0,0); background-color:rgb(255,255,255)">
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> archivesspace_users_group-bounces@lyralists.lyrasis.org <archivesspace_users_group-bounces@lyralists.lyrasis.org> on behalf of Nick Butler
<npwb2@cam.ac.uk><br>
<b>Sent:</b> Tuesday, May 21, 2019 10:10 AM<br>
<b>To:</b> archivesspace_users_group@lyralists.lyrasis.org<br>
<b>Subject:</b> [Archivesspace_Users_Group] Plugin problems: want the Notes section to default to open</font>
<div> </div>
</div>
<div link="#007aa6" vlink="#007aa6" style="text-align:left; direction:ltr; background-color:#ffffff">
<div>Hi all,</div>
<div><br>
</div>
<div>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).</div>
<div><br>
</div>
<div>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:</div>
<div><br>
</div>
<blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid; padding-left:1ex">
<div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
$(function () {</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
</div>
</div>
<div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
var click_the_button = function () {</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
var button = document.querySelector('.btn.btn-sm.btn-default.pull-right.add-note');</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
button.click();</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
};</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
</div>
</div>
<div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
click_the_button();</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
</div>
</div>
<div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
});</div>
</div>
</blockquote>
<div></div>
<div><br>
</div>
<div>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 <a href="https://arcspace-dev.lib.cam.ac.uk/staff/resources/new">
https://arcspace-dev.lib.cam.ac.uk/staff/resources/new</a>, but when the error messages appear this changes to
<a href="https://arcspace-dev.lib.cam.ac.uk/staff/resources">https://arcspace-dev.lib.cam.ac.uk/staff/resources</a>.</div>
<div><br>
</div>
<div>As a test I've changed the click_the_button function to perform another task instead:</div>
<div><br>
</div>
<blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid; padding-left:1ex">
<div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
var click_the_button = function () {</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
var button = document.querySelector('.btn.btn-sm.btn-default.pull-right.add-note');</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
button.style.backgroundColor = 'green';</div>
<div style="color:rgb(76,76,76); font-family:Ubuntu; font-size:14.666666984558105px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:left; text-indent:0px; text-transform:none; widows:auto; word-spacing:0px; background-color:rgb(255,255,255); text-decoration:none">
};</div>
</div>
</blockquote>
<div><br>
</div>
<div></div>
<div>This works exactly as expected, changing the button colour to green. No error messages appear and the URL stays as expected.</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>Many thanks,</div>
<div>Nick</div>
<div><span>
<pre>-- <br></pre>
<div>
<div>
<div><i><font color="#000080" size="4">Nick Butler</font></i></div>
<div><i><font color="#000080" size="4">Software Developer</font></i></div>
<div><i><font color="#000080" size="4">Digital Services</font></i></div>
<div><i><font color="#000080" size="4">Cambridge University Library</font></i></div>
<div><i><font color="#000080" size="4">West Road</font></i></div>
<div><i><font color="#000080" size="4">Cambridge CB3 9DR, UK</font></i></div>
<div><i><font color="#000080" size="4"><br>
</font></i></div>
<div><a href="mailto:npwb2@cam.ac.uk"><i><font color="#000080" size="4">npwb2@cam.ac.uk</font></i></a></div>
<div></div>
</div>
<pre><pre></pre><pre></pre></pre>
<pre><i><font face="monospace" color="#000080" size="4"></font></i></pre>
<pre><i><div><i style="font-family:Ubuntu; font-size:14.666666984558105px"><font color="#000080" size="4">Internal tel: 33067</font></i></div></i></pre>
</div>
<div></div>
<div></div>
</span></div>
</div>
</body>
</html>