PDA

View Full Version : My RowEditing don't work more on 4.2!



re.tf
11 Jun 2013, 12:44 PM
Hi,
I have this code that work on 4.1, but don't work on 4.2, any one know how to fix?


// ...
listeners : {validateedit:function(editor, e, eOpts) {
alert(e.newValues.id); // work on 4.1 (I have my id), but don't work on 4.2 (is null)!

Thanks

slemmon
12 Jun 2013, 9:13 PM
Can you offer a more complete code example?

re.tf
14 Jun 2013, 6:13 AM
Thanks for help!



<SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
<!--


// HERE v3.5 -->
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', 'https://d90xffihona40.cloudfront.net/<%= $ext %>/examples/ux');
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.state.*',
'Ext.toolbar.Paging',
'Ext.form.*'
]);


//
// Free functions
//


function setMailTitle(title)
{
$("input#_subject").val(title);
}


function setMailMessage(message)
{
$("textarea#_message").val(message);
}


//
// BSase onReady
//


Ext.onReady(function(){
// -
Ext.define('Track', {
extend: 'Ext.data.Model',
fields: [
'id',
'track_status',
'status_description',
{name: 'date_entered' , type: 'date', dateFormat: 'd.m.Y H.i.s'},
'pointer',
'xnome_emit',
'cnpj_emit',
'chnfe',
'nnf',
'vnf',
'natop',
{name: 'demi', type: 'date', dateFormat: 'd.m.Y H.i.s'}
],
idProperty: 'id'
}); // Track


var store = Ext.create('Ext.data.Store', {
pageSize: 15,
model: 'Track',
remoteSort: true,
proxy: {
type: 'ajax',
url: 'https://<%= $url->host %>/dswapi/1.0/json/domain-product-nfe-file1-track/<%== $did %>?query=<%== $query %>&m=<%== $m %>&y=<%== $y %>',
headers:
{
'Authorization' : '<%== $tok %>'
},
reader:
{
root: 'list',
totalProperty: 'total_count'
},
// sends single sort as multi parameter
simpleSortMode: true
},
sorters: [{
property: 'date_entered',
direction: 'DESC'
}]
});




var downloadAction = Ext.create('Ext.Action',
{
icon : 'https://d90xffihona40.cloudfront.net/<%= $ext %>/examples/shared/icons/fam/cog.png', // Use a URL in the icon config
text: 'Download da NFE',
disabled: true,
handler: function(widget, event)
{
var rec = grid.getSelectionModel().getSelection()[0];


if (rec)
{
// v 3.5
window.open('https://<%= $url->host %>/system/services/download.xml?depot=' + rec.get('id') + '&did=<%= $self->session('domain') %>&fsname=nfe&auth=<%=$self->session('token')%>');
}
else
{
alert('Selecione um item na grid');
}
}
});


var danfeGenAction = Ext.create('Ext.Action',
{
icon : 'https://d90xffihona40.cloudfront.net/<%= $ext %>/examples/shared/icons/fam/cog.png', // Use a URL in the icon config
text: 'Gerar DANFE em PDF',
disabled: true,
handler: function(widget, event)
{
var rec = grid.getSelectionModel().getSelection()[0];


if (rec)
{
// v 3.5
window.open('https://<%= $url->host %>/extensions/nfephp/danfe/generator/render-nfe-gridfs.php?ntp=outPut&baseurl=<%= $url->host %>&depot=' + rec.get('id') + '&did=<%= $self->session('domain') %>&fsname=nfe&auth=<%=$self->session('token')%>');
}
else
{
alert('Selecione um item na grid');
}
}
});



var contextMenu = Ext.create('Ext.menu.Menu', {
items: [
downloadAction, danfeGenAction
]
});


// ext 4.2
// Ext.grid.plugin.RowEditing.prototype.cancelBtnText = "Cancelar";
// Ext.grid.plugin.RowEditing.prototype.saveBtnText = "Atualizar";
// Ext.grid.plugin.RowEditing = new Ext.grid.plugin.RowEditing();


// ext 4.1
Ext.grid.RowEditor.prototype.cancelBtnText = "Cancelar";
Ext.grid.RowEditor.prototype.saveBtnText = "Atualizar";
Ext.grid.RowEditor = new Ext.grid.RowEditor();


var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false
});


function renderStatus(value, p, record)
{
// 0 : disabled, 1 : pendente, 2 : resolvido, 3 : aguardando
if(record.data.track_status == 0)
{
return Ext.String.format(
'<b>{0}</b>',
'Desativado'
);
}
else if(record.data.track_status == 1)
{
return Ext.String.format(
'<b>{0}</b>',
'Pendente'
);
}
else if(record.data.track_status == 2)
{
return Ext.String.format(
'<b>{0}</b>',
'Recebida'
);
}
else if(record.data.track_status == 3)
{
return Ext.String.format(
'<b>{0}</b>',
'Recusada'
);
}
}


var pluginExpanded = true;
var grid = Ext.create('Ext.grid.Panel', {
width: 955,
height: 300,
enableColumnHide: false,
store: store,
//disableSelection: true,
// grid columns
columns:[
{
text: "Status",
dataIndex: 'track_status',
width: 150,
sortable: false,
renderer: renderStatus,
editor: new Ext.form.field.ComboBox({
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
store: [
// 0 : disabled, 1 : PENDENTE (A RECEBER), 2 : RECEBIDA, 3 : RECUSADA
['0','Desabilitado'],
['1','Pendente'],
['2','Recebida'],
['3','Recusada']
],
lazyRender: true,
listClass: 'x-combo-list-small'
})
},
{
text : "Descri&ccedil;&atilde;o",
dataIndex: 'status_description',
flex : 1,
sortable : false,
editor: {
// defaults to textfield if no xtype is supplied
allowBlank: false
}
},
{
text : 'Data/Hora Entrada',
width : 120,
renderer : Ext.util.Format.dateRenderer('d/m/Y H:i:s'),
dataIndex: 'date_entered',
sortable : true
},
{
text : "Raz&atilde;o Social Emitente",
dataIndex: 'xnome_emit',
width : 180,
sortable : true
},
{
text : "Chave NF-e",
dataIndex: 'chnfe',
width : 290,
sortable : true
},
{
text: "N. NF-e",
dataIndex: 'nnf',
width: 60,
sortable: true
},
{
text: "id",
dataIndex: 'id',
width: 250,
hidden: true
}],
listeners : {



itemcontextmenu: function(view, rec, node, index, e) {
e.stopEvent();
contextMenu.showAt(e.getXY());
return false;
},




//beforeedit: function(editor, e) {
//},


validateedit: function(editor, e, eOpts) {


//alert(e.newValues.id);
//alert(e.newValues.status_description);
//alert(e.newValues.track_status);
//alert(e.newValues['track_status']);


var str = e.newValues.status_description;
var fine_status = str.replace(/['^"]/g, '');


Ext.Ajax.request( {
waitMsg: 'Gravando...',
headers: {
'Authorization' : '<%== $self->session('token') %>'
},
url: 'https://<%= $url->host %>/dswapi/1.0/json/domain-product-nfe-file1-track/' + e.newValues.id,
method: 'POST',


// //////////////////////////////////////////////////////////////////////////////////////////////
params: {
_status: fine_status,
_status_id: e.newValues.track_status,
_domain_id: '<%== $did %>'
},
// //////////////////////////////////////////////////////////////////////////////////////////////


failure:function(response,options){
Ext.MessageBox.alert('Erro','Tente novamente mais tarde...');
},


success:function(response,options){
// Ext.MessageBox.alert('Successo!','Prefer&ecirc;ncia Salvas');
// var responseData = Ext.util.JSON.decode(response.responseText);
} //end success block


}); //end request
}
},


// paging bar on the bottom
bbar: Ext.create('Ext.PagingToolbar', {
store: store,
displayInfo: true,
displayMsg: 'Rastro {0} - {1} de {2}',
emptyMsg: "Nenhum Rastro"
}),


renderTo: 'gridAnchor',
plugins: [rowEditing],


});


grid.getSelectionModel().on({
selectionchange: function(sm, selections) {
if (selections.length) {
downloadAction.enable();
danfeGenAction.enable();
} else {
downloadAction.disable();
danfeGenAction.disable();
}
}
});


// trigger the data store load
store.loadPage(1);


// -
}); // Ext.onReady


-->
</script>
Thanks

slemmon
14 Jun 2013, 11:48 AM
The following example works for me in 4.1.1 and 4.2.1 alike.
Does it for you?
*don't forget to wrap your code in code tags for readability



Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['id', 'name', 'email', 'phone'],
data: [
{"id": 1, "name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
{"id": 2, "name":"Bart", "email":"bart@simpsons.com", "phone":"555-222-1234"},
{"id": 3, "name":"Homer", "email":"home@simpsons.com", "phone":"555-222-1244"},
{"id": 4, "name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
]
});


Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Id', dataIndex: 'id'},
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'}
],
selType: 'rowmodel',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody(),
listeners: {
validateedit: function (editor, context) {
console.log(context.newValues.id);
}
}
});