Hybrid View

  1. #1
    Sencha User
    Join Date
    Nov 2012
    Location
    Mauritius
    Posts
    43
    Vote Rating
    3
    Shabneez is on a distinguished road

      0  

    Default Hide and Show onButtonClick()

    Hide and Show onButtonClick()


    Hello,

    Could anyone provide a small example on how to show a panel and hide a panel when we click on a button? my button is found on a toolbar..Im a bit lost. Also, am I (REALLY??) allowed to use only a function, and not a controller? (I saw in the documentation..but the button is a button only in the panel itself, how do I do this from a button found on a toolbar?)

    Thanks

  2. #2
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    52
    Vote Rating
    11
    celticboyone will become famous soon enough

      1  

    Default


    I don't have a sample but you can do what you ask using a controller and you will learn so much more building it yourself, like this:

    First, all you need to do in your View is give each control you need to interact with an "id" - in this case your panel and your button. The controls in your view fire events that the Controller can capture and act upon

    Now create a Controller if you don't already have one and then add a "References" for each control. E.g. if your button id is "myButton" then for the Reference name (step 1 of 1) enter "myButton" and for the selector (step 2 of 2) enter the button id with a "#' in front so "#myButton", make sure you spell these correctly. Do the same for the panel.

    Okay, now in the Controller let's capture a "tap" event on the button - in the Controller add an "Actions - Controller Action". Choose "Ext.Button" for the target type and "tap" for the event name. Now you have a new function that will be called when you tap the button. Let's check that it works:

    Select the new tap function in the Controller and switch to the Code view and enter "alert('Hello world');". Now save you project and run it - when you tap the button you should see a popup with the test "Hello world"

    Ok, now we simply need to show and hide the panel when you click the button instead of displaying a popup message. To do that we need to be able to reference the panel so we can show and hide it - remember how we added a reference for the panel id earlier? Now we get to use that. Sencha helps us here in that it will automatically create a "getter" for us to access the panel. The name will be the word "get" followed by the id of your panel with the first letter captialized. So, let's say your panel id is "myPanel", you will use the function getMyPanel() to find the panel. Now we need a context to do it so use the word "this" which means the Controller:

    Code:
    this.getMyPanel().hide();    // this will hide the panel
    So simply replace your alert message (or add to it) with the above line and now when you tap the button your panel should hide. You can show the panel using...

    Code:
    this.getMyPanel().show();    // this will show the panel
    I think you'll be able to figure it out from there and sorry if I made any mistakes.

  3. #3
    Sencha User
    Join Date
    Nov 2012
    Location
    Mauritius
    Posts
    43
    Vote Rating
    3
    Shabneez is on a distinguished road

      0  

    Default


    ohhh! thank you so much so much so much! I'll try this. So I do this for everything that I want to show and hide? the controller then can hide, apart from this panel, other views that I have on my viewport but which I dont need at some time, right? Also, I have a small query..I was thinking, if I have a login form with two buttons, Login and Cancel..then the Login one when I click on it,goes to some "login.php" that checks whether the user can log in etc etc, and then how do I redirect this to another view in my extjs app? I use the success function? Thanks

  4. #4
    Sencha User
    Join Date
    Nov 2012
    Location
    Mauritius
    Posts
    43
    Vote Rating
    3
    Shabneez is on a distinguished road

      0  

    Default


    for the views, can I make use of itemId instead of id?

  5. #5
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    52
    Vote Rating
    11
    celticboyone will become famous soon enough

      1  

    Default


    Ooops, this submitted before I was ready...

    Yes, the controller can do everything. The key is that by using References the Controller has access to every control item in your View. You can write local handlers in the Views too but your code will be more difficult to manage so it is good practice to use the Controller. When you get the MVC concept working you can move on to more "best practices" on how to manage events that will help you on larger projects.

    Yes, you are thinking correctly on the login form. This form would have a username and password field with a login button. When the user presses the login button (which triggers a function in the Controller just like we did in the previous example), the Controller calls the login web-service. The callback from that webservice will have a "records" value (and a success). The records value is where your data will be. So for example, lets say the server returns a 0 value if the login is successful, you would check that like this in the login webservice callback and then jump to your main screen (and you should destroy the login form to get that memory back and reduce the DOM):

    if (records[0].data.Result === LOGIN_SUCCEEDED) {
    mainTabScreen = Ext.create('myProject.view.MainTabPanel');
    Ext.Viewport.add(mainTabScreen); // Show the main tab panel
    }

    Use the id for now (not the itemId - as it works differently). Sencha has many different ways to reference controls, you just need to get one method working first and then you will understand what the other options means and when you might best use them.

  6. #6
    Sencha User
    Join Date
    Nov 2012
    Location
    Mauritius
    Posts
    43
    Vote Rating
    3
    Shabneez is on a distinguished road

      0  

    Default


    Thanks a lot! when I have forms, may I submit them directly, without using a controller? Sometimes I see form panels have a url directly, and then I see buttons have handlers with url, success and failure functions, and then controllers...?

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