Skip to content

Instantly share code, notes, and snippets.

@cmilfont
Created November 30, 2012 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cmilfont/4172995 to your computer and use it in GitHub Desktop.
Save cmilfont/4172995 to your computer and use it in GitHub Desktop.
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" }
});
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);
}
})
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment