progress and end of day commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
root = exports ? this
|
||||||
|
root.Qrammer =
|
||||||
|
alert: (msg) ->
|
||||||
|
alert(msg)
|
||||||
|
confirm: (callback, content) ->
|
||||||
|
content ||= 'Are you sure?'
|
||||||
|
wrapper = $('<div class="modal"></div>')
|
||||||
|
callback_wrapper = ->
|
||||||
|
wrapper.modal('hide')
|
||||||
|
callback()
|
||||||
|
header = $('<div class="modal-header"></div>')
|
||||||
|
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>')
|
||||||
|
.append('<h3>Confirm</h3>').appendTo(wrapper)
|
||||||
|
body = $('<div class="modal-body"></div>').append('<p>'+content+'</p>').appendTo(wrapper)
|
||||||
|
footer = $('<div class="modal-footer"></div>')
|
||||||
|
.append($('<a href="#" class="btn">Close</a>').click(-> wrapper.modal('hide')))
|
||||||
|
.append($('<a href="#" class="btn btn-primary">Yes</a>').click(callback_wrapper))
|
||||||
|
.appendTo(wrapper)
|
||||||
|
wrapper.modal()
|
||||||
|
currency: (num) ->
|
||||||
|
num = 0.0 if isNaN(num) || num == '' || num == null
|
||||||
|
'€ ' + parseFloat(num).toFixed(2)
|
||||||
|
add_product: (product) ->
|
||||||
|
window.active_list = {} unless window.active_list
|
||||||
|
window.active_list[product._id] = {product: product, number: 0} unless window.active_list[product._id]
|
||||||
|
window.active_list[product._id].number += 1
|
||||||
|
Qrammer.build_product_list()
|
||||||
|
build_product_list: ->
|
||||||
|
wrapper = $('<div class="modal"></div>')
|
||||||
|
callback_wrapper = ->
|
||||||
|
wrapper.modal('hide')
|
||||||
|
callback()
|
||||||
|
header = $('<div class="modal-header"></div>')
|
||||||
|
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>')
|
||||||
|
.append('<h3>Product list</h3>').appendTo(wrapper)
|
||||||
|
|
||||||
|
body = $('<div class="modal-body"></div>')
|
||||||
|
table = $('<table class="table"></table>').appendTo(body)
|
||||||
|
tbody = $('<tbody></tbody>').appendTo(table)
|
||||||
|
for product_id, info of window.active_list
|
||||||
|
row = $('<tr></tr>').appendTo(tbody)
|
||||||
|
row.append('<td>'+info.product.name+'</td>')
|
||||||
|
row.append('<td>'+info.number+'</td>')
|
||||||
|
row.append('<td>'+Qrammer.currency(info.product.price * info.number)+'</td>')
|
||||||
|
|
||||||
|
body.appendTo(wrapper)
|
||||||
|
|
||||||
|
footer = $('<div class="modal-footer"></div>')
|
||||||
|
.append($('<a href="#" class="btn">Close</a>').click(-> wrapper.modal('hide')))
|
||||||
|
.append($('<a href="#" class="btn btn-primary">Yes</a>').click(callback_wrapper))
|
||||||
|
.appendTo(wrapper)
|
||||||
|
wrapper.modal()
|
||||||
|
|
||||||
@@ -92,6 +92,7 @@ class SuppliersController < ApplicationController
|
|||||||
format.json do
|
format.json do
|
||||||
products = @supplier.products
|
products = @supplier.products
|
||||||
products.include_relation(:product_categories)
|
products.include_relation(:product_categories)
|
||||||
|
products.sort_by!{|p| p.product_category.try(:position) || 90000}
|
||||||
h = products.inject({}){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
|
h = products.inject({}){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
|
||||||
render json: h
|
render json: h
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Product
|
|||||||
|
|
||||||
property :name
|
property :name
|
||||||
property :code
|
property :code
|
||||||
property :price
|
property :price, type: Float
|
||||||
|
|
||||||
belongs_to :product_category
|
belongs_to :product_category
|
||||||
belongs_to :supplier # direct! category is an aid
|
belongs_to :supplier # direct! category is an aid
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ class ProductCategory
|
|||||||
include SimplyStored::Couch
|
include SimplyStored::Couch
|
||||||
|
|
||||||
property :name
|
property :name
|
||||||
|
property :position, type: Fixnum, default: 0
|
||||||
|
|
||||||
belongs_to :supplier
|
belongs_to :supplier
|
||||||
has_many :products
|
has_many :products
|
||||||
|
|
||||||
|
validates :position, numericality: true
|
||||||
|
validates :supplier_id, presence: true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
button onClick='Qrammer.build_product_list()' class='btn btn-inverse'Lijst
|
||||||
table#products-table.table.table-striped.table-hover
|
table#products-table.table.table-striped.table-hover
|
||||||
tbody
|
tbody
|
||||||
- content_for :footer do
|
- content_for :footer do
|
||||||
@@ -6,10 +7,21 @@ table#products-table.table.table-striped.table-hover
|
|||||||
$.get('#{product_list_supplier_path(@supplier, format: :json).html_safe}', function(res){
|
$.get('#{product_list_supplier_path(@supplier, format: :json).html_safe}', function(res){
|
||||||
window.products = res
|
window.products = res
|
||||||
body = $('#products-table tbody')
|
body = $('#products-table tbody')
|
||||||
for(category in window.products){
|
for(var category in window.products){
|
||||||
body.append('<tr><td><h3>'+category+'<h3></td></tr>')
|
body.append('<tr><td colspan="3"><h3>'+category+'<h3></td></tr>');
|
||||||
for(iproduct in window.products[category]){
|
var category_ref = window.products[category];
|
||||||
body.append('<tr><td>'+window.products[category][iproduct].name+'</td></tr>')
|
for(var iproduct = 0; iproduct < window.products[category].length; iproduct++){
|
||||||
|
var product_index = iproduct;
|
||||||
|
row = $('<tr></tr>');
|
||||||
|
button = $('<button class="btn btn-primary">Add</button>');
|
||||||
|
var callback = (function(ref){
|
||||||
|
return function(){ Qrammer.add_product(ref[product_index]) }
|
||||||
|
})(category_ref)
|
||||||
|
button.click(callback);
|
||||||
|
row.append('<td>'+window.products[category][iproduct].name+'</td>');
|
||||||
|
row.append('<td>'+Qrammer.currency(window.products[category][iproduct].price)+'</td>');
|
||||||
|
row.append($('<td></td>').append(button));
|
||||||
|
body.append(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -51,12 +51,11 @@ html lang="en"
|
|||||||
= yield
|
= yield
|
||||||
.span3
|
.span3
|
||||||
.well.sidebar-nav
|
.well.sidebar-nav
|
||||||
h3 Sidebar
|
h3 Qrammer
|
||||||
ul.nav.nav-list
|
ul.nav.nav-list
|
||||||
li.nav-header Sidebar
|
li.nav-header Links
|
||||||
li= link_to "Link 1", "/path1"
|
li= link_to "Home", root_path
|
||||||
li= link_to "Link 2", "/path2"
|
li= link_to "Companytools", 'http://www.companytools.nl/'
|
||||||
li= link_to "Link 3", "/path3"
|
|
||||||
|
|
||||||
footer
|
footer
|
||||||
p © Companytools 2012
|
p © Companytools 2012
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
= f.label :name, class: 'control-label'
|
= f.label :name, class: 'control-label'
|
||||||
.controls
|
.controls
|
||||||
= f.text_field :name, class: 'text_field'
|
= f.text_field :name, class: 'text_field'
|
||||||
|
.control-group class=(@product_category.errors[:position].any? ? 'error' : nil)
|
||||||
|
= f.label :position, class: 'control-label'
|
||||||
|
.controls
|
||||||
|
= f.text_field :position, class: 'text_field'
|
||||||
.control-group class=(@product_category.errors[:supplier_id].any? ? 'error' : nil)
|
.control-group class=(@product_category.errors[:supplier_id].any? ? 'error' : nil)
|
||||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||||
.controls
|
.controls
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ div.page-header= title :index, model_class
|
|||||||
thead
|
thead
|
||||||
tr
|
tr
|
||||||
th= model_class.human_attribute_name(:name)
|
th= model_class.human_attribute_name(:name)
|
||||||
|
th= model_class.human_attribute_name(:position)
|
||||||
th= Supplier.model_name.human
|
th= Supplier.model_name.human
|
||||||
th= model_class.human_attribute_name(:created_at)
|
th= model_class.human_attribute_name(:created_at)
|
||||||
th=t 'helpers.actions'
|
th=t 'helpers.actions'
|
||||||
@@ -12,7 +13,8 @@ div.page-header= title :index, model_class
|
|||||||
- @product_categories.each do |product_category|
|
- @product_categories.each do |product_category|
|
||||||
tr
|
tr
|
||||||
td= link_to product_category.name, product_category
|
td= link_to product_category.name, product_category
|
||||||
td= link_to product_category.supplier.name, product_category.supplier
|
td= product_category.position
|
||||||
|
td= link_to_if product_category.supplier.present?, product_category.supplier.try(:name), product_category.supplier
|
||||||
td=l product_category.created_at, format: :short
|
td=l product_category.created_at, format: :short
|
||||||
td
|
td
|
||||||
= link_to t('helpers.links.edit'), [:edit, product_category], class: 'btn btn-mini'
|
= link_to t('helpers.links.edit'), [:edit, product_category], class: 'btn btn-mini'
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
dl.dl-horizontal.show-list
|
dl.dl-horizontal.show-list
|
||||||
dt= model_class.human_attribute_name(:name)
|
dt= model_class.human_attribute_name(:name)
|
||||||
dd= @product_category.name
|
dd= @product_category.name
|
||||||
|
dt= model_class.human_attribute_name(:position)
|
||||||
|
dd= @product_category.position
|
||||||
|
- if @product_category.supplier.present?
|
||||||
dt= Supplier.model_name.human
|
dt= Supplier.model_name.human
|
||||||
dd= link_to @product_category.supplier.name, @product_category.supplier
|
dd= link_to @product_category.supplier.name, @product_category.supplier
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ div.page-header= title :index, model_class
|
|||||||
td= link_to product.name, product
|
td= link_to product.name, product
|
||||||
td= product.code
|
td= product.code
|
||||||
td= product.price
|
td= product.price
|
||||||
td= link_to product.product_category.name, product.product_category
|
td= link_to_if product.product_category.present?, product.product_category.try(:name), product.product_category
|
||||||
td= link_to product.supplier.name, product.supplier
|
td= link_to_if product.supplier.present?, product.supplier.try(:name), product.supplier
|
||||||
td=l product.created_at, format: :short
|
td=l product.created_at, format: :short
|
||||||
td
|
td
|
||||||
= link_to t('helpers.links.edit'), [:edit, product], class: 'btn btn-mini'
|
= link_to t('helpers.links.edit'), [:edit, product], class: 'btn btn-mini'
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ div.page-header= title :index, model_class
|
|||||||
td= <%= resource_name %>.<%= column.name %>
|
td= <%= resource_name %>.<%= column.name %>
|
||||||
<%- end end -%>
|
<%- end end -%>
|
||||||
<%- belongs_to_associations.each do |association| -%>
|
<%- belongs_to_associations.each do |association| -%>
|
||||||
td= link_to <%= resource_name %>.<%= association.name %>.<%= association.name_property %>, <%= resource_name %>.<%= association.name %>
|
td= link_to_if <%= resource_name %>.<%= association.name %>.present?, <%= resource_name %>.<%= association.name %>.try(:<%= association.name_property %>), <%= resource_name %>.<%= association.name %>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
td=l <%= resource_name %>.created_at, format: :short
|
td=l <%= resource_name %>.created_at, format: :short
|
||||||
td
|
td
|
||||||
|
|||||||
Reference in New Issue
Block a user