Posts tonen met het label HTML. Alle posts tonen
Posts tonen met het label HTML. Alle posts tonen

zondag 24 juni 2012

Get User Roles, Security groups on Client site


Last week I figgered out how to know in which security group the logged-on user has access to 
in order to show or hide some fields or ribbon items. 
For example to prevent to show All Site Contents in the action menu.

Below some code that does the work for you... have fun with it ;)
 

<script src="/scripts/jquery-1.7.min.js" type="text/javascript"></script>
<script src="/scripts/jquery.SPServices-0.7.0.js" type="text/javascript"></script>
<script type="text/javascript">

 getCurrentUserRole();
 function getCurrentUserRole() {
  $().SPServices({
   operation: "GetGroupCollectionFromUser",
   userLoginName: $().SPServices.SPGetCurrentUser(),
   async: false,
   completefunc: function (xData, Status) {

    if( Status == "success") {
     //alert(xData.responseText);
     $(xData.responseXML).find("Group").each(function () {
      if ($(this).attr("Name") == "DevSite Owners")
      {
       alert("write access");
      }
      else
      {
       // wrong access hide some stuff... for example the Site Action link.
       $("#siteactiontd").hide();
       // hide the global navigation folder
       $("#GlobalBreadCrumbNavPopout-anchor").hide();
      }//alert($(this).attr("Name"));
     });
    }
   }
  });
 }
</script>
 

donderdag 5 april 2012

Block Excape and Ctrl+z keypress to prevent the undo action by keyboard


One of the disadvantages of using Jscript of JQuery is when a user uses 
the Escape or CTRL+z on his keyboard that 
your actions, like filling in input fields, in your scripting are being undone.

So best option in this case is to prevent that thoose events are being executed.
This you can do by capturing the keypresses of the Escape key and the CTRL+z key combination.
The script below will execute on the document Keydown event. 

 function DisableEscAndCtrlZ(){
  document.onkeydown = function(evt) {
   evt = evt || window.event;
   // ctrl+z
   if (evt.ctrlKey && evt.keyCode == 90) {
    return false;  
   }
   // esc
   if (evt.keyCode == 27) {
    return false;  
   }
  };
 }

 $(document).ready( function() {
  DisableEscAndCtrlZ();
 };
 

zaterdag 31 maart 2012

Custom Cancel button, Go Back to the web-page you came from ...

Nice to have against the Close or Save button is a beautifull Cancel button. 
A request of a customer this week was to have a link on there intranet 
to a sharepoint custom new page, but without the Sharepoint header and menu. 

So people could add items in a list, but nothing else more. 

On the page the Sharepoint Close/Cancel button returns automatically back to 
the Sharepoint List. But what the customer wanted was that the requester 
returned back to the page where they came from or, 
if the page was openend in a new window, to close the window.

To do this, replace the Sharepoint Close/Cancel button with our own custum buttom.
add a little script in a content Editor webpart to execute the return function (goback).



<input type="button" value="Cancel" name="CancelButton" class="ms-ButtonHeightWidth" onclick="goback();" />

// in content editor webpart:
function goback() {
    // Jumps back
            //history.back();
            if (history.length >0)
            {
                        history.back();
            }
            else
            {
                        window.close();
            }
}