Monday, 23 July 2018

Graph Access token without login in sharepoint online




function GraphAccessToken()
{
    var deferred = new jQuery.Deferred();
    var requestHeaders = {
        'X-RequestDigest': $("#__REQUESTDIGEST").val(),
        "accept": "application/json;odata=nometadata",
        "content-type": "application/json;odata=nometadata"
    };
    var resourceData = {
        "resource": "https://graph.microsoft.com",
    };
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.OAuth.Token/Acquire",
        headers: requestHeaders,
        type: "POST",
        data: JSON.stringify(resourceData),
        success: function (data) {
            var msGraphToken = data.access_token;
            GetSharedWithMeDocument(msGraphToken);
            deferred.resolve(msGraphToken);
        },
        error: function (jqxr, errorCode, errorThrown) {
            console.log(jqxr.responseText);
            deferred.reject(jqxr.responseText);
        }
    });
    return deferred.promise();
}


function GetSharedWithMeDocument(token)
{
        var odurl = "https://graph.microsoft.com/v1.0/me/drive/sharedWithMe"
       // var thumbnailSize = "large"
      //  var odquery = "?expand=thumbnails,children(expand=thumbnails(select=" + thumbnailSize + "))";
        $.ajax({
            url: odurl,
            dataType: 'json',
            headers: { "Authorization": "Bearer " + token },
            accept: "application/json;odata.metadata=none",
            success: function (data)
            {
                var trCollection = "";
                if (data)
                {
                    for(var itemIndex=0;itemIndex<data.value.length;itemIndex++)
                    {                   
                        trCollection += "<tr><td>" + iconlink + "</td><td>" + data.value[itemIndex].remoteItem.shared.sharedDateTime + "</td><td>" + data.value[itemIndex].lastModifiedBy.user.displayName + "</td></tr>";
                    }
                }
                $("#oneDriveSharedWithTableBody").html('');
                $("#oneDriveSharedWithTableBody").append(trCollection);
            }           
        });
}

Monday, 16 July 2018

Print using Jquery

Print using Jquery





<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
var htmlContentPrint="";
$(document).ready(function(){
       $("#btnPrint").click(function () {
        var divPrint = document.getElementById('modelBox');
        var tableElements = $(divPrint).find('.ui.table');
        $(tableElements).each(function (i) {
            $($(tableElements)[i]).attr('style', 'width:100%');
            $($(tableElements)[i]).attr('border', '1');
        });
        var newWindow = window.open('', 'Print-Window');
        newWindow.document.open();
        htmlContentPrint = '<html><head>'+
            '<link type="text/css" media="print,screen" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.11/semantic.min.css"></link></head><body onload="window.print()">' + divPrint.innerHTML + '</body></html>';
        newWindow.document.write(htmlContentPrint);
        newWindow.document.close();
        setTimeout(function () { newWindow.close(); }, 10);
    });
});
</script>

<input id="btnPrint" type="button" value="Print" />
<div id="modelBox">
<table class="ui table">
    <thead>
<tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
</thead>
    <tbody>
<tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
<tr>
        <td>Mary</td>
        <td>Moe</td>
        <td>mary@example.com</td>
      </tr>
<tr>
        <td>July</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
</tbody>
  </table>
</div>