Skip to content

Commit

Permalink
Before creating active admin models
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra committed Apr 12, 2012
1 parent 1de9812 commit edfed2f
Show file tree
Hide file tree
Showing 46 changed files with 1,690 additions and 300 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ group :assets do
end

gem 'jquery-rails'
gem 'activeadmin'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
43 changes: 43 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ GEM
rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activeadmin (0.4.0)
bourbon (>= 1.0.0)
devise (>= 1.1.2)
fastercsv
formtastic (>= 2.0.0)
inherited_resources (< 1.3.0)
jquery-rails (>= 1.0.0)
kaminari (>= 0.13.0)
meta_search (>= 0.9.2)
rails (>= 3.0.0)
sass (>= 3.1.0)
activemodel (3.2.1)
activesupport (= 3.2.1)
builder (~> 3.0.0)
Expand All @@ -29,6 +40,9 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bourbon (1.3.6)
sass (>= 3.1)
builder (3.0.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
Expand All @@ -37,22 +51,47 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
devise (2.0.0)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
railties (~> 3.1)
warden (~> 1.1)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
fastercsv (1.5.4)
formtastic (2.0.2)
rails (~> 3.0)
has_scope (0.5.1)
hike (1.2.1)
i18n (0.6.0)
inherited_resources (1.2.2)
has_scope (~> 0.5.0)
responders (~> 0.6.0)
journey (1.0.3)
jquery-rails (2.0.1)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
mail (2.4.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
meta_search (1.1.2)
actionpack (~> 3.1)
activerecord (~> 3.1)
activesupport (~> 3.1)
meta_search
polyamorous (~> 0.5.0)
mime-types (1.17.2)
multi_json (1.1.0)
orm_adapter (0.0.6)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand All @@ -79,6 +118,7 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
responders (0.6.5)
sass (3.1.15)
sass-rails (3.2.4)
railties (~> 3.2.0)
Expand All @@ -98,11 +138,14 @@ GEM
uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
warden (1.1.0)
rack (>= 1.0)

PLATFORMS
ruby

DEPENDENCIES
activeadmin
coffee-rails (~> 3.2.1)
jquery-rails
rails (= 3.2.1)
Expand Down
44 changes: 44 additions & 0 deletions app/admin/dashboards.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ActiveAdmin::Dashboards.build do

# Define your dashboard sections here. Each block will be
# rendered on the dashboard in the context of the view. So just
# return the content which you would like to display.

# == Simple Dashboard Section
# Here is an example of a simple dashboard section
#
# section "Recent Posts" do
# ul do
# Post.recent(5).collect do |post|
# li link_to(post.title, admin_post_path(post))
# end
# end
# end

# == Render Partial Section
# The block is rendered within the context of the view, so you can
# easily render a partial rather than build content in ruby.
#
# section "Recent Posts" do
# div do
# render 'recent_posts' # => this will render /app/views/admin/dashboard/_recent_posts.html.erb
# end
# end

# == Section Ordering
# The dashboard sections are ordered by a given priority from top left to
# bottom right. The default priority is 10. By giving a section numerically lower
# priority it will be sorted higher. For example:
#
# section "Recent Posts", :priority => 10
# section "Recent User", :priority => 1
#
# Will render the "Recent Users" then the "Recent Posts" sections on the dashboard.

# == Conditionally Display
# Provide a method name or Proc object to conditionally render a section at run time.
#
# section "Membership Summary", :if => :memberships_enabled?
# section "Membership Summary", :if => Proc.new { current_admin_user.account.memberships.any? }

end
Binary file added app/assets/javascripts/.bills.js.swp
Binary file not shown.
Binary file added app/assets/javascripts/.products.js.swp
Binary file not shown.
1 change: 1 addition & 0 deletions app/assets/javascripts/active_admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require active_admin/base
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require underscore-min
//= require_tree .
169 changes: 169 additions & 0 deletions app/assets/javascripts/bills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
$(document).ready( function(){

billitems_list = [];

// Autocomplete
$('.code_autocomplete').on('focus', function(){
$(this).autocomplete(
{
minLength:1,
source:'/products/code_autocomplete',
focus: function(event, ui){
$('#code').val(ui.item.code);
$('#name').val(ui.item.name);
},
change:function(event, ui){
console.log(ui);
if(ui.item){
$('#item_id').val(ui.item.id);
$('#code').val(ui.item.code);
$('#name').val(ui.item.name);
if ($('#price').val()== ""){
$('#price').val(ui.item.price);
}
if ($('#quant').val()== ""){
$('#quant').val(1);
}
}
}
}
);
}
);
//billitem template
var billitem_tmpl = _.template("<span class='billitem' data-guid=<%= _guid %>><span class='span1'><%= code %></span><span class='span2'><%= name %></span><span class='span1'><%= price %></span><span class='span1'><%= quantity %></span><a class='btn btn-danger del_item' href='#'><i class='icon-remove-sign'></i>Remove</a><br/></span>");

// render bill items_list
function render_bill_items_list(){
if (billitems_list.length){
_.each(billitems_list, function(bi){
$('#bill_area').append(billitem_tmpl(bi));
});}
}
// Add to bill
function add_to_bill(){
var billitem = {
_guid:Math.guid(),
id:$('#item_id').val(),
code:$('#code').val(),
name:$('#name').val(),
price:$('#price').val(),
quantity:$('#quant').val()
};
$('#reset_billitem').trigger('click');
billitems_list.push(billitem);
$('#bill_area').append(billitem_tmpl(billitem));
}

function calculate_total(){
var total = _.reduce(billitems_list, function(tot, bi){ return tot+parseInt(bi.price)*parseInt(bi.quantity); }, 0);
$('#total strong').text(total);
}

$('#add_item_2_bill').live('click', function(){
if(parseInt($('#item_id').val())){
add_to_bill();
calculate_total();
}else{
alert('This product does not exist in the product database, please create it first.')
}
});

$('#reset_billitem').live('click', function(){
_.each($('#bill_item_form .item'), function(it){
$(it).val('');
});
});

$('#add_bill').live('click', function(evt){
evt.preventDefault();
if(billitems_list.length){
$.ajax({
url:"/bills",
data:{billitems:billitems_list},
dataType:'json',
type:'POST',
success:function(data, textStatus, jqXHR){
console.log(data);
if(data.success){
$('#reset_bill').trigger('click');
$('#reset_billitem').trigger('click');
}
}
});
}else{
alert('No items were found in the bill please add some items.');
}
});

// deleting items from the bill
$('.del_item').live('click',function(evt){
evt.preventDefault();
var ref = $($(this)[0]);
ref = ref.parent('.billitem').filter(':first');
var guid = ref.attr("data-guid");
ref.remove();
billitems_list = _.reject(billitems_list, function(bi){return bi._guid == guid;});
calculate_total();
});

// Reset bill
$('#reset_bill').live('click', function(){
$('.del_item').trigger('click');
});

// external code
Math.guid = function(){
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
}).toUpperCase();
};


/*
// Updating subtotal on field change
function show_subtotal(){
var price = parseInt($('#billitem_price').val());
var numbers = parseInt($('#billitem_numbers').val());
if (price && numbers){
$('#subtotal').text("Subtotal : " + price*numbers)
}
}
$('#bill_input_form #billitem_price').on('change', show_subtotal);
$('#bill_input_form #billitem_numbers').on('change', show_subtotal);
// Respond on successful write to billitem & bill
$(function(){
$('#bill_input_form')
.bind('ajax:success', function(e, data, status, xhr){
if(data.success){
$('#bill_table').append(bill_record(data));
}
return false
})
.bind('ajax:error', function(e, xhr, status, error){
console.log("error json: "+ xhr.respomseText);
})
})
// debug
$('input[name="commit"]').on('click', function(){console.log('Triggered submit');});
// Delete a bill item from the bill
$('.delete_bill_item').on('click', function(){
id = $(this).parent('tr').attr('id');
this_record = $(this);
$.ajax({
url:"/bills/"+id+"/destroy_item.json",
succeess:function(data){
if(data.success){
this_record.remove();
}
}
});
});
*/
})
Loading

0 comments on commit edfed2f

Please sign in to comment.