mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 08:55:36 -04:00 
			
		
		
		
	Creating Transactions works
-Need to scope transactions for users -Only Admins should be able to create transactions
This commit is contained in:
		
							parent
							
								
									1b7daa45ca
								
							
						
					
					
						commit
						2d51bd1d9a
					
				| @ -10,7 +10,7 @@ class AppTabPanel < Netzke::Basepack::TabPanel | ||||
| 
 | ||||
|     #all users | ||||
|     #  (had to use hash for borders to get the title to display properly) | ||||
|     @@app_tab_panel_items = [ :transactions, :bikes_border, {layout: :fit, wrappedComponent: :brands_and_models_border, title: "Brands/Models"}] | ||||
|     @@app_tab_panel_items = [ :transactions_border, :bikes_border, {layout: :fit, wrappedComponent: :brands_and_models_border, title: "Brands/Models"}] | ||||
| 
 | ||||
|     #for users | ||||
|     if controller.current_user.user? | ||||
|  | ||||
							
								
								
									
										10
									
								
								app/components/customers.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/components/customers.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| class Customers < Netzke::Basepack::Grid | ||||
|   def configure(c) | ||||
|     c.model = "Customer" | ||||
|   end | ||||
| 
 | ||||
|   #override with nil to remove actions | ||||
|   def default_bbar | ||||
|     [ :apply, :add_in_form, :search ] | ||||
|   end | ||||
| end | ||||
| @ -4,8 +4,8 @@ class Transactions < Netzke::Basepack::Grid | ||||
|     c.model = "Transaction" | ||||
|     c.strong_default_attrs = { | ||||
|       :vendor_id => controller.current_user.id, | ||||
|       :customer_id => session[:selected_user_id], | ||||
|       :customer_type => session[:selected_type] | ||||
|       :customer_id => session[:selected_customer_id], | ||||
|       :customer_type => session[:selected_customer_type] | ||||
|     } | ||||
|     c.columns = [ | ||||
|       :amount, | ||||
| @ -23,7 +23,13 @@ class Transactions < Netzke::Basepack::Grid | ||||
|   def default_fields_for_forms | ||||
|     bike_store = Bike.all.map { |b| [b.id, b.serial_number] } | ||||
|     user_store = User.all.map { |u| [u.id, u.to_s] } | ||||
|     customer = User.find_by_id(session[:selected_user_id]) | ||||
|     customer = nil | ||||
|     if session[:selected_customer_type] == "User" | ||||
|       customer = User.find_by_id(session[:selected_customer_id]) | ||||
|     elsif session[:selected_customer_type] == "Customer" | ||||
|       customer = Customer.find_by_id(session[:selected_customer_id]) | ||||
|     end | ||||
|      | ||||
|     customer = "No User Selected" if customer.nil? | ||||
|     [ | ||||
|       { :no_binding => true, :xtype => 'label', :text => "Creating Transaction for: #{customer.to_s}"}, | ||||
| @ -37,14 +43,8 @@ class Transactions < Netzke::Basepack::Grid | ||||
|     ] | ||||
|   end | ||||
| 
 | ||||
|   js_configure do |c| | ||||
|     c.mixin :init_component | ||||
|   #override with nil to remove actions | ||||
|   def default_bbar | ||||
|     [ :apply, :add_in_form, :search ] | ||||
|   end | ||||
| 
 | ||||
|   endpoint :select_user do |params, this| | ||||
|     # store selected boss id in the session for this component's instance | ||||
|     session[:selected_user_id] = params[:user_id] | ||||
|     session[:selected_type] = 'User' | ||||
|   end | ||||
| 
 | ||||
| end | ||||
|  | ||||
| @ -5,12 +5,14 @@ | ||||
| 
 | ||||
|     // setting the 'rowclick' event
 | ||||
|     var user_view = this.getComponent('users').getView(); | ||||
|     var customer_view = this.getComponent('users').getView(); | ||||
|     var customer_view = this.getComponent('customers').getView(); | ||||
|     user_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!
 | ||||
|       console.log("user: " + record.get('id') ); | ||||
|       this.selectCustomer({customer_id: record.get('id'), customer_type: 'User'}); | ||||
|     }, this); | ||||
|     customer_view.on('itemclick', function(view, record){ | ||||
|       console.log("user: " + record.get('id') ); | ||||
|       this.selectCustomer({customer_id: record.get('id'), customer_type: 'Customer'}); | ||||
|     }, this); | ||||
|   } | ||||
|  | ||||
| @ -2,7 +2,17 @@ class Customer < ActiveRecord::Base | ||||
|   attr_accessible :first_name, :last_name, :addrStreet1, | ||||
|     :addrStreet2, :addrCity, :addrState, :addrZip, :phone, :email | ||||
| 
 | ||||
|   has_many :transactions | ||||
|   has_many :transactions, :as => :customer | ||||
| 
 | ||||
|   validates :first_name, :presence => true | ||||
|   validates :last_name, :presence => true | ||||
|   #validates :addrStreet1, :presence => true | ||||
|   #validates :addrStreet2, :presence => true | ||||
|   #validates :addrCity, :presence => true | ||||
|   #validates :addrState, :presence => true | ||||
|   #validates :addrZip, :presence => true | ||||
|   #validates :phone, :presence => true | ||||
|   #validates :email, :presence => true | ||||
| 
 | ||||
|   def to_s | ||||
|     "#{first_name} #{last_name}" | ||||
|  | ||||
| @ -5,7 +5,7 @@ class Transaction < ActiveRecord::Base | ||||
| 
 | ||||
|   belongs_to :vendor, :class_name => 'User', :foreign_key => 'vendor_id' | ||||
|   belongs_to :bike | ||||
|   belongs_to :customer | ||||
|   belongs_to :customer, :polymorphic => true | ||||
| 
 | ||||
|   validates :vendor_id, :presence => true | ||||
|   validates :customer_id, :presence => { :message => "Choose a User or Customer"} | ||||
|  | ||||
| @ -3,7 +3,7 @@ class CreateTransactions < ActiveRecord::Migration | ||||
|     create_table :transactions do |t| | ||||
|       t.integer "vendor_id", :null => false | ||||
|       t.integer "customer_id", :null => false | ||||
|       t.integer "customer_type", :null => false | ||||
|       t.string "customer_type", :null => false | ||||
|       t.integer "bike_id" | ||||
|       t.integer "amount", :null => false | ||||
|       t.string  "item", :null => false | ||||
|  | ||||
| @ -104,8 +104,8 @@ ActiveRecord::Schema.define(:version => 20130120142249) do | ||||
| 
 | ||||
|   create_table "transactions", :force => true do |t| | ||||
|     t.integer  "vendor_id",     :null => false | ||||
|     t.integer  "customer_id" | ||||
|     t.integer  "customer_type" | ||||
|     t.integer  "customer_id",   :null => false | ||||
|     t.string   "customer_type", :null => false | ||||
|     t.integer  "bike_id" | ||||
|     t.integer  "amount",        :null => false | ||||
|     t.string   "item",          :null => false | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user