From cee461ebd92f081fb5d55612a7a116205040f4f6 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Sun, 6 Jan 2013 22:41:59 -0500 Subject: [PATCH] Breaking out javascript into js files instead of inline --- app/components/app_tab_panel.rb | 11 ++-------- .../app_tab_panel/javascripts/sign_out.js | 9 ++++++++ app/components/bikes.rb | 14 +----------- .../bikes/javascripts/init_component.js | 13 +++++++++++ app/components/bikes_border.rb | 17 +------------- .../javascripts/init_component.js | 14 ++++++++++++ app/components/brands_and_models_border.rb | 17 +------------- .../javascripts/init_component.js | 14 ++++++++++++ app/components/user_profile_border.rb | 16 +------------- .../javascripts/init_component.js | 13 +++++++++++ app/components/user_stats.rb | 10 +-------- .../user_stats/javascripts/user_stats.js | 8 +++++++ app/components/users_and_profiles_border.rb | 22 +------------------ .../javascripts/init_component.js | 19 ++++++++++++++++ 14 files changed, 98 insertions(+), 99 deletions(-) create mode 100644 app/components/app_tab_panel/javascripts/sign_out.js create mode 100644 app/components/bikes/javascripts/init_component.js create mode 100644 app/components/bikes_border/javascripts/init_component.js create mode 100644 app/components/brands_and_models_border/javascripts/init_component.js create mode 100644 app/components/user_profile_border/javascripts/init_component.js create mode 100644 app/components/user_stats/javascripts/user_stats.js create mode 100644 app/components/users_and_profiles_border/javascripts/init_component.js diff --git a/app/components/app_tab_panel.rb b/app/components/app_tab_panel.rb index 46fc83e..7442c27 100644 --- a/app/components/app_tab_panel.rb +++ b/app/components/app_tab_panel.rb @@ -39,15 +39,8 @@ class AppTabPanel < Netzke::Basepack::TabPanel end js_configure do |c| - c.on_sign_out = <<-JS - //this will give a 401 error, but made 401 exceptions forward to 'users/sign_in' - function(){ - Ext.Ajax.request({ - url: '/users/sign_out', - method: 'DELETE' - }); - } - JS + #gets js from app_tab_panel/javascripts/sign_out.js + c.mixin :sign_out end end diff --git a/app/components/app_tab_panel/javascripts/sign_out.js b/app/components/app_tab_panel/javascripts/sign_out.js new file mode 100644 index 0000000..d7c9bc3 --- /dev/null +++ b/app/components/app_tab_panel/javascripts/sign_out.js @@ -0,0 +1,9 @@ +{ + //this will give a 401 error, but made 401 exceptions forward to 'users/sign_in' + onSignOut: function(){ + Ext.Ajax.request({ + url: '/users/sign_out', + method: 'DELETE' + }); + } +} diff --git a/app/components/bikes.rb b/app/components/bikes.rb index 6f50825..8591975 100644 --- a/app/components/bikes.rb +++ b/app/components/bikes.rb @@ -37,19 +37,7 @@ class Bikes < Netzke::Basepack::Grid end js_configure do |c| - c.init_component = <<-JS - function(){ - // calling superclass's initComponent - this.callParent(); - - // setting the 'rowclick' event - var view = this.getView(); - view.on('itemclick', function(view, record){ - // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! - this.selectBikeBrand({bike_brand_id: record.get('bike_brand__brand')}); - }, this); - } - JS + c.mixin :init_component end endpoint :select_bike_brand do |params, this| diff --git a/app/components/bikes/javascripts/init_component.js b/app/components/bikes/javascripts/init_component.js new file mode 100644 index 0000000..402ef15 --- /dev/null +++ b/app/components/bikes/javascripts/init_component.js @@ -0,0 +1,13 @@ +{ + initComponent: function(){ + // calling superclass's initComponent + this.callParent(); + + // setting the 'rowclick' event + var view = this.getView(); + view.on('itemclick', function(view, record){ + // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! + this.selectBikeBrand({bike_brand_id: record.get('bike_brand__brand')}); + }, this); + } +} diff --git a/app/components/bikes_border.rb b/app/components/bikes_border.rb index 3883d92..a3480dc 100644 --- a/app/components/bikes_border.rb +++ b/app/components/bikes_border.rb @@ -16,22 +16,7 @@ class BikesBorder < Netzke::Base js_configure do |c| c.layout = :border c.border = false - - # Overriding initComponent - c.init_component = <<-JS - function(){ - // calling superclass's initComponent - this.callParent(); - - // setting the 'rowclick' event - var view = this.getComponent('bikes').getView(); - view.on('itemclick', function(view, record){ - // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! - this.selectBike({bike_id: record.get('id')}); - this.getComponent('bike_logs').getStore().load(); - }, this); - } - JS + c.mixin :init_component end endpoint :select_bike do |params, this| diff --git a/app/components/bikes_border/javascripts/init_component.js b/app/components/bikes_border/javascripts/init_component.js new file mode 100644 index 0000000..8637e43 --- /dev/null +++ b/app/components/bikes_border/javascripts/init_component.js @@ -0,0 +1,14 @@ +{ + initComponent: function(){ + // calling superclass's initComponent + this.callParent(); + + // setting the 'rowclick' event + var view = this.getComponent('bikes').getView(); + view.on('itemclick', function(view, record){ + // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! + this.selectBike({bike_id: record.get('id')}); + this.getComponent('bike_logs').getStore().load(); + }, this); + } +} diff --git a/app/components/brands_and_models_border.rb b/app/components/brands_and_models_border.rb index f7d004d..727d17b 100644 --- a/app/components/brands_and_models_border.rb +++ b/app/components/brands_and_models_border.rb @@ -16,22 +16,7 @@ class BrandsAndModelsBorder < Netzke::Base js_configure do |c| c.layout = :border c.border = false - - # Overriding initComponent - c.init_component = <<-JS - function(){ - // calling superclass's initComponent - this.callParent(); - - // setting the 'rowclick' event - var view = this.getComponent('bike_brands').getView(); - view.on('itemclick', function(view, record){ - // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! - this.selectBikeBrand({bike_brand_id: record.get('id')}); - this.getComponent('bike_models').getStore().load(); - }, this); - } - JS + c.mixin :init_component end endpoint :select_bike_brand do |params, this| diff --git a/app/components/brands_and_models_border/javascripts/init_component.js b/app/components/brands_and_models_border/javascripts/init_component.js new file mode 100644 index 0000000..8237d3a --- /dev/null +++ b/app/components/brands_and_models_border/javascripts/init_component.js @@ -0,0 +1,14 @@ +{ + initComponent: function(){ + // calling superclass's initComponent + this.callParent(); + + // setting the 'rowclick' event + var view = this.getComponent('bike_brands').getView(); + view.on('itemclick', function(view, record){ + // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! + this.selectBikeBrand({bike_brand_id: record.get('id')}); + this.getComponent('bike_models').getStore().load(); + }, this); + } +} diff --git a/app/components/user_profile_border.rb b/app/components/user_profile_border.rb index 2b5aa20..5067bb0 100644 --- a/app/components/user_profile_border.rb +++ b/app/components/user_profile_border.rb @@ -18,21 +18,7 @@ class UserProfileBorder < Netzke::Base js_configure do |c| c.layout = :border c.border = false - - # Overriding initComponent - c.init_component = <<-JS - function(){ - // calling superclass's initComponent - this.callParent(); - this.getComponent('user_stats').updateStats(); - - var store = this.getComponent('user_logs').getStore() - store.on('load', function (store, records, operation, success){ - console.log("Bitches"); - this.getComponent('user_stats').updateStats(); - }, this); - } - JS + c.mixin :init_component end end diff --git a/app/components/user_profile_border/javascripts/init_component.js b/app/components/user_profile_border/javascripts/init_component.js new file mode 100644 index 0000000..c5a338b --- /dev/null +++ b/app/components/user_profile_border/javascripts/init_component.js @@ -0,0 +1,13 @@ +{ + initComponent: function(){ + // calling superclass's initComponent + this.callParent(); + this.getComponent('user_stats').updateStats(); + + var store = this.getComponent('user_logs').getStore() + store.on('load', function (store, records, operation, success){ + console.log("Bitches"); + this.getComponent('user_stats').updateStats(); + }, this); + } +} diff --git a/app/components/user_stats.rb b/app/components/user_stats.rb index 554269a..3a82704 100644 --- a/app/components/user_stats.rb +++ b/app/components/user_stats.rb @@ -15,15 +15,7 @@ class UserStats < Netzke::Base js_configure do |c| c.body_padding = 15 c.title = "User Stats" - #c.html = body_content() - c.update_stats = <<-JS - function(){ - // Call endpoint - this.serverUpdate({}, function(){ - //success callback - }, this); - } - JS + c.mixin :user_stats end endpoint :server_update do |params, this| diff --git a/app/components/user_stats/javascripts/user_stats.js b/app/components/user_stats/javascripts/user_stats.js new file mode 100644 index 0000000..7584a22 --- /dev/null +++ b/app/components/user_stats/javascripts/user_stats.js @@ -0,0 +1,8 @@ +{ + updateStats: function(){ + // Call endpoint + this.serverUpdate({}, function(){ + //success callback + }, this); + } +} diff --git a/app/components/users_and_profiles_border.rb b/app/components/users_and_profiles_border.rb index a6dff69..11b6209 100644 --- a/app/components/users_and_profiles_border.rb +++ b/app/components/users_and_profiles_border.rb @@ -18,27 +18,7 @@ class UsersAndProfilesBorder < Netzke::Base js_configure do |c| c.layout = :border c.border = false - - # Overriding initComponent - c.init_component = <<-JS - function(){ - // calling superclass's initComponent - this.callParent(); - var stats = this.getComponent('user_stats'); - if (stats != undefined){ - stats.updateStats(); - } - - // setting the 'rowclick' event - var view = this.getComponent('users').getView(); - view.on('itemclick', function(view, record){ - // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! - this.selectUser({user_id: record.get('id')}); - this.getComponent('user_profiles').getStore().load(); - this.getComponent('user_logs').getStore().load(); - }, this); - } - JS + c.mixin :init_component end endpoint :select_user do |params, this| diff --git a/app/components/users_and_profiles_border/javascripts/init_component.js b/app/components/users_and_profiles_border/javascripts/init_component.js new file mode 100644 index 0000000..616de1f --- /dev/null +++ b/app/components/users_and_profiles_border/javascripts/init_component.js @@ -0,0 +1,19 @@ +{ + initComponent: function(){ + // calling superclass's initComponent + this.callParent(); + var stats = this.getComponent('user_stats'); + if (stats != undefined){ + stats.updateStats(); + } + + // setting the 'rowclick' event + var view = this.getComponent('users').getView(); + view.on('itemclick', function(view, record){ + // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! + this.selectUser({user_id: record.get('id')}); + this.getComponent('user_profiles').getStore().load(); + this.getComponent('user_logs').getStore().load(); + }, this); + } +}