Jarred Nicholls

.NET, RoR/Merb, iPhone, ExtJS, & more

Ext.tree.MultiSelectionModel Doesn't Unselect

clock August 19, 2008 09:38 by author jarred

The Ext.tree.MultiSelectionModel handles multiple selections very well by utilizing the well known Ctrl+Click action to do multiple selections of tree nodes.  However, doing Ctrl+Click on an already selected node does not unselect it, which is quite unintuitive to the Ctrl+Click action.  To add this behavior, simply override the private onNodeClick method of the MultiSelectionModel class:

Ext.override(Ext.tree.MultiSelectionModel, {
    onNodeClick: function(node, e){
        if (e.ctrlKey && this.isSelected(node))
            this.unselect(node);
        else
            this.select(node, e, e.ctrlKey);
    }
});

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


ColumnTree - Headers Always Up Top

clock August 19, 2008 08:30 by author jarred

A popular user extension to ExtJS, Ext.tree.ColumnTree (originally just a demo), suffers from a few lacking features.  These features include:

  • Header isn't anchored at the top
  • Cannot resize column width
  • Cannot reorder columns
  • Cannot click headers for sortability

Because all of these features are found in the GridPanel, people have grown to love these features, and thus expect them in any column-based data layout.  There is a user extension named TreeGrid, rumored to be adopted as a part of the Ext widget library, that provides these features.  However, the extension is currently a little immature, and is more geared to being a Grid than it is to being a Tree (if that makes any sense?).  So in the meantime, while it's being matured, I extended the ColumnTree to at least have an anchored column header bar, and will perhaps add the other features in the near future.

Another small edition is that I have added the xtype registration of 'columntreepanel', so you can create the ColumnTree via an xtype config object, rather than its constructor.

ux-columnnodeui.js (4.46 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


ExtJS iPhone Extensions

clock August 16, 2008 07:10 by author jarred

With the release of the iPhone and especially the iPhone 3G, the demand to create iPhone-compatible and iPhone-enriched web pages and applications has sky rocketed.

In my humble opinion, there is no better framework to create rich internet applications than the famous ExtJS.  Being an early contributor and active community member for ExtJS, I believe in it whole-heartedly.  While ExtJS does a lot of, if not all of, the heavy lifting for the average application and will create iPhone-compatible applications with ease, it has not been extended to create iPhone-enriched applications.

An iPhone-enriched application takes advantage of the Safari and iPhone specific additions to the DOM and Javascript API.  Such things as iPhone orientation events, SQLite integration, and native CSS selectors are a couple of the major iPhone specific features that ExtJS should extend itself to use or wrap with friendly code.

Stay tuned, as I have volunteered myself to Aaron and Jack from ExtJS to create this extension for the community.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


ExceptFilterAttribute - ASP.NET MVC

clock August 12, 2008 20:06 by author jarred

First of all, kudos to Scott Gu and the rest of the .NET/MVC team for doing a great job on ASP.NET MVC thus far.  Today I just upgraded a project of mine to Preview 4 and so far so good.

When I first started working with ASP.NET MVC and its built in Action Filtering capability -  which are implemented via Attributes on both the Action methods and the Controller class - I began to run into many situations where a particular filter of mine applied to the majority of actions in my controller, but not necessarily all of them.  One of my pet peeves is code clutter, and I couldn't find it in myself to tag 25 actions with the same filter attribute while leaving those other 3 actions untouched.  I really wanted to just put it on the controller class and somehow tag those 3 actions to ignore my controller-wide filter.

Thus was born my ExceptFilterAttribute class, as shown below.  This filter serves as a base class to a lot of my other filters that gives me the ability to declare actions to which the filter should not apply.  What this allows me to do is to put my filter on the controller class to satisfy those 25 actions I wish to target, and to specify the 3 actions I wish to leave untouched.  While this may incur a small amount of CPU overhead on all actions, it's almost negligent when weighed against its convenience.

using System;
using System.Linq;
using System.Web.Mvc


    public class ExceptFilterAttribute : ActionFilterAttribute
    {
        public string Except { get; set; }

        public bool IsException(ActionExecutingContext filterContext)
        {
            if (Except != null)
            {
                string[] exceptions = Except.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (exceptions.Contains(filterContext.ActionMethod.Name))
                    return true;
                else
                    return false;
            }

            return false;
        }
    }

Subclasses take advantage of the ExceptFilterAttribute class by calling its IsException method in an overridden OnActionExecuting event handler.  Below is an example of my own custom RequiresAuthenticationAttribute class that is a subclass of ExceptFilterAttribute:

public class RequiresAuthenticationAttribute : ExceptFilterAttribute
    {
        private bool _redirect = true;
        public bool Redirect
        {
            get { return _redirect; }
            set { _redirect = value; }
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (IsException(filterContext))
                return;

            //redirect if not authenticated
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                //use the current url for the redirect
                string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath;

                //send them off to the login page
                string redirectUrl = string.Format("?ReturnUrl={0}", redirectOnSuccess.URLEncode());
                string loginUrl = FormsAuthentication.LoginUrl + redirectUrl;
                filterContext.Cancel = true;
                if (Redirect)
                {
                    filterContext.HttpContext.Response.Redirect(loginUrl, true);
                }
            }
        }
    }

Notice the call to IsException and if it returns true, the filter returns and doesn't execute its primary code.  If your filter handles OnActionExecuted, OnResultExecuting, or OnResultExecuted and you want to implement the ExceptFilterAttribute functionality, simply implement the OnActionExecuting event handler and if IsExecuting returns true, then set the OnActionExecutingContext's Cancel property to true to cancel the filter execution altogether.

Below is an example controller using the RequiresAuthenticationAttribute.  Each action that is to be an exception is put into a comma-delimited string and is case-sensitive.

[RequiresAuthentication(Except = "Login,Logout")]
public class MyController : Controller
{
    public ActionResult MyProtectedAction1()
    { ... }

    public ActionResult MyProtectedAction2()
    { ... }

    public ActionResult MyProtectedAction3()
    { ... }

    public ActionResult Login()
    { ... }

    public ActionResult Logout()
    { ... }
}

The ExceptFilterAttribute class is attached.  It's small and not much to it, but certainly has proven useful for me.

ExceptFilterAttribute.cs (559.00 bytes)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Welcome

clock August 12, 2008 18:56 by author jarred

My name is Jarred Nicholls and I'm Chief Architect of DigitalSports, Inc. (http://www.digitalsports.com)  I've decided to start my own technology blog, discussing my favorite software topics including all of the latest happenings in .NET, Ruby on Rails, Merb, ExtJS, the iPhone, and more.

Along the way I plan to share my knowledge from over the years of being a software architect, and also plan to share code that I have found to be useful to myself and my colleagues past and present.

Please do subscribe to my blog's feed to stay tuned to my latest postings.  I will try to be fairly active inbetween my many hours of work and being a new father of a (currently) 3 week old son Laughing

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


About the author

Jarred Nicholls

Architect

Scientist

Entrepreneur

RecentPosts

Month List

Sign in