1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    9
    Vote Rating
    0
    Fredrik-s is on a distinguished road

      0  

    Default Answered: Button to new view example

    Answered: Button to new view example


    Hello,

    Im trying to figure out how to create a menu structure with buttons (no tabMenu, "independent" buttons in a container), like the example on the picture below.

    swedbank-app.png
    When pressing a button I want to go to a new view. I have searched for a long time on an example for this, but havent found.

    Is there any good guide how to accomplish this? I want it to be as easy and understandable as possible. My problem is not to create the button "layout" more how I connect each button to a event so it goes to a new view, when pushed.

    Greetings

  2. Suppose you have defined a new view called example and you want to display this as the active app screen. Below you can fine a sample view definition:

    Code:
    Ext.define('GS.view.Example, {
        extend: 'Ext.Container,
        alias: 'widget.example',
        config: {
            items: [
                {
                    xtype: 'toolbar',
                    docked: 'top',
                    title: 'Example'
                }
            ]
        }
    });
    In order to display it, all you need to do is to call:

    Code:
    Ext.Viewport.setActiveItem(Ext.widget('example'));
    Inside your button handler function.

  3. #2
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,394
    Answers
    148
    Vote Rating
    22
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Hello Fredrik,
    I suggest you to download this full MVC application I've developed and released for free under my github account.
    The app is full commented so should help you to understand how the MVC architecture works and much more.

    https://github.com/AndreaCammarata/F...ner-RSS-Reader

    Hope this helps.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    CEO at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    http://www.tux-components.com/


  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    9
    Vote Rating
    0
    Fredrik-s is on a distinguished road

      0  

    Default


    Quote Originally Posted by AndreaCammarata View Post
    Hello Fredrik,
    I suggest you to download this full MVC application I've developed and released for free under my github account.
    The app is full commented so should help you to understand how the MVC architecture works and much more.

    https://github.com/AndreaCammarata/F...ner-RSS-Reader

    Hope this helps.
    Thanks for the example. Have checked it out, but it feels like it is a little bit to much for me in this stage. Is there another example just describing the easiest way of adding a new view to a button?

    I have this code as it is now and when hitting the "erbjudandeAction" button it produces a popup. Now I want to be taken to a new view instead of the alert popup:

    app.js
    Code:
    //<debug>Ext.Loader.setPath({
        'Ext': 'sdk/src'
    });
    //</debug>
    
    
    Ext.application({
        name: 'GS',
    
    
        requires: [
            'Ext.MessageBox',
            //'GS.view.NyView'
        ],
    
    
        views: ['Main'],
        
        controllers: ['MainController'],
    
    
        icon: {
            57: 'resources/icons/Icon.png',
            72: 'resources/icons/Icon~ipad.png',
            114: 'resources/icons/Icon@2x.png',
            144: 'resources/icons/Icon~ipad@2x.png'
        },
        
        phoneStartupScreen: 'resources/loading/Homescreen.jpg',
        tabletStartupScreen: 'resources/loading/Homescreen~ipad.jpg',
    
    
        launch: function() {
            // Destroy the #appLoadingIndicator element
            Ext.fly('appLoadingIndicator').destroy();
    
    
            // Initialize the main view
            Ext.Viewport.add(Ext.create('GS.view.Main'));
        },
    
    
        onUpdated: function() {
            Ext.Msg.confirm(
                "Application Update",
                "This application has just successfully been updated to the latest version. Reload now?",
                function() {
                    window.location.reload();
                }
            );
        }
    });

    view/Main.js
    Code:
    Ext.define("GS.view.Main", {    extend: 'Ext.Container',
        requires: ['Ext.Img'],
        
        config: {
            border: '5px',
            margin: '',
            padding: '30 10 10 10',
            style: 'background-image: -webkit-gradient(linear, left top, left bottom,  color-stop(0, #ffffff), color-stop(1, #dadada));  background-image: -moz-linear-gradient(top, #ffffff, #dadada);',
            scrollable: 'true',
            items: [
                {
                    xtype: 'button',
                    id: 'erbjudandeKnapp',
                    margin: 10,
                    maxWidth: 600,
                    padding: 10,
                    style: 'margin: 0 auto; color: #fff; background: #d10808;     background: -webkit-gradient(linear, left top, left bottom, from(#ff3737), to(#d10808));     background: -moz-linear-gradient(top,  #ff3737,  #f47a20);     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ff3737\', endColorstr=\'#d10808\');',
                    iconCls: 'star',
                    iconMask: true,
                    text: 'Erbjudanden',
                    color: '',
                    action: 'erbjudandeAction'
                },
                {
                    xtype: 'button',
                    id: 'minaSidorKnapp',
                    margin: 10,
                    maxWidth: 600,
                    padding: 10,
                    style: 'margin: 0 auto; color: #fff; background: #d10808;     background: -webkit-gradient(linear, left top, left bottom, from(#ff3737), to(#d10808));     background: -moz-linear-gradient(top,  #ff3737,  #f47a20);     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ff3737\', endColorstr=\'#d10808\');',
                    iconCls: 'user',
                    iconMask: true,
                    text: 'Mina sidor',
                    color: ''
                },
                {
                    xtype: 'button',
                    id: 'hittaTillJulaKnapp',
                    margin: 10,
                    maxWidth: 600,
                    padding: 10,
                    style: 'margin: 0 auto; color: #fff; background: #d10808;     background: -webkit-gradient(linear, left top, left bottom, from(#ff3737), to(#d10808));     background: -moz-linear-gradient(top,  #ff3737,  #f47a20);     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ff3737\', endColorstr=\'#d10808\');',
                    iconCls: 'info',
                    iconMask: true,
                    text: 'Hitta till Jula'
                },
                {
                    xtype: 'button',
                    id: 'sokArtiklarKnapp',
                    margin: 10,
                    maxWidth: 600,
                    padding: 10,
                    style: 'margin: 0 auto; color: #fff; background: #d10808;     background: -webkit-gradient(linear, left top, left bottom, from(#ff3737), to(#d10808));     background: -moz-linear-gradient(top,  #ff3737,  #f47a20);     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ff3737\', endColorstr=\'#d10808\');',
                    iconCls: 'search',
                    iconMask: true,
                    text: 'Sök artiklar'
                },
                {
                    xtype: 'panel',
                    docked: 'bottom',
                    floatingCls: '',
                    height: 106,
                    ui: '',
                    layout: {
                        align: 'center',
                        type: 'vbox'
                    },
                    items: [
                        {
                            xtype: 'image',
                            docked: 'right',
                            height: 201,
                            maxHeight: 106,
                            maxWidth: 211,
                            right: '',
                            style: '',
                            ui: '',
                            width: 201,
                            src: 'resources/images/julaBottom.png'
                        }
                    ]
                }
            ]
        }
    
    
    
    });

    controller/MainController.js
    Code:
    Ext.define('GS.controller.MainController', {    extend: 'Ext.app.Controller',
        requires: [
            'Ext.navigation.View'
        ],
        
        config: {
            control: {
                'button[action=erbjudandeAction]': {
                    tap: 'erbjudandeAlert'    
                }
            }
        },
            
        erbjudandeAlert: function() {
            
            alert('TJA')
        }
        
    
    
    
    });

  5. #4
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,394
    Answers
    148
    Vote Rating
    22
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Suppose you have defined a new view called example and you want to display this as the active app screen. Below you can fine a sample view definition:

    Code:
    Ext.define('GS.view.Example, {
        extend: 'Ext.Container,
        alias: 'widget.example',
        config: {
            items: [
                {
                    xtype: 'toolbar',
                    docked: 'top',
                    title: 'Example'
                }
            ]
        }
    });
    In order to display it, all you need to do is to call:

    Code:
    Ext.Viewport.setActiveItem(Ext.widget('example'));
    Inside your button handler function.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    CEO at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    http://www.tux-components.com/


  6. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    9
    Vote Rating
    0
    Fredrik-s is on a distinguished road

      0  

    Default


    Thank you for patient and answer!

    I have updated my code to the following below. But I get an error I have encountered before and not understood why I get. Something with Ext.requires if I have my gooling right, but still dont understand why of the answers I got:

    [COLOR=red !important]Example.js:1Uncaught SyntaxError: Unexpected token ILLEGAL[/COLOR]
    • [COLOR=red !important]Example.js:1Uncaught SyntaxError: Unexpected token ILLEGAL[/COLOR]
      • [COLOR=red !important]sencha-touch.js:8002Uncaught Error: The following classes are not declared even if their files have been loaded: 'GS1.view.Example'. Please check the source code of their corresponding files for possible typos: 'app/view/Example.js[/COLOR]
    My code now look like this:

    app.js
    Code:
    //<debug>Ext.Loader.setPath({
        'Ext': 'sdk/src'
    });
    //</debug>
    
    
    Ext.application({
        name: 'GS1',
    
    
        requires: [
            'Ext.MessageBox',
            //'GS.view.NyView'
        ],
    
    
        views: [
            'Main',
            'Example'
        ],
        
        controllers: ['MainController'],
    
    
        icon: {
            57: 'resources/icons/Icon.png',
            72: 'resources/icons/Icon~ipad.png',
            114: 'resources/icons/Icon@2x.png',
            144: 'resources/icons/Icon~ipad@2x.png'
        },
        
        phoneStartupScreen: 'resources/loading/Homescreen.jpg',
        tabletStartupScreen: 'resources/loading/Homescreen~ipad.jpg',
    
    
        launch: function() {
            // Destroy the #appLoadingIndicator element
            Ext.fly('appLoadingIndicator').destroy();
    
    
            // Initialize the main view
            Ext.Viewport.add(Ext.create('GS1.view.Main'));
        },
    
    
        onUpdated: function() {
            Ext.Msg.confirm(
                "Application Update",
                "This application has just successfully been updated to the latest version. Reload now?",
                function() {
                    window.location.reload();
                }
            );
        }
    });


    view/Main.js
    Code:
    Ext.define("GS1.view.Main", {    extend: 'Ext.Container',
        requires: ['Ext.Img'],
        
        config: {
            border: '5px',
            margin: '',
            padding: '30 10 10 10',
            style: 'background-image: -webkit-gradient(linear, left top, left bottom,  color-stop(0, #ffffff), color-stop(1, #dadada));  background-image: -moz-linear-gradient(top, #ffffff, #dadada);',
            scrollable: 'true',
            items: [
                {
                    xtype: 'button',
                    id: 'erbjudandeKnapp',
                    margin: 10,
                    maxWidth: 600,
                    padding: 10,
                    style: 'margin: 0 auto; color: #fff; background: #d10808;     background: -webkit-gradient(linear, left top, left bottom, from(#ff3737), to(#d10808));     background: -moz-linear-gradient(top,  #ff3737,  #f47a20);     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ff3737\', endColorstr=\'#d10808\');',
                    iconCls: 'star',
                    iconMask: true,
                    text: 'Erbjudanden',
                    color: '',
                    action: 'erbjudandeAction'
                },
                {
                    xtype: 'button',
                    id: 'minaSidorKnapp',
                    margin: 10,
                    maxWidth: 600,
                    padding: 10,
                    style: 'margin: 0 auto; color: #fff; background: #d10808;     background: -webkit-gradient(linear, left top, left bottom, from(#ff3737), to(#d10808));     background: -moz-linear-gradient(top,  #ff3737,  #f47a20);     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ff3737\', endColorstr=\'#d10808\');',
                    iconCls: 'user',
                    iconMask: true,
                    text: 'Mina sidor',
                    color: ''
                },
                {
                    xtype: 'button',
                    id: 'hittaTillJulaKnapp',
                    margin: 10,
                    maxWidth: 600,
                    padding: 10,
                    style: 'margin: 0 auto; color: #fff; background: #d10808;     background: -webkit-gradient(linear, left top, left bottom, from(#ff3737), to(#d10808));     background: -moz-linear-gradient(top,  #ff3737,  #f47a20);     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ff3737\', endColorstr=\'#d10808\');',
                    iconCls: 'info',
                    iconMask: true,
                    text: 'Hitta till Jula'
                },
                {
                    xtype: 'button',
                    id: 'sokArtiklarKnapp',
                    margin: 10,
                    maxWidth: 600,
                    padding: 10,
                    style: 'margin: 0 auto; color: #fff; background: #d10808;     background: -webkit-gradient(linear, left top, left bottom, from(#ff3737), to(#d10808));     background: -moz-linear-gradient(top,  #ff3737,  #f47a20);     filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ff3737\', endColorstr=\'#d10808\');',
                    iconCls: 'search',
                    iconMask: true,
                    text: 'Sök artiklar'
                },
                {
                    xtype: 'panel',
                    docked: 'bottom',
                    floatingCls: '',
                    height: 106,
                    ui: '',
                    layout: {
                        align: 'center',
                        type: 'vbox'
                    },
                    items: [
                        {
                            xtype: 'image',
                            docked: 'right',
                            height: 201,
                            maxHeight: 106,
                            maxWidth: 211,
                            right: '',
                            style: '',
                            ui: '',
                            width: 201,
                            src: 'resources/images/julaBottom.png'
                        }
                    ]
                }
            ]
        }
    
    
    
    });


    view/Example.js
    Code:
    Ext.define('GS1.view.Example, {    extend: 'Ext.Container,
        alias: 'widget.example',
        config: {
            items: [
                {
                    xtype: 'toolbar',
                    docked: 'top',
                    title: 'Example'
                }
            ]
        }
    
    });


    controller/MainController.js
    Code:
    Ext.define('GS1.controller.MainController', {    extend: 'Ext.app.Controller',
        requires: [
            'Ext.navigation.View'
        ],
        
        config: {
            control: {
                'button[action=erbjudandeAction]': {
                    tap: 'erbjudandeAlert'    
                }
            }
        },
            
        erbjudandeAlert: function() {
            Ext.Viewport.setActiveItem(Ext.widget('example'));    
        }
        
    
    
    
    });


  7. #6
    Sencha User
    Join Date
    Apr 2012
    Posts
    9
    Vote Rating
    0
    Fredrik-s is on a distinguished road

      0  

    Default


    Got it work. Just typo with "-signs in declaration.

    The right code is:

    Code:
    Ext.define('GS1.view.Example', {    extend: 'Ext.Container',
        alias: 'widget.example',
        config: {
            items: [
                {
                    xtype: 'toolbar',
                    docked: 'top',
                    title: 'Example'
                }
            ]
        }
    });

  8. #7
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,394
    Answers
    148
    Vote Rating
    22
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Glad it worked and sorry for the typo
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    CEO at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    http://www.tux-components.com/


Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi