//use spBeforeRender event to get access to the SharePoint form context
fd.spBeforeRender(function(ctx) {
var dt = fd.control('vAllDocs');
if (dt.widget) {setRootFolder();}
else {dt.$on('ready', function() {setRootFolder();});
}
function setRootFolder(){
dt.baseRootFolder = ctx.ItemAttributes.Url.replace("&","%26");
dt.rootFolder = ctx.ItemAttributes.Url.replace("&","%26");
}
});
// use spRendered event to get access to the fully-loaded and initialized DOM
fd.spRendered(function(ctx) {
// populate top labels
console.log('setting form labels');
fd.control('txtPropertyName').text = null != fd.field('_MLMSPropertyLookup').value ? fd.field('_MLMSPropertyLookup').value.LookupValue : "";
fd.control('txtUnitNumber').text = null != fd.field('_MLMSUnitLookup').value ? fd.field('_MLMSUnitLookup').value.LookupValue : "";
fd.control('txtTenantName').text = null != fd.field('_MLMSTenantDBALookup').value ? fd.field('_MLMSTenantDBALookup').value.LookupValue : "";
fd.control('txtPosessionDate').text = fd.field('S2CaseStartDate').value;
fd.control('txtCommencementDate').text = fd.field('_MLMSCommencementDate').value;
fd.control('txtExpiryDate').text = fd.field('S2CaseEndDate').value;
console.log('labels ready');
// setup Property Picker
//fd.field('_MLMSPropertyLookup').ready().then(function () {
updatePropertyInfo();
updateUnitInfo();
updateTenantInfo();
//});
// wire up tab selector
$(fd.container('tabDocumentTypes').$el).find('.nav-link').click(function(){
var docsTable = fd.control('vAllDocs');
console.log('you switched to a different tab of documents');
documentsTabContainer = fd.container('tabDocumentTypes');
var tabName = documentsTabContainer.tabs[documentsTabContainer.currentTab].title;
console.log('the tab you switched to was ' + tabName);
docsTable.refresh();
if (tabName == "All Documents")
{
// clear the filter so that all documents are shown
docsTable.filter = "";
docsTable.refresh();
}
else {
// set a CAML filter for Agreement Form (S2DocumentType)
// column does or does not begin with the first 5 letters
// of the title of the selected tab
docsTable.filter =
"" +
"" +
"" + tabName.substr(0,4) + "" +
"";
docsTable.refresh();
}
});
});
function updatePropertyInfo() {
console.log('// looking up Property Info...');
// grab current value
var propertyID = fd.field('_MLMSPropertyLookup').value.LookupId;
pnp.sp.web.lists.getByTitle('Properties')
.items.getById(propertyID)
.get()
.then(function(foundItem) {
if (foundItem) {
// fill out the form values
fd.control('txtPropertyNumber').text = foundItem.S2Number;
fd.control('txtPropertyType').text = foundItem.OData__MLMSPropertyType;
fd.control('txtPropertyLandlord').text = foundItem.OData__MLMSLandlord;
fd.control('txtPropertyAddress').text = foundItem.WorkAddress;
}
}); // DONE>Property Info
}
function updateUnitInfo() {
console.log('// looking up Unit Info...');
// grab current value
var unitID = fd.field('_MLMSUnitLookup').value.LookupId;
pnp.sp.web.lists.getByTitle('Units')
.items.getById(unitID)
.get()
.then(function(foundItem) {
//debugger
if (foundItem) {
// fill out the form values
fd.control('txtUnitType').text = foundItem.OData__MLMSUnitType;
fd.control('txtUnitArea').text = foundItem.Subject;
}
}); // DONE>Unit Info
}
function updateTenantInfo() {
console.log('// looking up Tenant Info...');
// grab current value
var tenantID = fd.field('_MLMSTenantDBALookup').value.LookupId;
pnp.sp.web.lists.getByTitle('Tenants')
.items.getById(tenantID)
.get()
.then(function(foundItem) {
if (foundItem) {
// look up the Tenant Legal Name
var tenantLegalNameID = foundItem.OData__MLMSTenantLookupId;
// are nested promises OK with everyone?
//debugger
pnp.sp.web.lists.getByTitle('Tenant Legal Names')
.items.getById(tenantLegalNameID)
.get()
.then(function(foundItem) {
//debugger
if (foundItem) {
// fill out the form values
fd.control('txtTenantLegalName').text = foundItem.Title;
fd.control('txtTenantAddress').text = foundItem.WorkAddress;
}
}); // DONE>Tenant Legal Name and Address
}
}); // DONE>Tenant Info
}