3

window for additing record

I have one problem with adding new button for update my records in Ext-Js 3.0. I have already one window for creating new record and I intend to use the same window for editing one of the records. The question is: how can I load the record what I have choosen from existing records int the columns of the window for creating record? This code for adding a new record, I would like to load the content of such record in this window if I update it. Is it possible? I think I need something like store.load.record.data['id']?

Thank you in advance for your help.

var winAdd = new Ext.Window({
    id: 'winAdd',
    renderTo: Ext.getBody(),
    layout: 'fit',
    width: 400,
    autoHeight: true,
    closeAction: 'hide',
    closable: false,
    title: 'add item',
    plain: true,
    items: {
        xtype: 'form',
        id: 'frmAdd',
        autoHeight: true,
        frame: true,
        defaultType: 'textfield',
        border: false,
        dock_id: <?=$_SESSION['user']->getDock()->getId()?>,
        defaults: {allowBlank: true, anchor: '95%'},
        items: [{
            fieldLabel: 'dock',
            hiddenName: 'dock',
            name: 'dock',
            xtype: 'combo',
            store: strRamps,
            displayField: 'name',
            valueField: 'id',
            typeAhead: true,
            mode: 'local',
            triggerAction: 'all',
            forceSelection: true
        },

This is code for update the record:

new Ext.Toolbar.Button({
    text: '<?= $this→translate('edit item') ?>',
    handler: function () {
        Ext.getCmp('winAdd').show(this);
        var conn = new Ext.data.Connection();
        conn.request({
            url: 'example/updateItem',
            method: 'POST',
            params: {id: gridPanel.selModel.selection.record.data['id']},
            success: function (responseObject) {
                store.update(gridPanel.selModel.selection.record);
            },
    })
}
}
Svetlana
  • 141
  • 5

1 Answers1

0

The problem with the window for adding new record was solved: I use now only one window and have two buttons one for updating and one for adding new record. How it works:

  1. I added new varibale for the booking. If the booking is new the value of variable is null und if the booking exists the value of the variabe is id of this booking.

    var editBooking = null;

  2. I use this variable by saving and send booking id with the other params in ajax request in this way:

handler: function () {
var form = Ext.getCmp('frmAdd').getForm();
                        Ext.Ajax.request({
                            url: '/example/example2',
params: {    'id': editBookingId,'company': form.findField('company').getValue()    } 

}

  1. In my Controller in php I take the value (booking_id) from the request and check if the value is 0 oder id.

For rendering the values of the selected record (by clicking the button update) I use this syntax:

> form.findField('example_name').setValue(gridPanel.selModel.selection.record.data['example_id']);
>                         form.findField('start').setValue(gridPanel.selModel.selection.record.data['start']);
Svetlana
  • 141
  • 5