jslink only renders when I engage cisar inspector - sharepoint

Cisar verifies the jslink is getting called correctly but rendering only happens when I open the file with the cisar inspector. Weird.
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Header = "<div class='row'><div class='col-md- 8'>Title</div><div class='col-md-1'>Screen 16x9</div><div class='col-md-1'>Print</div><div class='col-md-2'>Updated</div>";
overrideCtx.Templates.Footer = "</div>";
overrideCtx.Templates.Item = CustomItem;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
function CustomItem(ctx) {
// Build a listitem entry for every announcement in the list.
var ret = "<div class='col-md-8'>" + ctx.CurrentItem.Title + "</div><div class='col-md-1'><a href='https://domain/subsite/library/" + ctx.CurrentItem.FileLeafRef + "'><i class='fa fa-tv fa-2x'></i></a></div><div class='col-md-1'><a href='" + ctx.CurrentItem.Print_x0020_4x3 + "'><i class='fa fa-print fa-2x'></i></a> </div>" "<div class='col-md-2'>" + ctx.CurrentItem.Updated + " </div>"
;
return ret;
}

Related

Use client side rendering(js link) for dynamically created Sharepoint document library

I want to use client side rendering(js link) for document library, the challenge for me is Sharepoint document library will be created dynamically when the remote event receiver triggers.
I know we need to pass js link reference in elements.xml file, but in my case list will be created later, so how can I achieve it?
Thanks in advance.
You can add script (JSLink) programmatically, after your condition event receiver:
C#:
using (SPSite site = new SPSite("http://sp/sites/test"))
{
SPWeb web = site.RootWeb;
SPFile page = web.GetFile("SitePages/Test.aspx");
page.CheckOut();
using (SPLimitedWebPartManager wpmgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
XmlElement p = new XmlDocument().CreateElement("p");
p.InnerText = "<script type='text/javascript'>alert('Hello World');</script>";
ContentEditorWebPart cewp = new ContentEditorWebPart
{
Content = p
};
wpmgr.AddWebPart(cewp, "Header", 0);
}
page.CheckIn(String.Empty);
}
JS:
var siteUrl = '/sites/MySiteCollection';
var serverRelativeUrl = '/sites/MySiteCollection/Default.aspx';
function addWebPart() {
var clientContext = new SP.ClientContext(siteUrl);
var oFile = clientContext.get_web().getFileByServerRelativeUrl(serverRelativeUrl);
var limitedWebPartManager = oFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
var webPartXml = '<?xml version=\"1.0\" encoding=\"utf-8\"?>' +
'<WebPart xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"' +
' xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"' +
' xmlns=\"http://schemas.microsoft.com/WebPart/v2\">' +
'<Title>My Web Part</Title><FrameType>Default</FrameType>' +
'<Description>Use for formatted text, tables, and images.</Description>' +
'<IsIncluded>true</IsIncluded><ZoneID></ZoneID><PartOrder>0</PartOrder>' +
'<FrameState>Normal</FrameState><Height /><Width /><AllowRemove>true</AllowRemove>' +
'<AllowZoneChange>true</AllowZoneChange><AllowMinimize>true</AllowMinimize>' +
'<AllowConnect>true</AllowConnect><AllowEdit>true</AllowEdit>' +
'<AllowHide>true</AllowHide><IsVisible>true</IsVisible><DetailLink /><HelpLink />' +
'<HelpMode>Modeless</HelpMode><Dir>Default</Dir><PartImageSmall />' +
'<MissingAssembly>Cannot import this Web Part.</MissingAssembly>' +
'<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge><IsIncludedFilter />' +
'<Assembly>Microsoft.SharePoint, Version=13.0.0.0, Culture=neutral, ' +
'PublicKeyToken=94de0004b6e3fcc5</Assembly>' +
'<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>' +
'<ContentLink xmlns=\"http://schemas.microsoft.com/WebPart/v2/ContentEditor\">' + '/sites/SiteAssets/Test.js</ContentLink>' +
'<Content xmlns=\"http://schemas.microsoft.com/WebPart/v2/ContentEditor\">' +
'<![CDATA[This is a first paragraph!<DIV> </DIV>And this is a second paragraph.]]></Content>' +
'<PartStorage xmlns=\"http://schemas.microsoft.com/WebPart/v2/ContentEditor\" /></WebPart>';
var oWebPartDefinition = limitedWebPartManager.importWebPart(webPartXml);
this.oWebPart = oWebPartDefinition.get_webPart();
limitedWebPartManager.addWebPart(oWebPart, 'Left', 1);
clientContext.load(oWebPart);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Web Part added: ' + oWebPart.get_title());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

Sharepoint 2013 - Fetch last modified date of the list

Trying to fetch the last modified time of Sharepoint list. Found a code that states the author and modified by. It was working fine when it had the line
<input id="btnGetFieldUserValue" onclick="getFieldUserValue()" type="button" value="Get Created by and Modified by"/>
but when i changed to
<div id="create" onload="getFieldUserValue()">  </div>
No repose in the content editor webpart of sharepoint 2013.
Help.
My task is to show the last updation time of the list. Any other way to do that, please share.
var listItem;
var list;
var clientContext;
function getFieldUserValue() {
this.clientContext = SP.ClientContext.get_current();
if (this.clientContext != undefined && clientContext != null) {
var webSite = clientContext.get_web();
this.list = webSite.get_lists().getByTitle("Resource Readiness");
this.listItem = list.getItemById(1);
clientContext.load(this.listItem);
this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
}
function OnLoadSuccess(sender, args) {
var fieldUserValueCreatedBy = this.listItem.get_item("Author");
var fieldUserValueModifiedBy = this.listItem.get_item("Editor");
document.getElementById("create").innerHTML = fieldUserValueModifiedBy.get_lookupValue() ;
alert("Created By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n Modified By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n");
}
function OnLoadFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
 
You have to wait for script files:
function getFieldUserValue(){
SP.SOD.executeOrDelayUntilScriptLoaded(loadContext, 'sp.js');
}
function loadContext() {
this.clientContext = SP.ClientContext.get_current();
if (this.clientContext != undefined && clientContext != null) {
var webSite = clientContext.get_web();
this.list = webSite.get_lists().getByTitle("Resource Readiness");
this.listItem = list.getItemById(1);
clientContext.load(this.listItem);
this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
}
function OnLoadSuccess(sender, args) {
var fieldUserValueCreatedBy = this.listItem.get_item("Author");
var fieldUserValueModifiedBy = this.listItem.get_item("Editor");
document.getElementById("create").innerHTML = fieldUserValueModifiedBy.get_lookupValue() ;
alert("Created By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n Modified By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n");
}
function OnLoadFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

jquery dynamically create html table and bind sharepoint list items in it

I have scenario where i need to bind sharepoint list to the dynamically cretaed html table and use the jquery in content editor webpart to show the table in site.Please help me with this regards.I am using sharepoint 2010.Thanks in advance.
I was trying something here but no luck please help me around with this.Thanksenter code here
<script type="text/javascript" language="javascript">
var _clientContext;
var _web;
alert("Working")
//ExecuteOrDelayUntilScriptLoaded(RetrieveListItems, "sp.js");
function RetrieveListItems() {
alert("Test");
_clientContext = new SP.ClientContext.get_current();
alert(Context);
_web = _clientContext.get_web();
alert(web);
var list = _web.get_lists().getByTitle('Planning Partners');
alert(list);
// var camlQuery = new SP.CamlQuery();
var myquery = new SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(myquery);
_clientContext.load(allItems);
_clientContext.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
function success() {
var Image = null;
var Linkurl = null;
var Title = null;
// var sHtml = "";
alert("success");
var ListEnumerator = this.allItems.getEnumerator();
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
Image = currentItem.get_item('Image');
Linkurl = currentItem.get_item('Linkurl');
Title = currentItem.get_item('Title');
//var tbl = document.createElement("tbl");
var row = document.createElement("tr");
var $table = $('<table>');
$table.append('<caption>MyTable</caption>')
$table.append('<thead>');
$table.append('<tr>');
if (Image != oListItem.get_item('Image')) {
var cell = document.createElement("td");
var cellText = document.createElement("<image imgurl='" + oListItem.get_item('Image') + "'></Image>");
cell.appendChild(cellText);
row.appendChild(cell);
}
if (Linkurl != oListItem.get_item('Linkurl')) {
var cell = document.createElement("td");
var cellText = document.createElement("<a target='_blank' href ='" + oListItem.get_item('Linkurl') + "'>" + oListItem.get_item('Title') + "</a>");
cell.appendChild(cellText);
row.appendChild(cell);
}
if (Title != oListItem.get_item('Title')) {
var cell = document.createElement("td");
var cellText = document.createElement("<p>" + Title + "</p>");
cell.appendChild(cellText);
row.appendChild(cell);
}
$table.append('</tr>');
$table.append('</thead>');
tblBody.appendChild(row);
tbl.appendChild(tblBody);
body.appendchild(tbl);
}
}
// sHtml += '<table><tr><td><img src="' + Image + '" height="55px" width="55px"></td><td><table><tr><td valign="top"><div class="fieldsTitle">' + Linkurl + '</div></td></tr><tr><td valign="top">' + Title + 'Read More >></td></tr><tr><td></td></tr></table></td></tr></table>';
// document.getElementById('MainDiv').innerHTML = sHtml;
// }
function failed(sender, args) {
alert("failed Message" + args.gte_message());
}
</script>
Instead of creating elements through JavaScript, simply create a variable to store theHTML tags and finally add on page using Jquery. Use below script, hope this will help you.
If "Image" and "Linkurl" are HyperLink or Picture Column then use currentItem.get_item('Image').get_url() . I think this was the issue in your case :)
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js "></script>
<script type="text/javascript" language="javascript">
var _clientContext;
var _web;
ExecuteOrDelayUntilScriptLoaded(RetrieveListItems, "sp.js");
function RetrieveListItems() {
_clientContext = new SP.ClientContext.get_current();
_web = _clientContext.get_web();
var list = _web.get_lists().getByTitle('Planning Partners');
var myquery = new SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(myquery);
_clientContext.load(allItems);
_clientContext.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
function success() {
var Image = null;
var Linkurl = null;
var Title = null;
var txtHTML = "";
var ListEnumerator = this.allItems.getEnumerator();
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
Image = currentItem.get_item('Image');
Linkurl = currentItem.get_item('Linkurl');
Title = currentItem.get_item('Title');
var row = document.createElement("tr");
txtHTML = txtHTML + "<tr>";
txtHTML = txtHTML + "<td>";
if (Image != null) {
txtHTML = txtHTML + "<image src='" + Image.get_url() + "'></Image>";
}
txtHTML = txtHTML + "</td>";
txtHTML = txtHTML + "<td>";
if (Linkurl != null) {
txtHTML = txtHTML + "<a target='_blank' href ='" + Linkurl.get_url() + "'>" + Title + "</a>";
}
txtHTML = txtHTML + "</td>";
txtHTML = txtHTML + "<td>";
if (Title != null) {
txtHTML = txtHTML + "<p>" + Title + "</p>";
}
txtHTML = txtHTML + "</td>";
txtHTML = txtHTML + "</tr>";
}
$("#tblCustomListData").append(txtHTML);
}
function failed(sender, args) {
alert("failed Message" + args.gte_message());
}
</script>
<table id="tblCustomListData" border="1">
<thead>
<tr>
<th>Image
</th>
<th>Linkurl
</th>
<th>Title
</th>
</tr>
</thead>
</table>

Insert File preview into sharepoint custom callout control

I followed example here http://blog.alexboev.com/2012/08/custom-callouts-in-sharepoint-2013.html to create callout control.
Now I'm trying to add Preview pane for documents(images, pptx, pdf etc..) in callout control. (similar to the OOTB functionality when user clicks on ellipse in document library item or search result).
How can I achieve this in my own callout control.
See SharePoint 2013 - Custom CallOut with File Preview.
It provide a working code sample:
function getCallOutFilePreviewBodyContent(urlWOPIFrameSrc, pxWidth, pxHeight) {
var callOutContenBodySection = '<div class="js-callout-bodySection">';
callOutContenBodySection += '<div class="js-filePreview-containingElement">';
callOutContenBodySection += '<div class="js-frame-wrapper" style="line-height: 0">';
callOutContenBodySection += '<iframe style="width: ' + pxWidth + 'px; height: ' + pxHeight + 'px;" src="' + urlWOPIFrameSrc + '&action=interactivepreview&wdSmallView=1" frameborder="0"></iframe>';
callOutContenBodySection += '</div></div></div>';
return callOutContenBodySection;
}
function OpenItemFilePreviewCallOut(sender, strTitle, urlWopiFileUrl) {
RemoveAllItemCallouts();
var openNewWindow = true; //set this to false to open in current window
var callOutContenBodySection = getCallOutFilePreviewBodyContent(urlWopiFileUrl, 379, 252);
var c = CalloutManager.getFromLaunchPointIfExists(sender);
if (c == null) {
c = CalloutManager.createNewIfNecessary({
ID: 'CalloutId_' + sender.id,
launchPoint: sender,
beakOrientation: 'leftRight',
title: strTitle,
content: callOutContenBodySection,
contentWidth: 420
});
var customAction = new CalloutActionOptions();
customAction.text = 'Open';
customAction.onClickCallback = function (event, action) {
if (openNewWindow) {
window.open(urlItemUrl);
RemoveItemCallout(sender);
} else {
window.location.href = urlItemUrl;
}
};
var _newCustomAction = new CalloutAction(customAction);
c.addAction(_newCustomAction);
}
c.open();
}
Usage:
<a id="CallOutExample" onclick="OpenItemFilePreviewCallOut(this, 'My Title','<WopiFileUrl>')" title="CallOut With File Preview" h ref="#">Call Out with File Preview</a>

Asterisk 11 active calls event over AMI

Data I would like to have:
Num From , Num To , Duration, Codec, Context, Hold status
ofc in realtime update
I using node.js + nami
what the best way to get this information?
tried use an action Status(), but this gives me not full information about call and if I run it every second browser dies.
here is what I have:
updateCallList();
function updateCallList() {
socket.emit('GET_ACTIVE_CALLS', function(calls) {
$("#callsList").find("tr:gt(0)").remove();
if (calls.response != 'Success') return;
var calls = calls.events;
for (call in calls) {
if (calls[call].privilege == 'Call') {
var callFrom = calls[call].calleridnum + '<' + calls[call].calleridname + '>';
var callTo = calls[call].extension;
var callDuration = calls[call].seconds;
var callRoute = calls[call].context;
var tmpRow = '<tr>';
tmpRow = tmpRow + '<td>' + callFrom + '</td>';
tmpRow = tmpRow + '<td>' + callTo + '</td>';
tmpRow = tmpRow + '<td>' + callDuration + '</td>';
tmpRow = tmpRow + '<td>' + callRoute + '</td>';
tmpRow = tmpRow + '</tr>';
$('#callsList tr:last').after(tmpRow);
}
}
setInterval(function(){
updateCallList();
},1000);
});
}
server side
socket.on('GET_ACTIVE_CALLS', function (callback) {
action = new namiLib.Actions.Status();
nami.send(action, function (response) {
callback(response);
});
});
You need start daemon which will collect NewExten, Link, Unlink, Hangup events and create list of channels.
http://www.voip-info.org/wiki/view/asterisk+manager+events
Also you can do action command with "core show channels" "core show channel XXXXX", but asterisk will die if you do alot of that.
http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Command

Resources