Best way to trigger a Modal View Controller on Tab Bar press. - uiviewcontroller

When the user triggers a tabbar item I want to display present a modal view controller.
I have something working but it's probably not the cleanest way to do it. It also prevents the UITabBarItem to be in selected state.
What I did is setting this method to false and in the that method body presenting the view controller (via the RootViewController).
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
UINavigationController *nvc = (UINavigationController*)viewController;
Do you guys have any idea of a cleaner implementation of this that would allow the TabBarItem to be highlighted ?

This is the one of the way to use the MVC on Tab bar...To highlighting the tab bar item like that.
id currentlySelected; //This will hold the address of the selected view
id dontAllowSelection; //This will hold the address of the Denied view
(BOOL)tabBarController:(UITabBarController *)tabBarControllers shouldSelectViewController:(UIViewController *)viewController
{
if (dontAllowSelection != nil && //If it is nil, we will skip it.
dontAllowSelection == viewController) //If the selected view is Denied return NO
{
return NO;
}
currentlySelected = viewController;
if (currentlySelected == someViewIWantToDisableOtherFor) //Any logic can go here to enable the Denied View.
{
dontAllowSelection = anotherViewIWantDisabled; //Set my denied view.
}
else
{
dontAllowSelection = nil; //Unsed the Denial.
}
return YES;
}

Related

window.addEventListener is not working on a user click on the browser back button in polymer 2.0?

window.addEventListener('popstate', function(event) {
alert("you are not able to push back button");
});
I have create the web application using polymer 2.0 but I have to click on the back button to the browser is logout I have to show the alert if the user is click on the back button of the browser I have tried window.addEventListener but still got error.
I've not been able to stop the browser's back button, but I've managed to get around it. In my app, I want to warn the user that they will log out by backing up to the first page, and give them a chance to leave or stay put. Using the polymer-2-starter-kit as my starting point, and tracking a connected property, I got this working:
_routePageChanged(page) {
// If no page was found in the route data, page will be an empty string.
// Default to 'home' in that case.
this.page = (page && this.connected) ? page : 'home';
// Close the drawer.
this.drawerOpened = false;
}
_pageChanged(page, oldPage) {
// Warn user if backing up logs out.
if ((page == '' || page == 'home') && this.connected) {
if (window.confirm("Do you really mean to logout?")) {
this.$.xhrLogout.generateRequest();
} else {
window.history.forward();
}
}
const resolvedPageUrl = this.resolveUrl('my-' + page + '.html');
Polymer.importHref(
resolvedPageUrl,
null,
this._showPage404.bind(this),
true);
}
So if the user is connected, and navigates to the initial page, I can force them to stay on the page where they were with window.history.forward().

How to disable the context menu on long press when using device mode in Chrome?

How to disable the context menu on long press when using device mode in Chrome ?
I mean this context menu:
I am asking this because I want to debug long press gestures for mobile devices and the context menu causes my react app to behave in a strange way:
when I try to reorder the list then "strange things start to happen": selected item starts to float all over the place (as can be seen from snapshot below). The Hello World is obscured by the selected item. Really strange.
My workaround is entering this code into the JS console when testing long press actions in device mode:
window.oncontextmenu = function() { return false; }
I have developed a slightly more "advanced" workaround that will still (most of the time) show the contextmenu on right-click while preventing it from showing on a simulated long-tap:
window.oncontextmenu = function() {
if (event.button != 2 && !(event.clientX == event.clientY == 1)) {
event.preventDefault();
}
}
#marsk comment was right therefore based on previous answers I come up with another solution using PointerEvent.pointerType
window.oncontextmenu = function (event: any) {
// eslint-disable-next-line no-console
console.log(event); // prints [object PointerEvent]
const pointerEvent = event as PointerEvent;
// eslint-disable-next-line no-console
console.log(`window.oncontextmenu: ${pointerEvent.pointerType}`);
if (pointerEvent.pointerType === 'touch') {
// context menu was triggerd by long press
return false;
}
// just to show that pointerEvent.pointerType has another value 'mouse' aka right click
if (pointerEvent.pointerType === 'mouse') {
// context menu was triggered by right click
return true;
}
// returning true will show a context menu for other cases
return true;
};

Lightswitch html client override default save button

I want to be able to override the default save button on the html client however i cant seem to find the control to do so. I want to write some validation behind it and allow the user to select an option but I just cant seem to find it.
I know the silverlight client you can override it but just cant seem to override it in the html client.
thanks
It's achieved using beforeApplyChanges.
example: (Please excuse any typos/syntax errors, you get the rough idea!)
myapp.AddEditScreen.beforeApplyChanges = function (screen) {
switch (screen.Property_SavingStatus) {
case 'Not Saving':
setTimeout(function () {
// Override Save -> toggle SavingStatus -> Call Save again
SaveMyChangesMyWay();
screen.Property_SavingStatus = 'Commit';
myapp.commitChanges(); // Or Discard or Apply.
}, 500);
return false; // Cancel save changes request
break;
case 'Apply':
return true;
break;
default:
};

Redirect after Login MyWSAT

I've been testing the example code here http://mywsat.codeplex.com/
In their example they have different buttons to login to either the admin pages or members page using seperate links
However, I'm trying to use a single link to a landing page and after the user logs in redirect to the relevant page using codebehind. The landingpage requires login but all roles can view this page set in the rules.
landingpage.aspx:
protected void Page_Load(object sender, EventArgs e)
{
string redirectPath;
string pagePath = Request.AppRelativeCurrentExecutionFilePath;
if (Page.User.IsInRole("Administrator"))
{
//Admin
redirectPath = "~/admin/Default.aspx";
if (redirectPath != pagePath)
{
Response.Redirect(redirectPath);
}
}
else if (Page.User.IsInRole("Member"))
{
//Members
redirectPath = "~/members/Default.aspx";
if (redirectPath != pagePath)
{
Response.Redirect(redirectPath);
}
}
else if (Page.User.IsInRole("Trial"))
{
//Trial
redirectPath = "~/trial/Default.aspx";
if (redirectPath != pagePath)
{
Response.Redirect(redirectPath);
}
}
else
{
//Non member
redirectPath = "~/Default.aspx";
if (redirectPath != pagePath)
{
Response.Redirect(redirectPath);
}
}
}
The problem is the Page_Load event fires straight away and then launches login-with-captcha.ascx after the event has fired.
So then I moved the code to the login form login-with-captcha.ascx.cs to redirect after e.Authenticated = true; but it just redirects back to login-with-captcha.ascx in an endless loop
login-with-captcha.ascx.cs:
// Next, determine if the user's username/password are valid
if (Membership.ValidateUser(loginUsername, loginPassword))
{
e.Authenticated = true;
//tried redirecting from here based on role!
}
else
//............
How can I redirect from the landing page after the user is validated? I suspect it may have something to do with postback but need some help
Can you try adding the following as the first line within your Page_Load to see if it helps? This will likely prevent the endless loop issue if it's being caused by something that triggers a postback event, like a button click.
if (IsPostBack) return;

Codeigniter limit certain page elements to profile owner

I want to limit access to certain elements of a user's profile so that only the user can see them and not other logged in users. So far the is_logged_in function (see below) works fine, now I need to refine it so that it is limited to a specific user that is logged in.
I'm already including a user_id variable in my session data, so that's available for use.
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if($is_logged_in)
{
$this->index();
}
else
{
redirect('fooview');
}
}
you will need to know the user_id of the profile you are viewing, lets assume in your controller you have it as $user_id.
in your controller you can do $is_owner = $this->session->userdata('user_id') == $user_id ? true : false;
then pass it to your view as e.g. $is_owner.
then in your view simply have
if($is_owner){
//show stuff
} else {
//message saying stuff is private!
}