1. #1
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    148
    Vote Rating
    2
    denisputnam is on a distinguished road

      0  

    Default How do you hook the save button to the controller

    How do you hook the save button to the controller


    Can someone tell me how to get the save button to call the updateUserController() method from the Ext.window.Window Edit popup window? I don't know how to get a hold of the Controller object from a popup window via the Architect designer.

    I have attached the zip of the project. It is the MVC example from sencha, but I am rewriting it using Architect.

    -Denis

    Ext.define('AM.view.user.Edit', {
    extend: 'Ext.window.Window',
    alias: 'widget.useredit',


    autoShow: true,
    height: 154,
    width: 400,
    title: 'Edit User',


    initComponent: function() {
    var me = this;


    Ext.applyIf(me, {
    items: [
    {
    xtype: 'form',
    bodyPadding: 10,
    items: [
    {
    xtype: 'textfield',
    name: 'name',
    fieldLabel: 'Name',
    anchor: '100%'
    },
    {
    xtype: 'textfield',
    name: 'email',
    fieldLabel: 'Email',
    anchor: '100%'
    }
    ]
    },
    {
    xtype: 'button',
    text: 'Save',
    listeners: {
    click: {
    fn: me.onButtonClickSave,
    scope: me
    }
    }
    },
    {
    xtype: 'button',
    autoShow: true,
    text: 'Cancel',
    listeners: {
    click: {
    fn: me.onButtonClickCancel,
    scope: me
    }
    }
    }
    ]
    });


    me.callParent(arguments);
    },


    onButtonClickSave: function(button, e, options) {
    //var store = Ext.getCmp( 'userscontroller' );
    //'userscontroller'.updateUser(button);
    var controller = Ext.app.Controller.getController('AM.controller.User');
    controller.updateUserController(button);
    },



    onButtonClickCancel: function(button, e, options) {
    button.up().close();
    }


    });

    Ext.define('AM.controller.Users', {
    extend: 'Ext.app.Controller',
    alias: 'controller.userscontroller',


    views: [
    'user.List',
    'user.Edit'
    ],
    id: 'userscontroller',


    init: function(application) {
    this.control({
    'viewport > userlist': {
    itemdblclick: this.editUser
    },
    'useredit button[action=save]': {
    click: this.updateUser
    }
    });
    },


    editUser: function(grid, record) {
    console.log('Double clicked on ' + record.get( 'name' ) );
    var view = Ext.widget('useredit');
    view.down('form').loadRecord(record);
    },


    updateUserController: function(button) {
    console.log( 'UPDATE' );
    var win = button.up('window'),
    form = win.down('form'),
    record = form.getRecord(),
    values = form.getValues();


    record.set(values);
    win.close();
    this.getUsersStore().sync();


    }


    });
    Attached Files
    Last edited by denisputnam; 25 Apr 2012 at 6:59 AM. Reason: Added source to the body of the message.

  2. #2
    Sencha User
    Join Date
    Feb 2012
    Posts
    21
    Vote Rating
    1
    DracisFL is on a distinguished road

      0  

    Default


    Why not just create a listener for your save button in your controller to perform some action when clicked ? Also, this keeps all your coding in the Controller instead of having code in your view.
    dputnam.zip
    ================================================================
    to do this

    Right Click on your save button, click "Convert to Action" and assign to your "Users" Controller
    Attachment 34507

    Then place a reference in your controller to the saveBtn (this is an ID, I gave your button)
    Attachment 34508

    Make sure the button fuction has this reference in the controlQuery field
    Attachment 34509

    I jut put an alert on the button to show it works.... I'll leave the actually coding to you
    Attachment 34506

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    148
    Vote Rating
    2
    denisputnam is on a distinguished road

      0  

    Default That was a big help.

    That was a big help.


    Thank you DracisFL,

    That seems to work, however, I am getting "Uncaught TypeError: Object [object Object] has no method 'getUsersStore'" for the this.getUsersStore() below. Can you tell me how to get a hold of the store object so I can sync() it?

    -Denis


    Ext.define('AM.controller.Users', {
    extend: 'Ext.app.Controller',
    alias: 'controller.userscontroller',


    views: [
    'user.List',
    'user.Edit'
    ],
    id: 'userscontroller',


    refs: [
    {
    ref: 'saveBtn',
    selector: '#saveBtn'
    }
    ],


    init: function(application) {
    this.control({
    'viewport > userlist': {
    itemdblclick: this.editUser
    },
    'useredit button[action=save]': {
    click: this.updateUser
    }
    });
    this.control({
    '#saveBtn': {
    click: this.onButtonClickSave
    }
    });
    },


    editUser: function(grid, record) {
    console.log('Double clicked on ' + record.get( 'name' ) );
    var view = Ext.widget('useredit');
    view.down('form').loadRecord(record);
    },


    updateUserController: function(button) {
    console.log( 'UPDATE' );
    var win = button.up('window'),
    form = win.down('form'),
    record = form.getRecord(),
    values = form.getValues();


    record.set(values);
    win.close();
    this.getUsersStore().sync();


    },


    onButtonClickSave: function(button, e, options) {
    console.log( 'UPDATE' );
    var win = button.up('window'),
    form = win.down('form'),
    record = form.getRecord(),
    values = form.getValues();


    record.set(values);
    win.close();
    this.getUsersStore().sync();
    alert('Save happened' );
    }


    });
    Last edited by denisputnam; 25 Apr 2012 at 9:55 AM. Reason: Fixed mistake in post.

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    21
    Vote Rating
    1
    DracisFL is on a distinguished road

      0  

    Default


    I believe you are missing your store reference in your controller..

    screenshot1.png

    Click on the store field and add your store... and your model why you are at it..

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    148
    Vote Rating
    2
    denisputnam is on a distinguished road

      0  

    Default That was a big help.

    That was a big help.


    DracisFL,

    I learned quite a bit from you. Thank you very much.

    -Denis

  6. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    21
    Vote Rating
    1
    DracisFL is on a distinguished road

      0  

    Default


    no problem.. I'm trying to get my head around all this myself , I trust if I'm in error on any of my responses, someone with more experience will slap me down.

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