I have created one custom Dashlet, and added it to site dashboard.
But now my requirement is that, I want to display that custom only for site manager and i want to hide it for all other users.
Can anyone help me with this? How can hide custom Dashlet for all consumers and collaborators.
Thanks in advance.
In your controller javascript (aka .get.js file) add an extra remote.call to get the groups of the current user like:
var groupResult = remote.call("/api/people/" + stringUtils.urlEncode(user.name) + "?groups=true");
Use the result and eval it, then send it to your freemarker dashlet.
--- Update ---
You can also take a look at the default share-header webscript.
Take a look at the file org\alfresco\share\imports\share-header.lib.js
The snippet:
// Call the repository to see if the user is site manager or not
var userIsSiteManager = false,
userIsMember = false;
json = remote.call("/api/sites/" + page.url.templateArgs.site + "/memberships/" + encodeURIComponent(user.name));
if (json.status == 200)
{
var obj = eval('(' + json + ')');
if (obj)
{
userIsMember = true;
userIsSiteManager = obj.role == "SiteManager";
}
}
siteData = {};
siteData.profile = profile;
siteData.userIsSiteManager = userIsSiteManager;
siteData.userIsMember = userIsMember;
// Store this in the model to allow for repeat calls to the function (and therefore
// prevent multiple REST calls to the Repository)...
// It also needs to be set in the model as the "userIsSiteManager" is required by the template...
model.siteData = siteData;
so use this in an if statement in freemarker
Related
I'm starting to review some requirements for processing a few HTML templates from within a suitelet using suitescript 1.0
I haven't been able to find any information on handlebars JS from within netsuite but I'm curious as to whether there is any requirements to configuring a suitelet that does the server side generation as I would prefer to use it compared to using the client side implementation
If anyone can share anything useful on how to get a suitelet prepared to make use of handlebars that would be greatly appreciated
Below is a sample from one of the Suitelets I use handlebars in. You setup the suitelet like any other by creating a form object and a html field to hold the rendered handlebar template.
var screenTitle = 'Form Title';
var form = nlapiCreateForm(screenTitle);
var pageTemplate = nlapiLoadFile('SuiteBundles/Bundle '+sitBundleId+'/src/sit_html_templates/template.html').getValue();
var hbTemplate = Handlebars.compile(pageTemplate);
Handlebars.registerHelper('if_eq',function(a,b,opts) { if(a == b) { return opts.fn(this); } else { return opts.inverse(this); } });
Handlebars.registerHelper('json', function(context) { return JSON.stringify(context); });
var data = {
"account_id":nlapiGetContext().getCompany(),
"bundle_id":sitBundleId,
"other_data":{}
};
var htmlValue = hbTemplate(data);
var templateField = form.addField('template_section','inlinehtml','',null,'main_group');
templateField.setDefaultValue(htmlValue);
response.writePage(form);
Thats the basics. Of course the Handlebar library must be added to the library sublist on the NetSuite Suitelet record.
Custom Search UI will be populated when user selects Complex asset in the Advance search screen drop down(apart from Folders,Contents) where 12 fields will be displayed .So when user clicks search button ,need to read those values and redirect to the alfresco repo files(org/alfresco/slingshot/search/search.get.js).We have already customized these files(search.get.js,search.lib.js) existed in the repository to suit out logic and working fine in 4.2.2;As we are migrating to 511,so we need to change this logic in customized faceted-search.get.js to read these values.How to write this logic in customized facted-search.get.js?
It's not actually possible to read those URL hash attributes in the faceted-search.get.js file because the JavaScript controller of the WebScript does not have access to that part of the URL (it only has information about the URL and the request parameters, not the hash parameters).
The hash parameters are actually handled on the client-side by the AlfSearchList widget.
Maybe you could explain what you're trying to achieve so that I can suggest an alternative - i.e. the end goal for the user, not the specifics of the coding you're trying to achieve.
We will be reading the querystring values something like below in the .get.js file.
function getNodeRef(){
var queryString = page.url.getQueryString();
var nodeRef = "NOT FOUND";
var stringArray = queryString.split("&");
for (var t = 0; t < stringArray.length; t++) {
if (stringArray[t].indexOf('nodeRef=') > -1) {
nodeRef = stringArray[t].split('=')[1];
break;
}
}
if (nodeRef !== "NOT FOUND") {
nodeRef = nodeRef.replace("://", "/");
return nodeRef;
}
else {
throw new Error("Node Reference is not found.");
}
}
It may be help you and we will wait for Dave Drapper suggestion also.
how to directly get SITE details (like ID and name ) on main() of controller js of dashelt in alfresco
i can use " Alfresco.constants.SITE" on FTL file to read site ID, but need to know is there any KEY to read data on controller
janaka
There isn't a service on the Share side which provides that information, because the information you want is only held on the repository. As such, you'll need to call one of the REST APIs on the Repo to get the information you need
Your code would want to look something like:
// Call the repository for the site profile
var json = remote.call("/api/sites/" + page.url.templateArgs.site);
if (json.status == 200)
{
// Create javascript objects from the repo response
var obj = eval('(' + json + ')');
if (obj)
{
var siteTitle = obj.title;
var siteShortName = obj.shortName;
}
}
You can see a fuller example of this in various Alfresco dashlets, eg the Dynamic Welcome dashlet
Sometimes there is a need to have one button which will automatically complete and create a new phone call where some data from the old one are transfered to new one, there is a solution. It is also possible to implement this behaviour on other forms.
Download the Visual Ribbon Editor for CRM 2011/2013 from http://crmvisualribbonedit.codeplex.com/
Create Phone Call Ribbon Scripts which will be used by button created in later steps.
Define the following source of the script created in previous step. The script mark as completed the phone call and open a new phone call - regarding and description fields are sent through url. Therefore the url has to be shortened if it exceeds 2000 chars, otherwise the link does not work.
function SaveAsCompleteAndNew() {
// Attempt to save Activity and Mark it as Complete
SaveAsCompleted();
// If the form is not valid
if (!Xrm.Page.data.getIsValid())
return;
var url = "/main.aspx?etn=phonecall&pagetype=entityrecord&extraqs=";
var regardingString = "";
var regardingValue = Xrm.Page.getAttribute("regardingobjectid").getValue();
if (regardingValue != null) {
regardingString += "®arding_id=" + regardingValue[0].id;
regardingString += "®arding_name=" + regardingValue[0].name;
regardingString += "®arding_type=" + regardingValue[0].entityType;
regardingString = encodeURIComponent(regardingString);
}
var descriptionValue = Xrm.Page.data.entity.attributes.get("description").getValue();
var descriptionString = ((descriptionValue != null) ? encodeURIComponent("description=" + descriptionValue) : "");
// The url length is limited to about 2k chars, otherwise the link cannot be opened. Therefore the length has to be limited.
var maxDescriptionLength = 1970 - (url.length + regardingString.length);
if (descriptionString.length > maxDescriptionLength) {
var shortenedText = descriptionString.substr(0, maxDescriptionLength - 25);
// Patt1 checks if it ends with e.g. %1 and patt2 with %. These are not allowed because they have been reduced by
// substr. Correct format is three chars like %20 for white space. If there are not in correct format, url does not work
var patt1 = new RegExp("%\\d$");
var patt2 = new RegExp("%$");
if (patt1.test(shortenedText))
shortenedText = shortenedText.substr(0, shortenedText.length - 3);
else if (patt2.test(shortenedText))
shortenedText = shortenedText.substr(0, shortenedText.length - 2);
descriptionString = shortenedText + encodeURIComponent("\n...shortened...");
}
var extraqsEncoded = descriptionString + regardingString;
window.open(url + extraqsEncoded);
}
Run Visual Ribbon Editor for CRM 2011/2013, connect to CRM instance, select the Phone Call entity and add a new button "Complete And New" through New button fucntion. Define the following setting on the Details tab:
Note: As you can see there are also icons defined. Load these icons as web resource to the CRM.
Select Action tab and define the action which should be perfomed on click command of "Complete And New button". As a Function Name use the same name as defined in step 3. Library should be a path to the script created also in step 3.
You can also define Display Rules - in our case we show the button only to people who has right to write to the current phone call entry and also if the phone call is in Open status (statuscode = 1).
Save all changes in Visual Ribbon Editor for CRM 2011/2013 and publish them. Also do not forget to publish changes in CRM customization otherwise added webresources are not available.
I have added a script to send mail whenever a site is created. How to restrict the email notification if the site created is a private site. Here is my java script
var mail = actions.create("mail");
var node = people.getGroup("GROUP_EMAIL_CONTRIBUTORS");
if(node){
var members = people.getMembers(node);
}
mail.parameters.from = "Administrator#community.com"
mail.parameters.subject=" A new site called " + document.properties.name+" is created";
mail.parameters.text="Click http://sameer_w7:8080/share/page/site/" + document.properties.name + "/dashboard" + " to join the site";
for(var i=0;i<members.length;i++)
{
mail.parameters.to = members[i].properties.email;
//execute action against a document
mail.execute(document);
}
You can get the siteVisibility state of a site.
Take a look at the SiteService Wiki page.
Something like this should work:
if (document.properties["st:siteVisibility"] != "PRIVATE"){
<your email action here>
}
Be sure you have selected type is st:site in your rule, otherwise add an extra check on that.