Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var outerObject = outerObject || {};
- SP.SOD.executeFunc("sp.js");
- //These functions taken from the internet
- function getUrlVars() {
- var vars = [], hash;
- var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
- for (var i = 0; i < hashes.length; i++) {
- hash = hashes[i].split('=');
- vars.push(hash[0]);
- vars[hash[0]] = hash[1];
- }
- return vars;
- };
- function getUrlVar(name) {
- return getUrlVars()[name];
- };
- var hostWebUrl = decodeURIComponent(getUrlVar('SPHostUrl'));
- var appWebUrl = decodeURIComponent(getUrlVar('SPAppWebUrl'));
- jQuery.getScript(
- hostWebUrl + "/_layouts/15/SP.RequestExecutor.js",
- continueExecution
- );
- function continueExecution() {
- //Begin Create Site Portion
- outerObject.CreateSite = outerObject.CreateSite ||
- function CreateSite(event) {
- SP.SOD.executeFunc("sp.js");
- // Get App and Host context (don't be confused that the object name has the word 'app' in it)
- var appContext = SP.ClientContext.get_current();
- var hostContext = new SP.AppContextSite(appContext, hostWebUrl);
- // Create variables, object, and properties for sub-site
- //debugger;
- var userSiteName = $("#userInputSiteName").val();
- var userSiteCode = $("#userInputSiteCode").val();
- var newSiteDetails = new SP.WebCreationInformation();
- newSiteDetails.set_title(userSiteName);
- newSiteDetails.set_url(userSiteCode);
- newSiteDetails.set_language(1033);
- newSiteDetails.set_webTemplate("CASESTUDYMONMORN#0");
- // Create the Site URL
- var siteUrl = String.format(hostWebUrl + "/" + userSiteCode);
- // Get the web site and site Collection from host site and add sub-site
- var website = hostContext.get_web();
- var webCollection = website.get_webs();
- webCollection.add(newSiteDetails);
- // execute query
- $("#messageToUser").text("Working on it...");
- $("#messageToUserArea").css("color", "black");
- $("#messageToUserArea").css("display", "block");
- appContext.set_requestTimeout(10*60*100000);
- appContext.executeQueryAsync(successSubsiteCreation, failSubsiteCreation);
- function successSubsiteCreation(sender, args) {
- $("#messageToUser").html("Success creating project site '" + userSiteName + "' at <a href='" + siteUrl + "'>" + siteUrl + "</a>.");
- $("#messageToUserArea").css("color","green");
- $("#messageToUserArea").css("display", "block");
- }
- function failSubsiteCreation(sender, args) {
- $("#messageToUser").text("Error occurred while attempting to create site " + userSiteName + " at URL " + siteUrl + ". \n" + args.get_message() + "\n" + args.get_stackTrace() + "\n" + args.get_errorDetails());
- $("#messageToUserArea").css("color", "red");
- $("#messageToUserArea").css("display", "block");
- }
- }
- }
Add Comment
Please, Sign In to add comment