Sencha Touch Extensions & Plugins

Ext.ux.PanelAction: Add action buttons to floating Sencha Touch panels

Sencha Touch Extensions & Plugins,Web Design & Development Blog 13 Comments

Plugin Overview

This plugin can be applied to panels to give a simple and flexible way of adding action buttons to a panel. It could be used as a simple close button or as the submit button on a form.

Although very simple we hope it might be of use to someone else who is looking for an alternative way of performing actions on floating panels.

The source code is now available on GitHub here
Extract the ZIP file into the ‘examples’ directory of the Sencha Touch libary package.

Download – Ext.ux.PanelAction

The Problem

This plugin was created within our Prop.erti.es project in response to a bug which closed a floating panel when an option was selected from a select field that lay within it. This meant we had to implement some sort of close/accept button on the panel so users could select options without having the form disappear.

The Plugin

The plugin places an icon on top of your panel (in any corner or in the middle of any side) which when tapped executes any method or function that you want, for example, closing the panel, submitting the form etc.

It is insanely simple to use and there are only a few config options that you need to worry about.

Just download the plugin from the link below.

Extract the ZIP file into the ‘examples’ directory of the Sencha Touch libary package.

Download – Ext.ux.PanelAction

… or view a live demo (please use Safari, Google Chrome or your Smartphone!)

Using the Plugin

Step 1

Add references to the Ext.ux.PanelAction.js and css/Ext.ux.PanelAction.css files to your HTML page.

Step 2

Add a new instance of the plugin to the ‘plugins’ config of your panel using a combination of the following config options, the important options to pay attention to are position, iconClass and actionMethod.

position defines where the Icon sits, the plugin automatically centres the icon but this can be adjusted with the xOffset and yOffset configs.Any combination of:  ‘t’ (Top), ‘b’ (Bottom) or ‘c’ (Centre) and ‘l’ (Left), ‘r’ (Right) or ‘c’ (Centre)

For example,

tl = Top Left

br = Bottom Right etc

xOffset a number (in pixels) to offset the horizontal position of the icon
yOffset a number (in pixels) to offset the vertical position of the icon
baseClass the base CSS class that is applied to the Ext.Element – shouldn’t need to be changed
iconClass the CSS class that MUST define the background-image, width and height and any other custom styles required for the Ext.Element
iconPressedClass the CSS class that is added to the Ext.Element when the user is pressing the icon
actionMethod an array, or single value, or methods to execute when the icon is tapped. This can be in the form of an array or as a single value. Acceptable values are strings of a function that exists on the parent’sclass, anonymous inline function declarations and references to functions.For example these are all valid:

actionMethod: ‘hide’

actionMethod: function(){ alert(‘test’); }

actionMethod: this.myFunction

actionMethod: [‘hide’, function(){ alert(‘test’); }, this.myFunction]

And that’s it!

There are no restrictions to using this plugin – download it and use it as you like (a link back is always nice though :) )

Sample Code


var pnl = new Ext.Panel({
    floating: true,
    width: 350,
    height: 370,
    centered: true,
    modal: true,
    hideMode: 'close',
    hideOnMaskTap: false,
    layout: 'fit',
    html: panelContent,
    showAnimation: {
        type: 'pop',
        duration: 250
    },
    plugins: [new Ext.ux.PanelAction({
        iconClass: 'x-panel-action-icon-tick',
        iconPressedClass: '',
        position: 'br',
        actionMethod: ['hide']
    })]
});

pnl.show();

Please feel free to leave a comment with any suggestions, bugs or ideas that you have or if you need some help integrating it with your application.

Extract the ZIP file into the ‘examples’ directory of the Sencha Touch libary package.

Download – Ext.ux.PanelAction

Share this

13 Comments to "Ext.ux.PanelAction: Add action buttons to floating Sencha Touch panels"

  1. Jeff B.

    April 27, 2011

    This is a great plugin and it works as advertised.

    However, I used it on a panel that can be opened an closed repeatedly, but the close icon added with the plugin is only displaying the first time the panel is displayed. After the first hide, it never comes back…

  2. Stuart

    April 27, 2011

    Hi Jeff,

    Could you post the code you are using that is producing this problem? I was unable to reproduce this issue so I might have recreated it slightly differently.

    Thanks
    Stuart

  3. Jeff B.

    April 27, 2011

    GA.sidebarall = Ext.extend(Ext.Panel, {
    floating: true,
    centered: true,
    modal:true,
    scroll: ‘vertical’,
    floatingCls: ‘ga-floating’,
    width: 560,
    height: 540,
    data: null,
    cls: ‘sidebarpop’,
    layout: ‘fit’,
    tpl : [
    '{title}',
    '',
    '{body}'
    ],
    plugins: [new Ext.ux.PanelAction({
    position: 'tr',
    actionMethod: ['hide']
    })]
    });

  4. Jeff B.

    April 28, 2011

    And then I am just doing a show() on the panel.

    What’s happening is that, in the plugin in onParentShow, the first time there is no iconEl and everything works great. After you hide the parent and then bring it back up, the onParentShow fires, but since the iconEl exists, it doesn’t do anything. However, the iconEl remains hidden even though the parent is re-shown.

    Any suggestions?

  5. Stuart

    May 1, 2011

    Hi Jeff

    Because the iconEl is a child of the Panel it should be ‘unhidden’ along with the panel when you call the show method.

    I’ve tried to recreate the issue using your setup but am still unable to get it to break. This is the code I’m using to test it – there might be something in your context code that is changing the behaviour.


    Ext.setup({
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    icon: 'icon.png',
    glossOnIcon: false,
    onReady: function(){
    Ext.ns('GA');

    GA.sidebarall = Ext.extend(Ext.Panel, {
    floating: true,
    centered: true,
    modal: true,
    scroll: 'vertical',
    floatingCls: 'ga-floating',
    width: 560,
    height: 540,
    data: {title: 'TEST TITLE', body: 'TEST BODY'},
    cls: 'sidebarpop',
    layout: 'fit',
    tpl: ['{title}', '', '{body}'],
    plugins: [new Ext.ux.PanelAction({
    position: 'tr',
    actionMethod: ['hide']
    })]
    });

    // create the panel
    var panel = new GA.sidebarall();

    // show it
    panel.show();

    // use timeout to hide and then another to show it so we don't need to make more buttons :)
    setTimeout(function(){
    panel.hide();

    setTimeout(function(){
    panel.show();
    }, 4000);
    }, 4000);

    }
    });

    Sorry I can’t be of more help just now! If you could direct me to a fully ‘breaking’ example then I will try to get the bug fixed!

    Thanks
    Stuart

  6. h.

    May 5, 2011

    exactly what I was looking for!
    thanx a lot!!!!!

  7. Brandon

    May 26, 2011

    Stuart – Thanks for the plugin work – It seems to work for the most part but I had the same issue as Jeff B. as when I hide my form panel and show again, the icon is not present. Here is how my panel is set up:

    Ext.apply(formBase, {
    autoRender: true,
    floating: true,
    modal: true,
    centered: true,
    hideOnMaskTap: false,
    height: 500,
    width: 480,
    plugins: [new Ext.ux.PanelAction({
    iconClass: 'x-panel-action-icon-close',
    iconPressedClass: '',
    position: 'bc',
    actionMethod: ['hide']
    })]
    });
    }

    form = new Ext.form.FormPanel(formBase);
    form.show();

    Any ideas? Do you need additional code?

    Thanks in advance – Brandon

  8. Stuart

    May 26, 2011

    Hi Brandon,

    Thanks for the snippet – I will try to make time to have a look at this tonight and sort the problem out once and for all!

    I’ll keep you posted.

    Stuart

  9. Brandon

    May 31, 2011

    Stuart,

    Thanks for your help! I look forward to your solution.

    Brandon

  10. Fredo

    September 17, 2011

    Great work, thanx a lot!
    a question – I stretched the modal view to 100% (height: ’100%’,
    width: ’100%’,
    and offset the icon) – but when I change the orientation (the panel is shown) from portrait to landscape and vice versa the modal panel keeps its initial screen size and doesn’t fit the screen changing from portrait to landscape or is greater than the screen view.
    What can I do to have the appropriate size after changing the orientation?

    Thank You!

  11. Stuart

    September 18, 2011

    @Fredo – I think you will need listen for the orientationchange event and manually update the modal view’s width and height to suit the new orientation.

  12. Fredo

    September 19, 2011

    Thanx for the fast response!
    My solution is to have the close icon top left instead of top right… :) Don’t know why – but now the panel sfits the whole viewport.
    Other question: I tried to call the action (panelLaunch) from html content in a carousel or page (with contentEL:) setting in a href like this:

    But… it doesn’t work. I dont wanna have a sencha-button in the topbar or something like this… Is there a work around to call the modalView via onClick or tap event in a HTML-context?

    Thank you!

  13. Joshua Ellis

    January 13, 2012

    It’s probably worth noting that if you don’t set an explicit width and/or height for your Panel, the positioning doesn’t work: the icon is just set at the top left corner. Also, if you’re using a ‘top’ positioning, you don’t need height set on the panel: for example, I have a panel which only has width set and I give the icon position ‘tr’ and it works fine.

Leave a Comment