Created
March 17, 2015 15:52
-
-
Save pariz/c0dccb9f9a90222dfe99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var context = SP.ClientContext.get_current(); | |
var user = context.get_web().get_currentUser(); | |
var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl")); | |
var appWebUrl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl")); | |
var PeopleID = ''; | |
$(document).ready(function() { | |
ExecuteOrDelayUntilScriptLoaded(StartThread, "sp.js"); | |
}); | |
function StartThread() { | |
PeopleID = GetUserName; | |
$("#MyTest").text(PeopleID); | |
$("#DagensData").text(GetToDaysPlanInstances('2015-02-28', PeopleID)); | |
} | |
function GetUserName() { | |
var TempUserName = '0001'; | |
//context.load(user); | |
//context.executeQueryAsync(function () {TempUserName = user.get_title(); }, function () { TempUserName = "Error" }); | |
var TempPeopleID = String(); | |
$.ajax({ | |
url: appWebUrl + "/_api/lists/getbytitle('tbl_People')/items?$top=5&$filter=PeopleNumber%20eq%20'" + TempUserName + " '", | |
method: "GET", | |
async: false, | |
headers: { | |
"Accept": "application/json; odata=verbose" | |
}, | |
success: function(data) { | |
if (data.d.results.length > 0) { | |
TempPeopleID = data.d.results[0].PeopleID; | |
} else { | |
TempPeopleID = "Error getting user" | |
} | |
} | |
}); | |
return TempPeopleID | |
} | |
function getQueryStringParameter(urlParameterKey) { | |
var params = document.URL.split('?')[1].split('&'); | |
var strParams = ''; | |
for (var i = 0; i < params.length; i = i + 1) { | |
var singleParam = params[i].split('='); | |
if (singleParam[0] == urlParameterKey) | |
return decodeURIComponent(singleParam[1]); | |
} | |
} | |
function GetToDaysPlanInstances(DateToFetch, PeopleIDToFetch) { | |
var MyResultSet; | |
var startDate = new Date(DateToFetch); | |
startDate.setHours(0); | |
startDate.setMinutes(0); | |
startDate.setSeconds(0); | |
startDate.setMilliseconds(0); | |
var stopDate = new Date(startDate); | |
stopDate.setDate(stopDate.getDate() + 2); | |
var MySearchString = appWebUrl + "/_api/web/lists/getbytitle('tbl_PlanInstances')/items?$filter=StopDateTime%20lt%20datetime'" + stopDate.toJSON() + "'%20and%20StartDateTime%20gt%20datetime'" + startDate.toJSON() + "'%20and%20PeopleID%20eq%20" + PeopleIDToFetch + "&$orderby=StartDateTime%20asc"; | |
$.ajax({ | |
url: MySearchString, | |
method: "GET", | |
async: false, | |
headers: { | |
"Accept": "application/json; odata=verbose" | |
}, | |
success: function(data) { | |
MyResultSet = data.d.results | |
} | |
}); | |
return MyResultSet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment