Refactoring suggestions
|
|
I have just been looking into the source of GamingTrends, since I want to use Rails with ExtJS and find it a somewhat good inspiration. To get up and running I first had to setup the MySql database with the schema. I had problems using the migrations. I got some errors on the E304 and descrip index og Games. (BLOG/TEXT requires a length key, tried adding a :limit => 1000, but didn’t work!?) To import the schema into a mysql database, I recommend removing Games indexes “E304” and “descrip” from the first migration. They are deleted on the cleanup migrations anyways! Finally I got the app up and running, but I was unable to create Posts! in the source code /app/views/post/new.rhtml — Looking into the code: I feel the ExtJS infrastructure can be vastly improved by scrapping the ext helper function in application_helper.rb and refactoring them. I came up with the following refactoring solution: application_helper.rb
games/index.rhtml <= ext_layout(‘Games’) %> shared/_ext_grid.rhtml
PageGrid.filterResource = function() {
filtervalue = Ext.get(‘text_filter’).dom.value;
ds.proxy = new Ext.data.HttpProxy({
method: ‘GET’,
url: ‘<%= models %>.json?search=’ + filtervalue}
);
ds.reload(); PageGrid.deleteResource = function() {
var id = grid.getSelectionModel().getSelected();
if(id){
Ext.MessageBox.confirm(‘Confirm’, ‘Are you sure you want to delete this <%= model %>?’, postDelete);
} else {
Ext.MessageBox.alert(‘DOH!’, ‘Maybe you want to try again after ACTUALLY selecting something?’)
} PageGrid.submitResource = function(){
document.create_resource.submit(); PageGrid.postDelete = function(btn){
if(btn == ‘yes’) {
var id = grid.getSelectionModel().getSelected();
var deleteme = id.get(‘<%= primary_key %>‘);
window.location.href = ’/<%= models %>/destroy/’ + deleteme;
} PageGrid.editResource = function (grid, rowIndex) {
var id = grid.getSelectionModel().getSelected();
if(id) {
window.location.href = ’/<= models %>/’ + id.get(‘<= primary_key %>‘);
} Ext.onReady(pageGrid.init, pageGrid, true); shared/_news_fun.rhtml PageGrid.renderNews = function(value, p, record) {
return String.format(‘{0} PageGrid.renderNewsPlain = function(value) {
return String.format(‘{0}’, value); PageGrid.toggleNews = function(btn, pressed) {
cm.getColumnById(‘Headline’).renderer = pressed ? renderNews : renderNewsPlain;
grid.getView().refresh(); var formatBoolean = function (value) { return (value == 1) ? ‘Yes’ : ‘IMO. I will see where I get from here… |