Change joomla menu from source code - joomla

can I change the joomla menu from source code?
I want to test if I have an open session, and if I have it , I want to change the Login menu, into My Account menu !
Can anyone help me? Thanks.

You need to make a template override of the menu.
https://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core
Then inside that use:
$user = JFactory::getUser();
if ($user->guest())
{
//Insert HTML if not logged in
}
else
{
//Insert HTML if logged in
}

Related

Can you do me a script for Flutter photo access permisson?

This is a sample of my Flutter source code which controlled behavior of photo access permisson:
class __ImageWidgetState extends State<_ImageWidget> {
Future<bool> requestGalleryPermission() async {
const Permission _photos = Permission.photos;
final PermissionStatus permissionss = await _photos.request();
if (permissionss == PermissionStatus.granted) {
return true;
} else {
return openAppSettings();
// return false;
}
}
With this code, if users press Don't Allow they will be redirected to Photo Setting automatically.
I have changed openAppSettings() by false so nothing happens if users press Don't Allow, but they can't upload image until they go to Photo Setting to choose Allow manually.
I'm new to Flutter, so can you please help me with my below scritp?
Users pressing Don't Allow will see a popup saying that: Because you choose Don't Allow so you won't be able to change profile image and upload image.
They press OK button to close this popup. Everytime they want to change/upload image they will see popup which requires access photo again.
Thank you! I'm so grateful to you!
If the user don't allow the access for photos you can show an AlertDialog.
https://api.flutter.dev/flutter/material/AlertDialog-class.html
If it is allowed you just ask for permission again.

Auto-close menu sections on open

We would like to only have one menu section open at a time using mmenu and so does anyone know how we could automatically close any opened sections when a section is expanded?
Thanks
OK i managed to come up with this which works, there's probably a better way to do it:
$("#mm-0 a[href^=#]").click(function() {
var clickedMenu = $(this);
$("#mm-0 a[href^=#]").parent().each(function( i ) {
$(this).removeClass("mm-opened");
});
if($(clickedMenu).parent().hasClass("mm-opened")){
$(clickedMenu).parent().removeClass("mm-opened");
}else{
$(clickedMenu).parent().addClass("mm-opened");
}
});
So i basically add an onclick handler to any anchor links in the menu and then update the class.

How can i set a session variable in jquery?

Can anyone help me how to set a session variable in Jquery. Actually My requirement is like this:-
I am having a popup in html file. When i click the link, the popup opens. However, if i set the session expire , the popup should not open. So, when i click on the link, if session expires, the popup should not open but should redirect to targeted page. How can i do this?? My TL told me to google this but didn't found actually what i required. He suggested me to set session in Jquery. Is there any alternative for this?? As i am a newbie to Jquery, any code snippets are higly appreciated.please help me..
If you are needing to do this in .NET MVC you can do it as such. Below is a an example:
Controller:
if (Session["pageInitCounter"] == null)
{
Session["pageInitCounter"] = 1;
}
else
{
int counter = Convert.ToInt32(Session["pageInitCounter"]);
counter++;
Session["pageInitCounter"] = counter;
}
View:
#Html.Hidden("pageInitCounter", Session["pageInitCounter"])
Javascript:
alert($("#pageInitCounter").val());
You may try using localStorage like below.
$(document).ready(function() {
var notSeen = localStorage['seen'];
if (!notSeen) {
// open popup
localStorage['seen'] = "yes";
}
});
Alternatively, use may as well try using a hidden field for this purpose.
Please visit the below links for more information. This should satisfy your requirement
http://forums.asp.net/t/1499296.aspx
http://forums.asp.net/t/1672519.aspx/1

Joomla 2.5 custom mvc component: different form for task add

I'm developing a custom mvc component for Joomla 2.5.
For my admin section I included a "New" button in the toolbar.
By clicking this button I want to display a separate form with less
fields. So far everything works out but the buttons of the view's
toolbar won't redirect (i.e. 'Cancel')
To redirect the task 'add' I added an override of the method "add()"
to my controller:
class ArchitectProjectControllerArchitectProject extends JControllerForm
{
public function add()
{
JRequest::setVar('layout', 'add');
$result = parent::add();
return $result;
}
}
I don't know if I'm on the right track. Probably someone can give me a hint?
If you wish to redirect for example on 'Cancel' then try the following in the controller:
public function cancel()
{
$this->setRedirect('index.php?option='.$this->option.'&view=yourview');
}

On Session Timeout Login.gsp is rendered within the <body> tag instead of redirecting to a new gsp page

I am new to Grails and working on a project which has just 2 controllers one is for login and the other is for a explorer (similar to a windows explorer with left panel displaying a tree -like structure and the right displays the folders contents as a table)
The application is working as excpected meaning when user accesses the application it displays Login Screen if user hasn't logged in and if he has logged in it displays the explorer screen.
But this is not the case on session Timeout: suppose the session has timed out and the user clicks on a link in the right panel of the explorer screen then the login screen is displayed within the right panel.
I am using SecurityFilter to redirect to login screen.
SecurityFilters.groovy
def filters = {
loginCheck(controller:'*', action:'*') {
before = {
if (!session.idpuser && actionName != "login") {
redirect(controller: "user", action: "login")
return false
}
}
}
}
userController.groovy
def login () {
if (request.get) {
return false
}
......
redirect(controller: "explorer", action: "file")
}
explorerController.groovy
def generateFiles = {
.....
render(template: 'list', model: [ dirList: dirList])
}
UrlMappings.groovy
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(action:"file", controller: "explorer")
"500"(view:'/error')
}
The reason I think login.gsp is being rendered in the right panel is because when a user click on a link in right panel "generateFiles" action is invoked and that is rendering login.gsp as a template within explorer.gsp. But I dont know how to fix it :(
I would appreciate if someone can help me with this issue.
PLEASE HELP!!!!!
Since this is an ajax based site, you need to explicitly handle the "you need to login" response in your ajax response handlers and force the user to the login page if needed.
Looks like I found the solution may not be an efficient way but it works.Based on the response I get from the Ajax call I am redirecting to Login.gsp using
window.location.href = '${createLink(controller='user', action='login')}'
Thank you cdeszaq for the hint. I really appreciate it.

Resources