Abstract classes with Ext JS

Ext JS Screencast: Abstract Classes from Jay Garcia on Vimeo.

In this screencast, we discuss the basics of Abstract classes and how they can help you design maintainable and extensible code.


Here is the code from the screencast: AbstractFormPanel.js

Ext.ns('MyApp');

MyApp.AbstractFormPanel = Ext.extend(Ext.form.FormPanel, {
    defaultType : 'textfield',
    frame       : true,
    width       : 300,
    height      : 200,
    labelWidth  : 75,
    submitUrl   : null,
    initComponent : function() {
         Ext.apply(this, {
            items    : this.buildItems(),
            buttons  : this.buildButtons(),
            defaults : {
                anchor : '-10'
            }
         });

         MyApp.AbstractFormPanel.superclass.initComponent.call(this);
    },
    buildItems : function() {
        return [];
    },
    buildButtons : function() {
        return [
            {
                text    : 'Submit',
                scope   : this,
                handler : this.onSubmit
            },
            {
                text    : 'Cancel',
                scope   : this,
                handler : this.onCancel
            }
        ];
    },
    onSubmit : function() {
        Ext.MessageBox.alert('Submit', this.submitUrl);    
    },
    onCancel : function() {
        this.el.mask('This form is canceled');
    }
});


NameFormPanel.js

Ext.ns('MyApp');

MyApp.NameFormPanel = Ext.extend(MyApp.AbstractFormPanel, {
    title      : 'Edit name data',
    submitUrl  : 'nameAction.asp',
    buildItems : function() {
        return [
            {
                name       : 'firstName',
                fieldLabel : 'First Name'
            },
            {
                name       : 'lastName',
                fieldLabel : 'Last Name'
            },
            {
                name       : 'middleName',
                fieldLabel : 'Middle Name'
            },
            {
                xtype      : 'datefield',
                name       : 'dob',
                fieldLabel : 'DOB'
            }
        ];
    },
    //Extension
    buildButtons : function() {
        var btns = MyApp.NameFormPanel.superclass.buildButtons.call(this);

        btns[0].text = "OK";
        btns[0].handler = this.onOkBtn;
        return btns;
    },
    //Override
    onOkBtn : function() {
        console.info('OK btn pressed');        
    }
   
});

<br/>AddressFormPanel.js

Ext.ns('MyApp');

MyApp.AddressFormPanel = Ext.extend(MyApp.AbstractFormPanel, {
    title      : 'Edit address data',
    submitUrl  : 'addressAction.asp',
    buildItems : function() {
        return [
            {
                name       : 'address1',
                fieldLabel : 'Address 1'
            },
            {
                name       : 'address2',
                fieldLabel : 'Address 2'
            },
            {
                name       : 'city',
                fieldLabel : 'city'
            },
            {
                xtype      : 'combo',
                name       : 'state',
                fieldLabel : 'State',
                store      : ['MD', 'VA', 'DC']
            },
            {
                xtype      : 'numberfield',
                name       : 'zip',
                fieldLabel : 'Zip Code'
            }
        ];
    }


});

[donation-can Macpro]

  • Pingback: Tweets that mention TDG innovations LLC » Blog Archive » Abstract classes with Ext JS -- Topsy.com

  • Pingback: TDG innovations LLC » Blog Archive » Abstract classes with Ext JS – js - dowiedz siÄ™ wiÄ™cej!

  • Pingback: Tweets that mention TDG innovations LLC » Blog Archive » Abstract classes with Ext JS -- Topsy.com

  • Pingback: Nice screencast about abstract… | /blog

  • murrah

    Thanks Jay. That is most interesting. A couple of things:

    1. Very happy to donate – you’ve helped me a lot so thanks for that! I am also in the MEAP for your book.

    2. Some of your descriptions of yourself (“loser”,”tool”) are certainly not accurate based on my experience of the great work you do. As a student of neuroscience as well as software development I am concerned that such thinking / language may limit your brain wiring. :-)

    Thanks again for all the work you do in sharing the understanding of this great library.

    Murray

    • http://moduscreate.com Jay Garcia

      Thank you for your very generous donation.

      In response to the feedback: I was merely trying to add some ‘color’ to the screencast :) . I certainly do not feel like a “loser” or “tool”. :)

      I hope to start filming the next screencast soon.

      • http://moduscreate.com Jay Garcia

        Hi Damo,

        I think that’s a great subject for another screencast ;)

  • Damo

    Hi Jay,

    Great screen cast thanks so much for this!

    I don’t think you explained why you put certain config properties in the initComponent wheras other in main object with the build functions…

    Cheers, Damo

  • http://www.enovision.net jvandemerwe

    Thank you for this wonderful screencast, but as you are much into explaining about the quality of the video, which is by the way GREAT, I want to tell you that unfortunately the sound of your explanation is only on my left channel, where the the intro is on both. Keep up the good work, I like it very much.

    • http://moduscreate.com Jay Garcia

      Jvan, the screencast has been updated online with the audio fixed.

      Thanks again for the heads up.

  • http://moduscreate.com Jay Garcia

    Hi Jvan,

    Thank you so much for your donation and heads up on that issue. I did the editing on my laptop speakers and could not detect the left-only audio issue. I’m going to rectify the issue shortly. I’ll post an update as a comment here when it’s finished.

    Thanks, -jay :)

  • http://moduscreate.com Jay Garcia

    meh, this is all just for show

  • http://moduscreate.com Jay Garcia

    aaaaaaaaaaaa

  • mdavis6890

    Jay, this was the first of your videos that I’ve watched. You’re awesome! Aside from all the awesomeness, I have a couple of comments: - You don’t need to spend so much time justifying a donation box. We all get many thousands of dollars of value from your work, and we’d lose a lot if you curtailed your efforts due to funding issues. Just ask, and ye shall receive! - Practice in your mind what you’re going to say, and try to read AHEAD of what you’re saying, so that you don’t have to pause while you read the next line. We understand that presenting is hard and we don’t expect you to make up eloquent prose on the fly.

  • Pingback: Ext Extension with Factory Functions File Pattern | Saki's Blog

  • Pingback: Abstract class pattern extended by Saki | TDG innovations LLC