In one requirement I need to hide some sites (from the top right menu ) depending on the role of the user .
Right now if the user X doesn't have the access to site ABC but he can still sees the site in the top right My Site menu. When he clicks on it he goes there and sees message saying you are not authorized. Instead of this I want to hide those site which the user doesn't have access to.
Is there any way to do so?
Check is the user is a member of the site. If he should not have access to the site, don't make him a member. The top right menu is generated according to the site membership.
here's [a link] , i hope this will help you , http://findnerd.com/list/view/Hiding-My-Sites-Menu-in-Docbar-in-Liferay/1940/
Update :
You can hide the "My Sites" menu from Liferay Docbar by creating hook. In my example i am hidding the menu option for all the users except those whose role is Administrator. You need to Hook the html/taglib/ui/my_sites/page.jsp
Add the following code to check whether the logged in user is administrator role.
boolean isAdminUser=permissionChecker.isOmniadmin();
Hence if the logged in user is Administrator we are showing the My Sites menu else hidding it. I added extra condition of isAdminUser in following code for same.
<c:if test="<%= !mySiteGroups.isEmpty() && isAdminUser %>">
Following is the code snippet from page.jsp
<%# include file="/html/taglib/init.jsp" %>
<%
String[] classNames = (String[])request.getAttribute("liferay-ui:my_sites:classNames");
String cssClass = GetterUtil.getString((String)request.getAttribute("liferay-ui:my_sites:cssClass"));
boolean includeControlPanel = GetterUtil.getBoolean((String)request.getAttribute("liferay-ui:my_sites:includeControlPanel"));
int max = GetterUtil.getInteger((String)request.getAttribute("liferay-ui:my_sites:max"));
if (max <= 0) {
max = PropsValues.MY_SITES_MAX_ELEMENTS;
}
List<Group> mySiteGroups = user.getMySiteGroups(classNames, includeControlPanel, max);
boolean isAdminUser=permissionChecker.isOmniadmin();
System.out.println("\n\n\n\n\n\n isAdminUser \n\n\n\n\n\n"+isAdminUser);
%>
<c:if test="<%= !mySiteGroups.isEmpty() && isAdminUser %>">
<ul class="taglib-my-sites <%= cssClass %>">
<%
PortletURL portletURL = new PortletURLImpl(request, PortletKeys.SITE_REDIRECTOR, plid, PortletRequest.ACTION_PHASE);
portletURL.setParameter("struts_action", "/my_sites/view");
portletURL.setPortletMode(PortletMode.VIEW);
portletURL.setWindowState(WindowState.NORMAL);
for (Group mySiteGroup : mySiteGroups) {
String escapedSiteName = HtmlUtil.escape(mySiteGroup.getName());
boolean showPublicSite = mySiteGroup.isShowSite(permissionChecker, false);
boolean showPrivateSite = mySiteGroup.isShowSite(permissionChecker, true);
%>
Related
<span id="continue" class="a-button a-button-span12 a-button-primary"><span class="a-button-inner"><input id="continue" tabindex="5" class="a-button-input" type="submit" aria-labelledby="continue-announce"><span id="continue-announce" class="a-button-text" aria-hidden="true">
Continue
</span></span></span>
Above the the HTML from part of a page, which has a 'Continue' button that i'm trying to click, using my script.
So, writing in Javascript, i'm trying to click this button. But nothing I have tried works.
My attempted answer is:
function() {
var goButton = document.getElementById("continue");
goButton.click();},
Why doesn't it work? Help me, please !
You have set the ID of both the span and the input field to "continue". ID's should be unique for a single element. When I enter your code in the browser's console it returns the following:
> var goButton = document.getElementById("continue");
< undefined
> goButton.valueOf()
< <span id="continue" class="a-button a-button-span12 a-button-primary">
You can see the span is the element being selected instead of the input submit button. You should rename either of the 2 elements so both have a unique ID and use that in your script.
Edit: OP mentioned the HTML can not be changed so instead of fixing the use of a not-unique ID this Javascript can be used:
function() {
var continueSpan = document.getElementById("continue");
var goButton = continueSpan.firstElementChild.firstElementChild;
goButton.click();}
I created a web app form using Google Apps Script and the HTMLService.
It is a one-page form with a submit button at the bottom.
When submitted, the form validates whether the data input into the form is valid, and if valid, it logs the form data to a spreadsheet.
That all works so far.
I now need the user to be sent to a confirmation page, and the confirmation page needs to be able to have parameters passed to it (to display certain information on the confirmation page).
main.gs:
function doGet(e) {
var template = HtmlService.createTemplateFromFile('form');
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function processFormSubmission(formData) {
Logger.log('starting processPoRequest');
Logger.log('po: ' + JSON.stringify(formData, null, 2));
// code for appending data to sheet here
}
form.html:
<!DOCTYPE html>
<form id="form1" name="form1">
<label for="info" id="info_label">Info</label>
<input id="info" name="info" type="text">
<input class="btn" id="button" onclick="onClickFunctions(document.getElementById('form1'))" type="submit" value="Submit">
</form>
<script>
function onClickFunctions(formData) {
console.log('starting onClickFunctions');
var allDataValid = validateForm(formData);
if (allDataValid === true) {
google.script.run.withSuccessHandler().processFormSubmission(formData);
}
}
function validateForm(form) {
console.log('starting validateForm');
var errors = 0;
var element = document.getElementById('info');
if (!form.info) { element.classList.add("validation_error"); errors++; if (errors === 1) element.focus(); }
else element.classList.remove("validation_error");
if (errors > 0) return false;
else return true;
}
</script>
confirmation.html:
<!DOCTYPE html>
<?!= confirmationMessage ?>
I don't know what to put in .withSuccessHandler() to make it so that the user is brought to the confirmation page.
I've Googled this extensively and found these results on Stack Overflow, and each one suggests a different solution, but none of them actually include complete working code for a solution:
Possible solutions using doPost:
Send form by email and track responses in spreadsheet
HtmlService doPost With Google Docs Form
HtmlService doPost
I messed around with doPost but I couldn't figure out how to get it to be invoked, and I couldn't find any official documentation in the HTMLService docs.
Possible solution using the link to the web app in an a href:
href in HtmlService
If my button was a link that looked like a button, I'm not sure how I would execute the form validation function when the link is clicked.
I have done this two different ways.
had a hidden statement that gets shown, and the form gets hidden.
or
use .withSuccessHandler(google.script.host.close()), but have the processFormSubmission function open a new dialogue.
In my Page_Load event of my custom DNN module I retrieve the settings that I have stored using the following.
if (((string)Settings["username"] != null) && ((string)Settings["username"] != ""))
username = "";
{
username = (string)Settings["username"];
if (((string)Settings["password"] != null) && ((string)Settings["password"] != ""))
{
password = (string)Settings["password"];
}
if (((string)Settings["baseServiceUrl"] != null) && ((string)Settings["baseServiceUrl"] != ""))
{
baseServiceUrl = (string)Settings["baseServiceUrl"];
}
baseServiceUrl = "";
Now my question is how do I redirect it to my module settings(called settings.ascx) control if username, password or baseServiceurl is null.
I'm sure it's not as simple as Response.Redirect('settings.ascx');
my aim is to replace
username = "";
with a snippet similar to Response.Redirect('settings.ascx');
Please help
If you want to load a different ASCX file that is registered in DNN (registered in the Module Definition, via the MANIFEST file) you do so by calling either the EditUrl method, or the NavigateURL Method in DNN.
EditUrl("Settings") where Settings is the ControlKey defined in the Module definition.
Edit URL is available off of PortalModuleBase, assuming your controls inherit from PMB.
Thanks again Chris, your answer is correct but I decided to get the settings of the module via the modal pop up. This is what I did to get the answer to get the javascript popup script and url i right clicked on the gear icon using google chrome an inspected the element.
I then copied the contents the anchor tag href attribute, this looked a bit like
href="javascript:dnnModal.show('http://localhost/TestPage/ctl/Module/ModuleId/417?ReturnURL=/TestPage&popUp=true',/*showReturn*/false,550,950,true,'')">
In my default.aspx page I created an anchor tag without the href. I made it a server control by putting runat=server and adding an ID to it and made the visibility false (in my logic i make it visible if it does not meet my criteria)
<a runat="server" class="btn btn-success" id="settingsLink" visible="false" > <img src="/images/action_settings.gif"><span>Settings</span></a>
Next I create a method to dynamically build my link
private string settingsUrlBuilder()
{
var s = new StringBuilder();
var urlPartArray = TabController.CurrentPage.FullUrl.ToString().Split('/');
var partUrl = urlPartArray[3].ToString();
s.Append("javascript:dnnModal.show('");
s.Append(TabController.CurrentPage.FullUrl.ToString().ToLower());
s.Append("/ctl/Module/ModuleId/" + ModuleId.ToString());
s.Append("?ReturnURL=/");
s.Append(partUrl);
s.Append("&popUp=true");
s.Append("',/*showReturn*/false,550,950,true,'')");
return s.ToString();
}
This is where i use the function in the page load
settingsLink.HRef = settingsUrlBuilder(); settingsLink.Visible = true;
I have ng-file-upload with form submit running. I would like to add a button to cancel the upload after the user selects a file.
I have tried:
<button class= "btn btn-warning btn-cancel" ng-disabled="!myForm.$valid"
ng-click="cancelPic(picFile)">Cancel</button>
and in the controller:
$scope.cancelPic = function() {
myForm.reset();
file: '';
}
The form does seem to reset as I get a "please select a file" message but the image remains - in the dev tools Elements:
<img ng-show="myForm.file.$valid" ngf-src="!picFile.$error && picFile" class="thumb" src="blob:http%3A//localhost%3A3000/85f1b27c-a92e-447d-b760-8cfe17bbd6b7" style="">
Obviously I'm barking up the wrong tree here. Can anyone help?
Ok I found what I sought at:
https://github.com/danialfarid/ng-file-upload/issues/12
The code that works is:
$scope.cancelPic = function(file) {
myForm.reset();
$scope.picFile = undefined;
}
Now I need to apply this to individual images so a user can choose which to cancel and not reset the whole form. That's for another day.
How can I display the right image, title and link for a Facebook Like button in a list of products?
I do implement sucessfully the like button but it is when you navigate to the product details, you see only one product.
I ask how can i do it in the list of products, for now the image displayed on my facebook page is a generic image from the site and not the specific image of the product, the link is right.
Must the tag <meta property="og:image" content="some value"/> only be inside the head tag? I cannot use it inside the body tag?
The meta tags for the news story don't need to be on the page that is displaying the Like button. The news story will be generated from the meta tags on the page listed in the URL parameter of the Like button.
Here is an example. -
This Repeater will dynamically generate a list of products from a database with customized Like buttons:
<asp:Repeater ID="_RPT_Product" runat="server">
<HeaderTemplate><h3>Products</h3><ul class="bulleted-list"></HeaderTemplate>
<ItemTemplate><li><%# Utilities.ScrubText(((Product)Container.DataItem).ProductName) %>
</li>
<div style="padding-top:10px;">
<iframe
src="https://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.yourdomainname.com/Product.aspx%3FID%3D<%#((Product)Container.DataItem).ProductID %>%26x%3D1&send=false&layout=button_count&width=88&show_faces=false&action=like&colorscheme=light&font&height=23"
scrolling="no" frameborder="0"
style="border:none; overflow:hidden; width:88px; height:23px;"
allowTransparency="true">
</iframe></div><br />
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
This would be the code-behind on a separate Product page that dynamically renders meta tags from a product database:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Get the product meta content from the ID URL parameter.
string productName = "";
string productImageURL = "";
string productDescription = "";
int productID = 0;
if (Request.QueryString["ID"] != null)
{
productID = Convert.ToInt32(Request.QueryString["ID"]);
}
if (Request.QueryString["ID"] != null)
{
using (ProductDatabaseDataContext db = new ProductDatabaseDataContext(Config.ConnectionStrings.ProductDatabase))
{
Product select = new Product();
select = db.Products.FirstOrDefault(p =>
p.ProductID == Convert.ToInt32(Request.QueryString["ID"]));
productName = select.ProductName;
productImageURL = select.ProductImageURL;
productDescription = select.ProductDescription;
}
}
// Dynamically generate Open Graph Meta Tags for each Product:
HtmlMeta _metaTitle = new HtmlMeta();
_metaTitle.Name = "og:title";
_metaTitle.Content = "Product: " + productName;
this.Header.Controls.Add(_metaTitle);
HtmlMeta _metaURL = new HtmlMeta();
_metaURL.Name = "og:url";
_metaURL.Content = "http://www.yourdomainname.com/Product.aspx?ID=" + Convert.ToString(productID);
this.Header.Controls.Add(_metaURL);
HtmlMeta _metaImage = new HtmlMeta();
_metaImage.Name = "og:image";
_metaImage.Content = Convert.ToString(productImageURL);
this.Header.Controls.Add(_metaImage);
HtmlMeta _metaDescription = new HtmlMeta();
_metaDescription.Name = "og:description";
_metaDescription.Content = Convert.ToString(productDescription);
this.Header.Controls.Add(_metaDescription);
}
}
Note that every Like button must have a unique URL parameter, because only one set of meta content attributes can be tied to a single URL. This can be accomplished by having a unique ID parameter on your separate Product.aspx page. The "og:url" meta tag for each of your products can be the same if you just want all of the product news stories to link back to one master list page.
The Like button likes a specific URL and if it's a product the user is liking, that link really should bring users back to a description of that product and not to a completely different set of content.
What you display on that propduct page itself isn't really important (it could be the full product list if you really wanted) provided that that URL returns the same meta tags to the Facebook crawler each time
What you're trying to do could be achieved by setting up a script which serves the meta tags for each product based on URL parameters (making sure to keep the og:url tags pointing to the correct URL to generate the same tags again.
Serve those tags to the Facebook crawler and redirect other browsers wherever you want.