SwarmOnline Menu Mobile
  • Home
  • About
  • Services
  • Portfolio
  • Blog
  • Contact

Recent Posts

  • PhoneGap and the TestFlight SDK – Taking it Further!
  • Integrating the TestFlight SDK into your PhoneGap Application
  • Retrieving References to Internal View Components
  • Launching Sencha Insights
  • Documenting your Sencha apps with JSDuck

Recent Comments

  • Stuart on Ext.ux.TouchCalendar – A Sencha Touch Calendar component
  • Stuart on Localising Sencha Touch and Ext JS applications with Ux.locale.Manager
  • Manuel Rodriguez on Localising Sencha Touch and Ext JS applications with Ux.locale.Manager
  • Remi Bloch on Ext.ux.TouchCalendar – A Sencha Touch Calendar component
  • Remi Bloch on Ext.ux.TouchCalendar – A Sencha Touch Calendar component

Archives

  • May 2013
  • March 2013
  • February 2013
  • December 2012
  • September 2012
  • August 2012
  • November 2011
  • October 2011
  • May 2011
  • March 2011
  • February 2011
  • January 2011
  • November 2010

Categories

  • Development Tips
  • Ext JS
  • News
  • Sencha Touch
  • Sencha Touch Extensions & Plugins
  • Web Design
  • Web Design & Development Blog

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

16
18 Jan
2011
PanelActionScreenshot

Sencha Touch Extensions & Plugins

Web Design & Development Blog

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 (1280)

Demo – 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 (1280)

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

Demo – Ext.ux.PanelAction

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

[javascript]

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();

[/javascript]

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 (1280)
Tweet

16
  1. Jeff B. - Reply

    April 27, 2011 at 7:00 pm

    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 - Reply

    April 27, 2011 at 7:07 pm

    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. - Reply

    April 27, 2011 at 8:24 pm

    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. - Reply

    April 28, 2011 at 9:21 pm

    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?

    • Stuart - Reply

      May 1, 2011 at 11:40 am

      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

  5. h. - Reply

    May 5, 2011 at 5:37 pm

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

  6. Brandon - Reply

    May 26, 2011 at 8:07 am

    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

    • Stuart - Reply

      May 26, 2011 at 9:12 am

      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

  7. Brandon - Reply

    May 31, 2011 at 4:52 pm

    Stuart,

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

    Brandon

  8. Fredo - Reply

    September 17, 2011 at 10:42 pm

    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!

    • Stuart - Reply

      September 18, 2011 at 10:56 pm

      @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.

  9. Fredo - Reply

    September 19, 2011 at 10:51 pm

    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!

  10. Joshua Ellis - Reply

    January 13, 2012 at 11:01 pm

    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.

  11. Gilles - Reply

    November 7, 2012 at 9:57 pm

    Hi Stuart

    Seems not working on sencha touch 2.0
    I extract the zip into the examples’ directory of the Sencha Touch libary package.
    And when i run it i get :
    viewport argument value “device-width;” for key “width” not recognized. Content ignored. /~gilles/touch/Examples/PanelAction/:5
    Viewport argument value “1.0;” for key “initial-scale” was truncated to its numeric prefix. /~gilles/touch/Examples/PanelAction/:5
    Viewport argument value “1.0;” for key “maximum-scale” was truncated to its numeric prefix. /~gilles/touch/Examples/PanelAction/:5
    Viewport argument value “1.0;” for key “minimum-scale” was truncated to its numeric prefix. /~gilles/touch/Examples/PanelAction/:5
    Viewport argument value “0;” for key “user-scalable” was truncated to its numeric prefix. /~gilles/touch/Examples/PanelAction/:5
    Uncaught TypeError: Cannot set property ‘PanelAction’ of undefined

    • Stuart - Reply

      November 8, 2012 at 10:03 pm

      Hi

      Unfortunately the PanelAction plugin is currently only compatible with Sencha Touch 1. If you end up upgrading it, it would be great to fork it on GitHub (https://github.com/SwarmOnline/Ext.ux.PanelAction) and we can point people to your repo in the future!

      Thanks
      Stuart

  12. Gilles - Reply

    November 8, 2012 at 1:49 pm

    Hi Stuart,

    Does this works with sencha touch 2 ?
    I extract the ZIP file into the ‘examples’ directory of the Sencha Touch libary package. And when i run it i get multiples errors

    Regards
    Gilles
    Ps : I wrote already a post but it was delete !

Leave a Comment - Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About SwarmOnline

Based in Glasgow’s West End, SwarmOnline provide web development, cross platform mobile app development and training services for local and international organisations. We have expert knowledge of Sencha technologies and have been Sencha Partners since 2011. We specialise in creating dynamic, innovative and practical solutions.

Meet the Team...

Newsletter

Subscribe to our newsletter and we’ll keep you up-to-date. We don't do spam.

Get in touch!

Email: [email protected]   
Skype: andrew-swarmonline stuart-swarmonline   
Phone: 0141 438 2231   


© 2013 SwarmOnline Ltd. All Rights Reserved.

SwarmOnline Ltd is a Limited Company registered in Scotland, with company number SC411633. Our Registered Office is 1-2 249 Byres Road, Glasgow G12 8UB.