Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");
- var engLanguage = true;
- // var context = new SP.ClientContext.get_current();
- // var user = context.get_web().get_currentUser();
- var context;
- var user;
- var hostweburl;
- var appweburl;
- var appContextSite;
- var list;
- var employeeList;
- var web;
- var collListItem;
- var collListItem1;
- var collListItem2;
- var isManager = false;
- var requestList;
- var firstLoad = true;
- var tempList = [];
- var link = "https://ejadasharepoint-1786e4322383f6.sharepoint.com/sites/SANSOnlinePortalProject/SANS_HRAppraisalForm/Pages/Default.aspx?SPHostUrl=https%3A%2F%2Fejadasharepoint%2Esharepoint%2Ecom%2Fsites%2FSANSOnlinePortalProject&SPLanguage=en-US&SPClientTag=0&SPProductNumber=16%2E0%2E6601%2E1208&SPAppWebUrl=https%3A%2F%2FEjadaSharePoint-1786e4322383f6%2Esharepoint%2Ecom%2Fsites%2FSANSOnlinePortalProject%2FSANS_HRAppraisalForm";
- var pageLink = "https://ejadasharepoint-1786e4322383fb.sharepoint.com/sites/SANSOnlinePortalProject/SANS_UserInbox/Pages/Default.aspx?SPHostUrl=https%3A%2F%2Fejadasharepoint%2Esharepoint%2Ecom%2Fsites%2FSANSOnlinePortalProject&SPLanguage=en-US&SPClientTag=0&SPProductNumber=16%2E0%2E6614%2E1203&SPAppWebUrl=https%3A%2F%2FEjadaSharePoint-1786e4322383fb%2Esharepoint%2Ecom%2Fsites%2FSANSOnlinePortalProject%2FSANS_UserInbox";
- function initializePage()
- {
- context = new SP.ClientContext.get_current();
- //this.oWeb = context.get_web();
- currentUser = context.get_web().get_currentUser();
- context.load(currentUser);
- context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
- }
- // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
- $(document).ready(function ()
- {
- $('#example').on('click', 'tr', function () {
- var rid = $(this).find('td:first').text();
- var state = $(this).find('td').eq(3).html();
- window.open(link + "?rid=" + rid + "&manager=" + isManager + "&state=" + state, "_self");
- });
- $("#langBtn").click(function ()
- {
- if (localStorage.getItem('lang') == 'en')
- {
- localStorage.setItem('lang', 'ar');
- window.open(pageLink + "&lang=ar", "_self");
- // window.location.href = window.location.pathname + "?" + $.param({ 'lang': 'ar' });
- }
- else
- {
- localStorage.setItem('lang', 'en');
- window.open(pageLink + "&lang=en", "_self");
- // window.location.href = window.location.pathname + "?" + $.param({ 'lang': 'en' });
- }
- //location.reload();
- });
- //getUserName();
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getUrl);
- });
- // This function prepares, loads, and then executes a SharePoint query to get the current users information
- function getUserName()
- {
- context = new SP.ClientContext.get_current();
- user = context.get_web().get_currentUser();
- context.load(user);
- // context.load(user,'Include(Title)');
- context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
- }
- // This function is executed if the above call is successful
- // It replaces the contents of the 'message' element with the user name
- function onGetUserNameSuccess()
- {
- //console.log('Hello '+ user.get_title());
- // $('#message').text('Hello ' + user.get_title());
- }
- // This function is executed if the above call fails
- function onGetUserNameFail(sender, args) {
- alert('Failed to get user name. Error:' + args.get_message());
- }
- //Get the url for the sharepoint site
- function getUrl() {
- hostweburl = getQueryStringParameter("SPHostUrl");
- hostweburl = hostweburl.replace("%2FUserInbox", "");
- appweburl = getQueryStringParameter("SPAppWebUrl");
- hostweburl = decodeURIComponent(hostweburl);
- appweburl = decodeURIComponent(appweburl);
- var scriptbase = hostweburl + "/_layouts/15/";
- $.getScript(scriptbase + "SP.Runtime.js",
- function () {
- $.getScript(scriptbase + "SP.js",
- function () { $.getScript(scriptbase + "SP.RequestExecutor.js", execOperation); }
- );
- }
- );
- // event.preventDefault();
- }
- function execOperation() {
- context = new SP.ClientContext(appweburl);
- var factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
- context.set_webRequestExecutorFactory(factory);
- appContextSite = new SP.AppContextSite(context, hostweburl);
- web = appContextSite.get_web();
- context.load(web);
- context.executeQueryAsync(getEmployeeInfo, onFail);
- }
- function getEmployeeInfo()
- {
- employeeList = web.get_lists().getByTitle("Employees");
- var camlQuery = new SP.CamlQuery();
- camlQuery.set_viewXml(
- "<View><Query><Where><Eq><FieldRef Name='EmployeeName' /><Value Type='User'>" + user.get_title() + "</Value></Eq></Where></Query></View>"
- );
- collListItem1 = employeeList.getItems(camlQuery);
- context.load(collListItem1);
- context.executeQueryAsync(getEmployeeType, onFail);
- }
- function getEmployeeType()
- {
- var listItemInfo = '';
- var listItemEnumerator = collListItem1.getEnumerator();
- while (listItemEnumerator.moveNext()) {
- var oListItem = listItemEnumerator.get_current();
- console.log(oListItem.get_item('EmployeeName'));
- listItemInfo += '\n Employee: ' + oListItem.get_item('EmployeeName')['$5K_1'];
- if (oListItem.get_item('EmployeeType') == "Manager") {
- isManager = true;
- }
- }
- context.executeQueryAsync(getRequestList, onFail);
- }
- function getRequestList()
- {
- list = web.get_lists().getByTitle("AppraisalRequests");
- var camlQuery = new SP.CamlQuery();
- if (isManager == true)
- {
- camlQuery.set_viewXml(
- "<View><Query><Where><Eq><FieldRef Name='Manager' /><Value Type='User'>" + user.get_title() + "</Value></Eq></Where></Query></View>"
- );
- }
- else
- {
- camlQuery.set_viewXml(
- "<View><Query><Where><Eq><FieldRef Name='Employee' /><Value Type='User'>" + user.get_title() + "</Value></Eq></Where></Query></View>"
- );
- }
- collListItem = list.getItems(camlQuery);
- context.load(collListItem);
- context.executeQueryAsync(fillRequests, onFail);
- }
- function fillRequests()
- {
- var listItemEnumerator = collListItem.getEnumerator();
- //var table = document.getElementById("example").getElementsByTagName('tbody')[0];
- var table = $('#example').DataTable();
- if (firstLoad) {
- $("#example tbody tr").remove();
- firstLoad = false;
- }
- while (listItemEnumerator.moveNext())
- {
- var oListItem = listItemEnumerator.get_current();
- table.row.add([oListItem.get_item('RequestID'), oListItem.get_item('Employee').get_lookupValue(), oListItem.get_item('Manager').get_lookupValue(), oListItem.get_item('RequestStatus'), oListItem.get_item('RequestDate')]).draw();
- }
- }
- // This function is executed if the above call fails
- function onFail(sender, args) {
- alert(args.get_message());
- }
- function getQueryStringParameter(paramToRetrieve) {
- var params =
- document.URL.split("?")[1].split("&");
- for (var i = 0; i < params.length; i = i + 1) {
- var singleParam = params[i].split("=");
- if (singleParam[0] == paramToRetrieve)
- return singleParam[1];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement