mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-11-03 17:15:34 -05:00 
			
		
		
		
	Added reset password action column to users comp.
This commit is contained in:
		
							parent
							
								
									761ab81b56
								
							
						
					
					
						commit
						0ef4e81474
					
				@ -1,4 +1,13 @@
 | 
				
			|||||||
class Users < Netzke::Basepack::Grid
 | 
					class Users < Netzke::Basepack::Grid
 | 
				
			||||||
 | 
					  include Netzke::Basepack::ActionColumn
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  column :reset do |c|
 | 
				
			||||||
 | 
					    c.type = :action
 | 
				
			||||||
 | 
					    c.actions = [{name: :reset_password, icon: :lock_break}]
 | 
				
			||||||
 | 
					    c.header = ""
 | 
				
			||||||
 | 
					    c.width = 20
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def configure(c)
 | 
					  def configure(c)
 | 
				
			||||||
    super
 | 
					    super
 | 
				
			||||||
    c.header = false
 | 
					    c.header = false
 | 
				
			||||||
@ -11,6 +20,8 @@ class Users < Netzke::Basepack::Grid
 | 
				
			|||||||
      :email,
 | 
					      :email,
 | 
				
			||||||
      :bike__shop_id
 | 
					      :bike__shop_id
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    c.columns << :reset if can? :manage, User
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #override with nil to remove actions
 | 
					  #override with nil to remove actions
 | 
				
			||||||
 | 
				
			|||||||
@ -4,8 +4,32 @@
 | 
				
			|||||||
    this.callParent();
 | 
					    this.callParent();
 | 
				
			||||||
    this.getView().on('itemclick', function(view, record){
 | 
					    this.getView().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!
 | 
					      // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server!
 | 
				
			||||||
      console.log("user: " + record.get('id') );
 | 
					 | 
				
			||||||
      this.selectCustomer({customer_id: record.get('id'), customer_type: 'User'});
 | 
					      this.selectCustomer({customer_id: record.get('id'), customer_type: 'User'});
 | 
				
			||||||
    }, this);
 | 
					    }, this);
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  onResetPassword: function(record){
 | 
				
			||||||
 | 
					    user = record.data;
 | 
				
			||||||
 | 
					    Ext.Msg.confirm(
 | 
				
			||||||
 | 
					      "Reset Password",
 | 
				
			||||||
 | 
					      "Are you sure you want to reset "+user.first_name+" "+user.last_name+"'s password?",
 | 
				
			||||||
 | 
					      function(butt_id){
 | 
				
			||||||
 | 
					        if( butt_id === "yes" ){
 | 
				
			||||||
 | 
					          $.ajax({
 | 
				
			||||||
 | 
					            type: 'POST',
 | 
				
			||||||
 | 
					            url: '/api/v1/reset',
 | 
				
			||||||
 | 
					            dataType: 'json',
 | 
				
			||||||
 | 
					            contentType: 'application/json',
 | 
				
			||||||
 | 
					            processData: false,
 | 
				
			||||||
 | 
					            data: JSON.stringify({"user_id": user.id}),
 | 
				
			||||||
 | 
					            complete: function() { },
 | 
				
			||||||
 | 
					            success: function(data) {
 | 
				
			||||||
 | 
					              Ext.Msg.alert("Success", "New Password: "+data.password);
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            error: function(data,textStatus) {
 | 
				
			||||||
 | 
					              Ext.Msg.alert( "Error", JSON.parse(data.responseText)["error"]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@ class UsersAndProfilesBorder < Netzke::Base
 | 
				
			|||||||
    super
 | 
					    super
 | 
				
			||||||
    c.header = false
 | 
					    c.header = false
 | 
				
			||||||
    c.items = [
 | 
					    c.items = [
 | 
				
			||||||
     { netzke_component: :users, header: "Users", region: :center, width: 300, split: true },
 | 
					     { netzke_component: :users, header: "Users", region: :center, width: 350, split: true },
 | 
				
			||||||
     { netzke_component: :user_profiles, region: :south, height: 150, split: true},
 | 
					     { netzke_component: :user_profiles, region: :south, height: 150, split: true},
 | 
				
			||||||
     { netzke_component: :user_logs, region: :east, split: true}
 | 
					     { netzke_component: :user_logs, region: :east, split: true}
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user