Browse Source

Breaking out javascript into js files instead of inline

denney-disable-on-select
Jason Denney 12 years ago
parent
commit
cee461ebd9
  1. 11
      app/components/app_tab_panel.rb
  2. 9
      app/components/app_tab_panel/javascripts/sign_out.js
  3. 14
      app/components/bikes.rb
  4. 13
      app/components/bikes/javascripts/init_component.js
  5. 17
      app/components/bikes_border.rb
  6. 14
      app/components/bikes_border/javascripts/init_component.js
  7. 17
      app/components/brands_and_models_border.rb
  8. 14
      app/components/brands_and_models_border/javascripts/init_component.js
  9. 16
      app/components/user_profile_border.rb
  10. 13
      app/components/user_profile_border/javascripts/init_component.js
  11. 10
      app/components/user_stats.rb
  12. 8
      app/components/user_stats/javascripts/user_stats.js
  13. 22
      app/components/users_and_profiles_border.rb
  14. 19
      app/components/users_and_profiles_border/javascripts/init_component.js

11
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

9
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'
});
}
}

14
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|

13
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);
}
}

17
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|

14
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);
}
}

17
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|

14
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);
}
}

16
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

13
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);
}
}

10
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|

8
app/components/user_stats/javascripts/user_stats.js

@ -0,0 +1,8 @@
{
updateStats: function(){
// Call endpoint
this.serverUpdate({}, function(){
//success callback
}, this);
}
}

22
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|

19
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);
}
}
Loading…
Cancel
Save