public
Last active

  • Download Gist
book.js
JavaScript
1 2 3 4 5 6 7 8 9 10
Ext.define('Book', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'},
{name: 'thumb_image_path', type: 'string'},
{name: 'user_id', type: 'int'}
],
proxy: { url: "/books", type: 'rest', format: "json" }
});
booksformpanel.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Ext.define("BooksFormPanel", {
extend: "Ext.form.Panel",
alias: "widget.booksformpanel",
salvar: function(){
var json = this.getForm().getValues();
this.update_attributes( json );
if( this.callback ) this.callback.call( this.parentScope || this )
},
update_attributes: function(json) {
var model = this.getForm().getRecord();
for(var field in json) {
model.set(field, json[field] );
}
model.save();
},
initComponent: function() {
this.items = [
{ xtype: "textfield", fieldLabel: "Title", name: "title" },
{ xtype: "hidden", name: "id" },
];
this.buttons = [{text: "Salvar", handler: this.salvar, scope: this}]
this.callParent(arguments);
this.getForm().loadRecord(this.model);
}
})
booksgrid.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Ext.define("BooksGrid", {
extend: "Ext.grid.Panel",
alias: "widget.booksgrid",
abrirTela: function(record) {
Ext.create('Ext.window.Window', {
title: "Editar livro", modal:true,
width: 400,
items: [{xtype: "booksformpanel", model: record}]
}).show();
 
 
},
initComponent: function() {
this.columns = [{
header: "Title", dataIndex: "title"
}];
this.store = {model: "Book"};
 
this.listeners = {
itemdblclick: {
scope: this,
fn: function(g, record){ this.abrirTela(record) }
}
};
this.callParent(arguments);
this.store.load();
}
})
 
Ext.create('Ext.window.Window', {
title: "Lista de livros",
width: 400,
items: [{xtype: "booksgrid"}]
}).show();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.