rightnow_oms 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.md +10 -4
- data/app/assets/javascripts/rightnow_oms/app/controllers/cart.js.coffee +49 -2
- data/app/assets/javascripts/rightnow_oms/app/models/cart.js.coffee +18 -0
- data/app/assets/javascripts/rightnow_oms/app/models/cart_item.js.coffee +10 -2
- data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/show.hjs +1 -1
- data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/show_in_detail.hjs +2 -2
- data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_in_detail.hjs +8 -3
- data/app/assets/javascripts/rightnow_oms/app/views/carts/show_in_detail.js.coffee +3 -0
- data/app/assets/javascripts/rightnow_oms/lib/ember/data/{adapters/my_rest_adapter.js.coffee → my_rest_adapter.js.coffee} +0 -0
- data/app/assets/javascripts/rightnow_oms/lib/ember/data/types.js.coffee +7 -0
- data/app/assets/stylesheets/rightnow_oms/carts.css.scss +6 -6
- data/app/models/rightnow_oms/cart.rb +5 -9
- data/lib/rightnow_oms/version.rb +1 -1
- metadata +20 -19
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
*Rightnow OMS 0.1.2 (wip)*
|
2
|
+
|
3
|
+
* Clean up the cart
|
4
|
+
* Load the cart items in cart by group
|
5
|
+
* Update cart items
|
6
|
+
* Define a float type for Ember.JS
|
7
|
+
* Call a callback when a cart item is added successfully
|
8
|
+
|
1
9
|
*Rightnow OMS 0.1.1 (Mon 18:35, Feb 13, 2012)*
|
2
10
|
|
3
11
|
* Validate that cart items are cartable
|
data/README.md
CHANGED
@@ -126,11 +126,17 @@ You can add cartables to the cart by:
|
|
126
126
|
|
127
127
|
```javascript
|
128
128
|
RightnowOms.cartController.addCartItem({
|
129
|
-
cartable_id: 1,
|
130
|
-
cartable_type: 'Product'
|
129
|
+
cartable_id: 1, // required
|
130
|
+
cartable_type: 'Product', // required
|
131
|
+
price: '10.00', // required
|
131
132
|
|
132
|
-
//
|
133
|
-
|
133
|
+
// optional, indicating this is a child node of another one
|
134
|
+
parent_id: 2,
|
135
|
+
|
136
|
+
// optional, grouping cart items
|
137
|
+
group: 'booking'
|
138
|
+
}, function(cartItem) {
|
139
|
+
// Do something after the cart item is created
|
134
140
|
})
|
135
141
|
```
|
136
142
|
|
@@ -9,11 +9,32 @@ RightnowOms.cartController = Ember.Object.create
|
|
9
9
|
@set('content', RightnowOms.store.find(RightnowOms.Cart, @get('content').get('id')))
|
10
10
|
|
11
11
|
# item: a hash
|
12
|
-
addCartItem: (item) ->
|
12
|
+
addCartItem: (item, callback) ->
|
13
13
|
cartItem = @get('content').addCartItem(item)
|
14
14
|
@store.commit()
|
15
15
|
|
16
|
-
|
16
|
+
return unless callback
|
17
|
+
|
18
|
+
return callback.call(@, cartItem) if cartItem.get('id')
|
19
|
+
|
20
|
+
self = @
|
21
|
+
cartItem.addObserver('isDirty', ->
|
22
|
+
if (!cartItem.get('isDirty')) && (!cartItem.get('isDeleted'))
|
23
|
+
callback.call(self, cartItem)
|
24
|
+
)
|
25
|
+
|
26
|
+
# @id: id of the cart item to be updated
|
27
|
+
# @properties: a hash which is the new properties of the cart item.
|
28
|
+
#
|
29
|
+
# For example:
|
30
|
+
#
|
31
|
+
# RightnowOms.cartController.updateCartItem(1, {
|
32
|
+
# 'price': 10.00,
|
33
|
+
# 'quantity': 2
|
34
|
+
# })
|
35
|
+
updateCartItem: (id, properties) ->
|
36
|
+
@get('content').updateCartItem(id, properties)
|
37
|
+
@store.commit()
|
17
38
|
|
18
39
|
increaseCartItem: (id) ->
|
19
40
|
@get('content').increaseCartItem(id)
|
@@ -35,3 +56,29 @@ RightnowOms.cartController = Ember.Object.create
|
|
35
56
|
if remove
|
36
57
|
@get('content').removeCartItem(id)
|
37
58
|
@store.commit()
|
59
|
+
|
60
|
+
cleanUp: ->
|
61
|
+
if confirm('您确定要清空您的购物车吗?')
|
62
|
+
@get('content').cleanUp()
|
63
|
+
@store.commit()
|
64
|
+
|
65
|
+
# return: an array of cart items.
|
66
|
+
#
|
67
|
+
# For example:
|
68
|
+
#
|
69
|
+
# RightnowOms.cartController.findCartItemsByGroup('booking');
|
70
|
+
#
|
71
|
+
# =>
|
72
|
+
# [{
|
73
|
+
# 'id': 1, 'cartable_id': 2, 'cartable_type': 'Product', 'name': 'product-1', 'price': 10.0, 'group': 'booking', 'parent_id': null
|
74
|
+
# }, {
|
75
|
+
# 'id': 2, 'cartable_id': 3, 'cartable_type': 'Product', 'name': 'product-2', 'price': 20.0, 'group': 'booking', 'parent_id': 2
|
76
|
+
# }]
|
77
|
+
findCartItemsByGroup: (group) ->
|
78
|
+
found = []
|
79
|
+
cartItems = @get('content').findCartItemsByGroup(group)
|
80
|
+
|
81
|
+
cartItems.forEach (item) ->
|
82
|
+
found.push(item.getProperties('id', 'cartable_id', 'cartable_type', 'name', 'price', 'quantity', 'group', 'parent_id'))
|
83
|
+
|
84
|
+
found
|
@@ -29,6 +29,20 @@ RightnowOms.Cart = DS.Model.extend
|
|
29
29
|
|
30
30
|
cartItem
|
31
31
|
|
32
|
+
updateCartItem: (id, properties) ->
|
33
|
+
cartItem = RightnowOms.CartItem.findById(id)
|
34
|
+
cartItem.setProperties(properties) if cartItem?
|
35
|
+
|
36
|
+
cleanUp: ->
|
37
|
+
cartItemIds = @get('cartItems').map (item) ->
|
38
|
+
return item.get('id')
|
39
|
+
|
40
|
+
cartItemIds.forEach (id) ->
|
41
|
+
item = RightnowOms.CartItem.findById(id)
|
42
|
+
|
43
|
+
# INFO Children will be deleted when the parent is deleted
|
44
|
+
item.deleteRecord() if item && !item.get('hasParent')
|
45
|
+
|
32
46
|
removeCartItem: (id) ->
|
33
47
|
cartItem = RightnowOms.CartItem.findById(id)
|
34
48
|
|
@@ -48,5 +62,9 @@ RightnowOms.Cart = DS.Model.extend
|
|
48
62
|
cartItem.decrease()
|
49
63
|
cartItem
|
50
64
|
|
65
|
+
findCartItemsByGroup: (group) ->
|
66
|
+
@get('cartItems').filter (item) ->
|
67
|
+
return true if item.get('group') == group
|
68
|
+
|
51
69
|
RightnowOms.Cart.reopenClass
|
52
70
|
isSingleton: true
|
@@ -2,15 +2,23 @@ RightnowOms.CartItem = DS.Model.extend
|
|
2
2
|
cartable_id: DS.attr('integer')
|
3
3
|
cartable_type: DS.attr('string')
|
4
4
|
name: DS.attr('string')
|
5
|
-
price: DS.attr('
|
5
|
+
price: DS.attr('money')
|
6
6
|
quantity: DS.attr('integer')
|
7
7
|
group: DS.attr('string')
|
8
8
|
parent_id: DS.attr('integer')
|
9
9
|
|
10
|
+
priceString: (->
|
11
|
+
round(@get('price'), 2)
|
12
|
+
).property('price')
|
13
|
+
|
10
14
|
subtotal: (->
|
11
|
-
|
15
|
+
@get('price') * @get('quantity')
|
12
16
|
).property('price', 'quantity')
|
13
17
|
|
18
|
+
subtotalString: (->
|
19
|
+
round(@get('subtotal'), 2)
|
20
|
+
).property('subtotal')
|
21
|
+
|
14
22
|
children: (->
|
15
23
|
RightnowOms.CartItem.all().filterProperty('parent_id', @get('id'))
|
16
24
|
).property()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
{{#with cartItem }}
|
2
2
|
<td class="name">{{ name }}</td>
|
3
|
-
<td class="price r-money">¥{{
|
3
|
+
<td class="price r-money">¥{{ priceString }}x{{ quantity }}</td>
|
4
4
|
<td class="delete">
|
5
5
|
{{#unless hasParent }}
|
6
6
|
<a href="#" {{ action "deleteRecord" }}>删除</a>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
{{#with cartItem}}
|
2
2
|
<td class="name">{{ name }}</td>
|
3
|
-
<td class="price">¥{{
|
3
|
+
<td class="price">¥{{ priceString }}</td>
|
4
4
|
<td class="quantity">
|
5
5
|
{{#if hasParent }}
|
6
6
|
<span class="quantity-only">{{ quantity }}</span>
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<span class="increase"><a href="#" {{ action "increase" }}>+</a></span>
|
11
11
|
{{/if}}
|
12
12
|
</td>
|
13
|
-
<td class="subtotal r-money">¥{{
|
13
|
+
<td class="subtotal r-money">¥{{ subtotalString }}</td>
|
14
14
|
<td class="delete">
|
15
15
|
{{#unless hasParent }}
|
16
16
|
<a href="#" {{ action "deleteRecord" }}>删除</a>
|
@@ -24,7 +24,12 @@
|
|
24
24
|
</table>
|
25
25
|
</div>
|
26
26
|
<div class="r-bottom-bar">
|
27
|
-
<
|
28
|
-
|
29
|
-
|
27
|
+
<div class="left-conner">
|
28
|
+
<span class="r-cleanup-cart"><a href="#" {{ action cleanUp }}>清空购物车</a></span>
|
29
|
+
</div>
|
30
|
+
<div class="right-conner">
|
31
|
+
<span>总价:<span class="r-money">¥{{ cart.total }}</span></span>
|
32
|
+
<span class="r-continue-to-shop"><a href="/"><< 继续购物</a></span>
|
33
|
+
<span class="r-checkout"><a href="#">去结算 >></a></span>
|
34
|
+
</div>
|
30
35
|
</div>
|
File without changes
|
@@ -35,11 +35,11 @@
|
|
35
35
|
display: none;
|
36
36
|
table {
|
37
37
|
td {
|
38
|
-
padding: 5px;
|
38
|
+
padding: 5px 8px;
|
39
39
|
text-align: right;
|
40
40
|
}
|
41
41
|
td.name {
|
42
|
-
width:
|
42
|
+
width: 150px;
|
43
43
|
text-align: left;
|
44
44
|
overflow: hidden;
|
45
45
|
}
|
@@ -134,11 +134,11 @@
|
|
134
134
|
}
|
135
135
|
.r-bottom-bar {
|
136
136
|
position: relative;
|
137
|
-
|
137
|
+
width: 100%;
|
138
138
|
font-size: 20px;
|
139
139
|
line-height: 36px;
|
140
|
-
span {
|
141
|
-
|
142
|
-
}
|
140
|
+
span { padding: 8px; }
|
141
|
+
.left-conner { float: left; }
|
142
|
+
.right-conner { float: right; }
|
143
143
|
}
|
144
144
|
}
|
@@ -19,24 +19,20 @@ module RightnowOms
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def add_item(cartable, opts = { quantity: 1 })
|
22
|
-
quantity = opts[:quantity]
|
23
|
-
group = opts[:group]
|
24
|
-
parent_id = opts[:parent_id]
|
25
|
-
|
26
22
|
cart_item = cart_items.find_by_cartable(cartable)
|
27
23
|
|
28
24
|
if cart_item
|
29
25
|
cart_item.update_attributes(
|
30
|
-
quantity: cart_item.quantity + quantity.to_i
|
26
|
+
quantity: cart_item.quantity + opts[:quantity].to_i,
|
31
27
|
)
|
32
28
|
else
|
33
29
|
cart_item = cart_items.create(
|
34
30
|
cartable: cartable,
|
35
31
|
name: cartable.cartable_name,
|
36
|
-
price: cartable.cartable_price,
|
37
|
-
quantity: quantity,
|
38
|
-
group: group,
|
39
|
-
parent_id: parent_id
|
32
|
+
price: opts[:price] || cartable.cartable_price,
|
33
|
+
quantity: opts[:quantity],
|
34
|
+
group: opts[:group],
|
35
|
+
parent_id: opts[:parent_id]
|
40
36
|
)
|
41
37
|
end
|
42
38
|
|
data/lib/rightnow_oms/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rightnow_oms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &8877280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *8877280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jquery-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &8904080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *8904080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: coffee-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &8902620 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *8902620
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sass-rails
|
49
|
-
requirement: &
|
49
|
+
requirement: &8901160 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *8901160
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: acts_as_api
|
60
|
-
requirement: &
|
60
|
+
requirement: &8898360 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *8898360
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ember-rails
|
71
|
-
requirement: &
|
71
|
+
requirement: &8897240 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *8897240
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: haml-rails
|
82
|
-
requirement: &
|
82
|
+
requirement: &8911980 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *8911980
|
91
91
|
description: A common mountable engine can be used to manage the orders.
|
92
92
|
email:
|
93
93
|
- towerhe@gmail.com
|
@@ -109,8 +109,9 @@ files:
|
|
109
109
|
- app/assets/javascripts/rightnow_oms/vendor/ember.js
|
110
110
|
- app/assets/javascripts/rightnow_oms/vendor/ember.min.js
|
111
111
|
- app/assets/javascripts/rightnow_oms/lib/utils.js.coffee
|
112
|
-
- app/assets/javascripts/rightnow_oms/lib/ember/data/
|
112
|
+
- app/assets/javascripts/rightnow_oms/lib/ember/data/types.js.coffee
|
113
113
|
- app/assets/javascripts/rightnow_oms/lib/ember/data/extensions.js
|
114
|
+
- app/assets/javascripts/rightnow_oms/lib/ember/data/my_rest_adapter.js.coffee
|
114
115
|
- app/assets/javascripts/rightnow_oms/app/templates/cart_items/show.hjs
|
115
116
|
- app/assets/javascripts/rightnow_oms/app/templates/cart_items/show_in_detail.hjs
|
116
117
|
- app/assets/javascripts/rightnow_oms/app/templates/carts/show.hjs
|
@@ -155,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
156
|
version: '0'
|
156
157
|
segments:
|
157
158
|
- 0
|
158
|
-
hash:
|
159
|
+
hash: 4137530938571715017
|
159
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
161
|
none: false
|
161
162
|
requirements:
|
@@ -164,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
165
|
version: '0'
|
165
166
|
segments:
|
166
167
|
- 0
|
167
|
-
hash:
|
168
|
+
hash: 4137530938571715017
|
168
169
|
requirements: []
|
169
170
|
rubyforge_project:
|
170
171
|
rubygems_version: 1.8.10
|