...
Name | Description | Last Modified Date | Download | |
---|---|---|---|---|
Set-SiteClassification | Updates property bag values |
| None16/05/2014 | |
Get-SiteClassification | Gets applied classification | 16/05/2014 | Get-SiteClassification.ps1 | |
Classify.js | A script to inject classification at top of page | 16/05/2014 | classify.js |
Summary
These set of scripts allow a classification to be applied to a SharePoint Site Collection. It is an information only value and does not attempt to control content at any level.
...
Code Block | ||
---|---|---|
| ||
/*
Script by: Tim Wheeler http://tjwheeler.blogspot.com/
This script retrieves the classification properties from the Root Web of the current site collection's property bag.
It then injects html positioned at the top center of the page identifying the content classification.
If the properties are not present or invalid it will show an Unclassified name.
This script should be referenced in the master page: Eg;
<SharePoint:ScriptLink language="javascript" name="~SiteCollection/style library/classify/classify.js" OnDemand="false" runat="server" Localizable="false" />
*/
var spClassify= {};
//Function that makes the client side call to the server
spClassify.getClassification = function(onSuccess, onFailure) {
spClassify.clientContext = SP.ClientContext.get_current();
spClassify.site = spClassify.clientContext.get_site();
spClassify.web = spClassify.site.get_rootWeb();
spClassify.clientContext.load(spClassify.web);
spClassify.properties = spClassify.web.get_allProperties();
spClassify.clientContext.load(spClassify.properties);
spClassify.clientContext.executeQueryAsync(Function.createDelegate(this, onSuccess), Function.createDelegate(this, onFailure));
};
spClassify.renderLink = function(color, backColor, name, url){
$('body').append('<div id="classificationWrapper" style="background:' + backColor + ';border-left:1px solid black;border-bottom:1px solid black;border-right:1px solid black; position:absolute; left:50%;border-bottom-left-radius: 4px;border-bottom-right-radius: 4px; padding-top:1px;padding-left: 5px; padding-right:5px; padding-bottom: 2px; top:0;"></div>');
var link = '<a id="classificationLink" target=_blank; href="' + url + '" style="color:' + color + ';">' + name + '</a>';
$("#classificationWrapper").append(link);
$("#classificationWrapper").append('<label style="color:' + color + '" onclick="$(\'#classificationWrapper\').hide()"> ^</label>');
};
//If successful, this method is called
spClassify.onSuccess = function(sender, args) {
try
{
var color = spClassify.properties.get_item('ClassificationColor'); // '#32B332'
var backColor = spClassify.properties.get_item('ClassificationBackColor'); // '#32B332'
var name = spClassify.properties.get_item('ClassificationName');
var url = spClassify.properties.get_item('ClassificationUrl');
spClassify.renderLink(color, backColor, name, url);
}
catch(e)
{
var color = 'black';
var backColor = 'white';
var name = 'Unclassified';
var url = '';
spClassify.renderLink(color, backColor, name, url);
}
};
//If an error occurs this method is called
spClassify.onFailure = function(sender, args) {
if (args instanceof SP.ClientRequestFailedEventArgs) {
var message = args.get_message();
var code = args.get_errorCode();
var details = args.get_errorDetails();
var value = args.get_errorValue();
var typeName = args.get_errorTypeName();
var stack = args.get_stackTrace();
var correlationId = args.get_errorTraceCorrelationId();
alert('Error: ' + message + ".");
} else {
alert('Unexpected Error accessing classification: ' + args);
}
};
//This method initates the process
function ClassifyThis() {
spClassify.getClassification(spClassify.onSuccess, spClassify.onFailure);
}
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(ClassifyThis, "SP.js");
});
|
...