[SOLVED ... kinda] Show Edit, Comment dialog from pages other than issue view

Hello,

I am wondering how could I open the Edit issue dialog programatically. I know how to do it on the issue page, but I would like to do it from elsewhere. I’ve been following this https://developer.atlassian.com/server/jira/platform/displaying-content-in-a-dialog-in-jira/
but it doesn’t seem to work.

Currently, I’m taking several operations from the REST resource for a selected issue, and appending the buttons to the document, some of them work fine, some of the redirect to a new page, but most of them I don’t need.

EDIT: What I mean by doesn’t seem to work is that some of the page data is missing, I guess, and I’m getting an error in the browser console like “x is undefined”. So what I tried to do is actually write own handler for the dialog, and what happened was after using AJS.$.load to load the data into the dialog there the CSS and all the fields would load, however, select2 wasn’t init’d on the fields it was supposed to.
Some googling and I found that $.load strips javascript from the page, but $.ajax should work, so I tried that. The request would go through, I could append the form to the dialog, but now the problem was that there was javascript on the page; some part of JS tries to redefine contextPath global and that breaks the whole page.
I believe I’m missing something obvious, like I have to require an ADM module or there is a parameter I have to pass to “new JIRA.Dialog”, or something similar, but I don’t know where to start.

Weird thing is, issue transitions work perfectly, without custom handling of the dialogs or ajax requests.
I’m also tryna do this for the Assign and Comment form. JS which handles the Assign to me button is not initialized either, but I can init some custom js to select a value in the select on click so that is not a problem.

Another wierd thing is, these dialogs are opened based on the page they fetch using the specified URL in the anchor tag, which is kinda cool. However, other parameters I found on some of these links (like data-issuekey, data-issueid) don’t seem to be taken into consideration when creating a new JIRA.Dialog (after inspection those values turn out to be null), as well as the returnUrl I specifiy to go to the my (current) page, actually points to /browse/ISSUE-KEY. Not a problem since I will handle the Cancel button with a closing operation on the dialog, but still, could it actually be a bug? The behaviour is the same when I open the link in a new tab - the form is displayed, everything works fine, but the “Return to issue” link points to an issue, instead of returnUrl. Is this the desired behaviour, or is it a bug?

EDIT 2: After solution found
So, now I have another problem, and it’s related to the attachment field; what happens is this (after I run JIRA.trigger): “l[z] is not a function”
I inspected the line throwing the error and it looks to be tied to a define directive defining “dndattachment/init” so … This is all I’ve got so far. I’ll update this topic if I find more stuff.

I found the thing I was missing; I remembered how whenever there was a webfragment that I wanted to listen to changes for, I listened to NEW_CONTENT_ADDED, and it would actually reload the stuff on the page.

Which means, that probably should also cause any uninitialized fields to be re-initialized. And yes, maybe it’s luck, but that assumption was correct because you can actually load

jira/secure/EditIssue!default.jspa?id=issueId, find the form and put it into the dialog. The fields (dropdowns and stuff) will be uninitialized, but you can call JIRA.trigger(JIRA.Events.NEW_CONTENT_ADDED, [AJS.$("#DIALOG_ID_HERE"), JIRA.CONTENT_ADDED_REASON.inlineEditStarted]); and initialize the fields.

Cheers!