Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
138 lines (120 sloc) 5.27 KB
<!DOCTYPE html>
<html>
<head>
<title>sencha-wakanda :: model</title>
<link rel="stylesheet" href="http://extjs.cachefly.net/ext-4.0.2a/resources/css/ext-all-gray.css" type="text/css" media="screen" charset="utf-8">
</head>
<body>
<script type="text/javascript" src="http://extjs.cachefly.net/ext-4.0.2a/ext-all.js"></script>
<script type="text/javascript" src="https://raw.github.com/revolunet/sencha-wakanda/master/extjs/4.0.2a/Ext.data.writer.Wakanda.js"></script>
<script type="text/javascript" src="https://raw.github.com/revolunet/sencha-wakanda/master/extjs/4.0.2a/Ext.data.reader.Wakanda.js"></script>
<script type="text/javascript" src="https://raw.github.com/revolunet/sencha-wakanda/master/extjs/4.0.2a/Ext.data.proxy.Wakanda.js"></script>
<script type="text/javascript" src="https://raw.github.com/revolunet/sencha-wakanda/master/extjs/4.0.2a/Ext.data.WakandaModel.js"></script>
<script type="text/javascript">
Ext.define('Employee', {
extend: 'Ext.data.WakandaModel'
});
Ext.onReady(function() {
var destroy = function() {
var buttons = this.ownerCt.items,
employee = form.getRecord();
id = employee.getId();
form.getForm().reset();
buttons.getAt(0).hide();
buttons.getAt(3).hide();
buttons.getAt(4).show();
employee.destroy({
success: function() {
Ext.Msg.alert('Success', 'Employee ' + id + ' has been destroyed!');
}
});
};
var reset = function() {
var buttons = this.ownerCt.items;
form.getForm().reset();
buttons.getAt(3).hide();
buttons.getAt(4).show();
};
var update = function() {
if (form.getForm().isValid()) {
var values = form.getValues(),
employee = form.getRecord();
employee.set(values);
employee.save({
success: function(employee) {
Ext.Msg.alert('Success', 'Employee ' + employee.getId() + ' has been updated!');
}
});
}
};
var create = function() {
if (form.getForm().isValid()) {
var values = form.getValues(),
employee = Ext.create('Employee', values),
buttons = this.ownerCt.items;
employee.save({
success: function(employee) {
form.loadRecord(employee);
buttons.getAt(0).show();
buttons.getAt(3).show();
buttons.getAt(4).hide();
Ext.Msg.alert('Success', 'Employee ' + employee.getId() + ' has been created!');
}
});
}
};
var Employee = Ext.ModelManager.getModel('Employee');
var form = Ext.create('Ext.form.Panel', {
x: 20,
y: 20,
floating: true,
frame: true,
bodyPadding: 5,
width: 350,
buttonAlign: 'left',
layout: 'anchor',
renderTo: document.body,
defaults: {anchor: '100%'},
defaultType: 'textfield',
items: [{
xtype: 'displayfield',
fieldLabel: 'ID',
name: 'ID'
}, {
fieldLabel: 'First Name',
name: 'firstName',
allowBlank: false
},{
fieldLabel: 'Last Name',
name: 'lastName',
allowBlank: false
}, {
xtype: 'numberfield',
fieldLabel: 'Salary',
name: 'salary'
}],
buttons: [{
text: 'Delete',
hidden: true,
handler: destroy
}, '->', {
text: 'Reset',
handler: reset
}, {
text: 'Update',
handler: update
}, {
text: 'Create',
hidden: true,
handler: create
}]
});
Employee.load(3083, {
success: function(employee) {
form.loadRecord(employee);
}
});
});
</script>
</body>
</html>