-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chandra
committed
Apr 12, 2012
1 parent
1de9812
commit edfed2f
Showing
46 changed files
with
1,690 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//= require active_admin/base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
}); | ||
}); | ||
*/ | ||
}) |
Oops, something went wrong.