mercredi 25 mars 2015

Manipulating SharePoint UI over an IFrame to add missing clientside Features

I stumbled across a requirement where I had to change the RequestAccessMail via clientside code. This property is not available via CSOM or JSOM. Feature Request

There are several people who asked if this is possible and i havent found an answer that didnt say "no".

Well there is an option. When you are willing to go a quite hacky way, you can do pretty much anything that is possible via the UI when simply emulating UI interaction via JS.

Here's my example for the RequestAccessMail:

//quite dirty hack but at this point the only possibility to set the AccessRequest mail via clientside
function setAccessRequest(mail) {
var iframe = document.createElement('iframe');
//set the setrqacc.aspx link
var setrqaccUrl = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/setrqacc.aspx?type=web';
//create setrqacc.aspx hidden iframe
iframe.setAttribute('src', setrqaccUrl);
iframe.setAttribute('style', 'display:none');
iframe.onload = function () {
//this will fire 2 times - the first time when its initially loaded. the second after the changes were applied (page is reloaded (postback) after the submitbutton is triggered)
var $iframeInput = $('input[id*="_txtEmail"]', $(iframe).contents());
if ($iframeInput.length) {
//initial load - apply settings
//gets iframeInput's parent so the current input can be placed inside
var $iframeBtn = $('input[id*="_btnSubmit"]', $(iframe).contents());
//trigger the post
} else {
//second load - do callback

(Of course the code is wrapped in some warnings to prevent prematurely abortion of the running code)

This is due to the multiple asynch pageloads quite slow, but works fine.

Now here's my question - and yes I know there is no clear answer - Why not doing this for every missing feature in CSOM and JSOM (and every wanted feature that is possible via the UI)?

0 commentaires:

Enregistrer un commentaire