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'; | |
//Global Variable with namespaces | |
var BasicJSOM = window.BasicJSOM || {}; | |
BasicJSOM.Samples = BasicJSOM.Samples || {}; | |
// 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 () { | |
debugger; | |
BasicJSOM.Samples.SimpleDemo = new BasicJSOM.Samples.WebAndListSamples(); | |
BasicJSOM.Samples.SimpleDemo.getUserName(); | |
BasicJSOM.Samples.SimpleDemo.getLists(); | |
}); | |
BasicJSOM.Samples.WebAndListSamples = function () { | |
//private varables | |
var context = SP.ClientContext.get_current(); | |
var user = context.get_web().get_currentUser(); | |
var lists = context.get_web().get_lists(); | |
//private functions | |
function _getUserName() { | |
$('#message').text('Web Absolute url : ' + _spPageContextInfo.webAbsoluteUrl); | |
context.load(user); | |
context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail); | |
} | |
function onGetUserNameSuccess() { | |
$('#message').append('<br/> User Title :' + user.get_title()); | |
} | |
function onGetUserNameFail(sender, args) { | |
alert('Failed to get user name. Error:' + args.get_message()); | |
} | |
function _getLists() { | |
context.load(lists); | |
context.executeQueryAsync(onGetListSuccess, onGetListFail); | |
} | |
function onGetListSuccess() { | |
$('#message').append('<br/> List Count ' + lists.get_count()); | |
} | |
function onGetListFail(sender, args) { | |
alert('Failed to get list names. Error:' + args.get_message()); | |
} | |
//register public members | |
var publicMembers = { | |
getUserName: _getUserName, | |
getLists: _getLists | |
} | |
return publicMembers; | |
} |
No comments:
Post a Comment