rightnow_oms 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. data/CHANGELOG +8 -1
  2. data/README.md +10 -0
  3. data/app/assets/javascripts/rightnow_oms/app/app.js.coffee +2 -0
  4. data/app/assets/javascripts/rightnow_oms/app/controllers/cart.js.coffee +3 -3
  5. data/app/assets/javascripts/rightnow_oms/app/models/cart.js.coffee +14 -4
  6. data/app/assets/javascripts/rightnow_oms/app/models/cart_item.js.coffee +25 -15
  7. data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/show.hjs +23 -9
  8. data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/show_in_detail.hjs +45 -18
  9. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show.hjs +0 -2
  10. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_in_detail.hjs +15 -23
  11. data/app/assets/javascripts/rightnow_oms/app/views/cart_items/show.js.coffee +5 -1
  12. data/app/assets/javascripts/rightnow_oms/app/views/cart_items/show_in_detail.js.coffee +9 -6
  13. data/app/assets/javascripts/rightnow_oms/app/views/carts/show_in_detail.js.coffee +1 -0
  14. data/app/assets/javascripts/rightnow_oms/vendor/ember-data.js +640 -236
  15. data/app/assets/javascripts/rightnow_oms/vendor/ember-data.min.js +1 -1
  16. data/app/assets/javascripts/rightnow_oms/vendor/ember.js +61 -37
  17. data/app/assets/javascripts/rightnow_oms/vendor/ember.min.js +2 -2
  18. data/app/assets/stylesheets/rightnow_oms/application.css.scss +17 -0
  19. data/app/assets/stylesheets/rightnow_oms/carts.css.scss +99 -72
  20. data/app/assets/stylesheets/rightnow_oms/orders.css.scss +50 -0
  21. data/app/controllers/rightnow_oms/cart_items_controller.rb +5 -5
  22. data/app/controllers/rightnow_oms/orders_controller.rb +30 -0
  23. data/app/models/rightnow_oms/cart.rb +22 -13
  24. data/app/models/rightnow_oms/cart_item.rb +20 -2
  25. data/app/models/rightnow_oms/order.rb +43 -0
  26. data/app/models/rightnow_oms/order_item.rb +16 -0
  27. data/app/views/rightnow_oms/carts/show.html.haml +2 -0
  28. data/app/views/rightnow_oms/orders/show.html.haml +45 -0
  29. data/config/routes.rb +1 -0
  30. data/db/migrate/20120214074943_create_rightnow_oms_orders.rb +20 -0
  31. data/db/migrate/20120214081113_create_rightnow_oms_order_items.rb +15 -0
  32. data/db/migrate/20120215064659_add_user_id_to_rightnow_oms_orders.rb +7 -0
  33. data/db/migrate/20120217081138_add_base_quantity_to_rightnow_oms_cart_items.rb +6 -0
  34. data/lib/rightnow_oms/order_no_generator.rb +13 -0
  35. data/lib/rightnow_oms/version.rb +1 -1
  36. data/lib/rightnow_oms.rb +19 -5
  37. metadata +41 -20
  38. data/app/assets/stylesheets/rightnow_oms/application.css +0 -7
data/CHANGELOG CHANGED
@@ -1,4 +1,11 @@
1
- *Rightnow OMS 0.1.2 (wip)*
1
+ *Rightnow OMS 0.1.3 (Fri 20:05, Feb 17, 2012)*
2
+
3
+ * Don't count the children of cart items
4
+ * Group children of cart items
5
+ * Unmerge the same items by setting mergable to false when adding a item
6
+ * Create orders
7
+
8
+ *Rightnow OMS 0.1.2 (Wed 17:15, Feb 15, 2012)*
2
9
 
3
10
  * Clean up the cart
4
11
  * Load the cart items in cart by group
data/README.md CHANGED
@@ -13,6 +13,7 @@ Add the following gems to your Gemfile:
13
13
  gem 'ember-rails'
14
14
  gem 'acts_as_api'
15
15
  gem 'haml-rails'
16
+ gem 'confstruct'
16
17
 
17
18
  group :assets do
18
19
  gem 'uglifier'
@@ -82,6 +83,15 @@ Create a layout for your detailed cart view like:
82
83
  = yield
83
84
  ```
84
85
 
86
+ You need to configure your new order url in RightnowOms:
87
+
88
+ ```ruby
89
+ # config/initializers/rightnow_oms.rb
90
+ RightnowOms.configure do
91
+ new_order_url '/orders/new'
92
+ end
93
+ ```
94
+
85
95
  Add before filters to your controllers which need to use the cart:
86
96
 
87
97
  ```ruby
@@ -6,3 +6,5 @@ window.RightnowOms.store = DS.Store.create
6
6
  DS.MyRESTAdapter.create
7
7
  bulkCommit: false
8
8
  namespace: 'rightnow_oms'
9
+
10
+ window.RightnowOms.config = Em.Object.create()
@@ -70,15 +70,15 @@ RightnowOms.cartController = Ember.Object.create
70
70
  #
71
71
  # =>
72
72
  # [{
73
- # 'id': 1, 'cartable_id': 2, 'cartable_type': 'Product', 'name': 'product-1', 'price': 10.0, 'group': 'booking', 'parent_id': null
73
+ # 'id': 1, 'cartable_id': 2, 'cartable_type': 'Product', 'name': 'product-1', 'original_price', 10.0, 'price': 10.0, 'group': 'booking', 'parent_id': null
74
74
  # }, {
75
- # 'id': 2, 'cartable_id': 3, 'cartable_type': 'Product', 'name': 'product-2', 'price': 20.0, 'group': 'booking', 'parent_id': 2
75
+ # 'id': 2, 'cartable_id': 3, 'cartable_type': 'Product', 'name': 'product-2', 'original_price', 20.0, 'price': 20.0, 'group': 'booking', 'parent_id': 2
76
76
  # }]
77
77
  findCartItemsByGroup: (group) ->
78
78
  found = []
79
79
  cartItems = @get('content').findCartItemsByGroup(group)
80
80
 
81
81
  cartItems.forEach (item) ->
82
- found.push(item.getProperties('id', 'cartable_id', 'cartable_type', 'name', 'price', 'quantity', 'group', 'parent_id'))
82
+ found.push(item.getProperties('id', 'cartable_id', 'cartable_type', 'name', 'original_price', 'price', 'quantity', 'group', 'parent_id'))
83
83
 
84
84
  found
@@ -6,7 +6,7 @@ RightnowOms.Cart = DS.Model.extend
6
6
  cartableCount: (->
7
7
  count = 0
8
8
  @get('cartItems').forEach (item) ->
9
- count += item.get('quantity')
9
+ count += item.get('quantity') unless item.get('hasParent')
10
10
 
11
11
  count
12
12
  ).property("cartItems.@each.quantity")
@@ -14,18 +14,28 @@ RightnowOms.Cart = DS.Model.extend
14
14
  total: (->
15
15
  total = 0
16
16
  @get('cartItems').forEach (item) ->
17
- total += parseFloat(item.get('price')) * item.get('quantity')
17
+ total += item.get('price') * item.get('quantity') unless item.get('hasParent')
18
18
 
19
19
  round(total, 2)
20
- ).property("cartableCount")
20
+ ).property("cartItems.@each.quantity")
21
21
 
22
22
  addCartItem: (item) ->
23
+ return @createCartItem(item) if item.mergable == false
24
+
23
25
  cartItem = RightnowOms.CartItem.findByCartableAndParentId(item.cartable_id, item.cartable_type, item.parent_id)
24
26
 
25
27
  if cartItem?
26
28
  cartItem.increase() unless cartItem.get('parent')?
27
29
  else
28
- cartItem = RightnowOms.store.createRecord(RightnowOms.CartItem, item)
30
+ cartItem = @createCartItem(item)
31
+
32
+ cartItem
33
+
34
+ createCartItem: (item)->
35
+ cartItem = RightnowOms.store.createRecord(RightnowOms.CartItem, item)
36
+
37
+ if cartItem.get('hasParent')
38
+ cartItem.get('parent').set('children', RightnowOms.CartItem.findByParentId(cartItem.get('id')))
29
39
 
30
40
  cartItem
31
41
 
@@ -2,10 +2,13 @@ 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
+ original_price: DS.attr('string')
6
+ base_quantity: DS.attr('integer')
5
7
  price: DS.attr('money')
6
8
  quantity: DS.attr('integer')
7
9
  group: DS.attr('string')
8
10
  parent_id: DS.attr('integer')
11
+ mergable: DS.attr('boolean')
9
12
 
10
13
  priceString: (->
11
14
  round(@get('price'), 2)
@@ -20,16 +23,17 @@ RightnowOms.CartItem = DS.Model.extend
20
23
  ).property('subtotal')
21
24
 
22
25
  children: (->
23
- RightnowOms.CartItem.all().filterProperty('parent_id', @get('id'))
24
- ).property()
26
+ RightnowOms.CartItem.findByParentId(@get('id'))
27
+ ).property().cacheable()
25
28
 
26
29
  parent: (->
27
30
  if @get('parent_id')?
28
31
  RightnowOms.CartItem.all().filterProperty('id', @get('parent_id'))
29
- ).property()
32
+ ).property('parent_id')
30
33
 
31
34
  hasChildren: (->
32
- @get('children.length') > 0
35
+ @set('children', RightnowOms.CartItem.findByParentId(@get('id')))
36
+ @get('children') && @getPath('children.length') > 0
33
37
  ).property()
34
38
 
35
39
  hasParent: (->
@@ -41,23 +45,26 @@ RightnowOms.CartItem = DS.Model.extend
41
45
  ).property('quantity')
42
46
 
43
47
  increase: ->
44
- @get('children').forEach((child) ->
45
- child.increase()
46
- )
48
+ if @get('hasChildren')
49
+ @get('children').forEach((child) ->
50
+ child.increase()
51
+ )
47
52
 
48
- @set('quantity', @get('quantity') + 1)
53
+ @set('quantity', @get('quantity') + @get('base_quantity'))
49
54
 
50
55
  decrease: ->
51
- @get('children').forEach((child) ->
52
- child.decrease()
53
- )
56
+ if @get('hasChildren')
57
+ @get('children').forEach((child) ->
58
+ child.decrease()
59
+ )
54
60
 
55
- @set('quantity', @get('quantity') - 1)
61
+ @set('quantity', @get('quantity') - @get('base_quantity'))
56
62
 
57
63
  deleteRecord: ->
58
- @get('children').forEach((child) ->
59
- child.deleteRecord()
60
- )
64
+ if @get('hasChildren')
65
+ @get('children').forEach((child) ->
66
+ child.deleteRecord()
67
+ )
61
68
 
62
69
  @_super()
63
70
 
@@ -68,6 +75,9 @@ RightnowOms.CartItem.reopenClass
68
75
  findById: (id) ->
69
76
  @all().filterProperty('id', id).get('firstObject')
70
77
 
78
+ findByParentId: (parentId) ->
79
+ @all().filterProperty('parent_id', parentId)
80
+
71
81
  findByName: (name) ->
72
82
  @all().filterProperty('name', name).get('firstObject')
73
83
 
@@ -1,9 +1,23 @@
1
- {{#with cartItem }}
2
- <td class="name">{{ name }}</td>
3
- <td class="price r-money">¥{{ priceString }}x{{ quantity }}</td>
4
- <td class="delete">
5
- {{#unless hasParent }}
6
- <a href="#" {{ action "deleteRecord" }}>删除</a>
7
- {{/unless}}
8
- </td>
9
- {{/with}}
1
+ {{#unless cartItem.hasParent }}
2
+ <dt>
3
+ <ul>
4
+ <li class="name" {{ action "toggleChildren" }}>{{ cartItem.name }}</li>
5
+ <li class="price r-money">¥{{ cartItem.priceString }}x{{ cartItem.quantity }}</li>
6
+ <li class="delete">
7
+ <a href="#" {{ action "deleteRecord" }}>删除</a>
8
+ </li>
9
+ <ul>
10
+ </dt>
11
+ {{#if isChildrenHidden}}
12
+ {{#if cartItem.hasChildren}}
13
+ <dd>
14
+ {{#each cartItem.children }}
15
+ <ul class='child'>
16
+ <li class="name">{{ name }}</li>
17
+ <li class="price r-money">¥{{ priceString }}x{{ quantity }}</li>
18
+ </ul>
19
+ {{/each}}
20
+ </dd>
21
+ {{/if}}
22
+ {{/if}}
23
+ {{/unless}}
@@ -1,19 +1,46 @@
1
- {{#with cartItem}}
2
- <td class="name">{{ name }}</td>
3
- <td class="price">¥{{ priceString }}</td>
4
- <td class="quantity">
5
- {{#if hasParent }}
6
- <span class="quantity-only">{{ quantity }}</span>
7
- {{else}}
8
- <span class="decrease"><a href="#" {{ action "decrease" }}>-</a></span>
9
- <span class="quantity"> {{ quantity }} </span>
10
- <span class="increase"><a href="#" {{ action "increase" }}>+</a></span>
1
+ {{#unless cartItem.hasParent}}
2
+ <dt>
3
+ <ul>
4
+ <li class="name" {{ action "toggleChildren" }}>{{ cartItem.name }}</li>
5
+ <li class="others">
6
+ <div class='price'>¥{{ cartItem.priceString }}</div>
7
+ <div class="quantity">
8
+ {{#if hasParent }}
9
+ <span class="quantity-only">{{ cartItem.quantity }}</span>
10
+ {{else}}
11
+ <span class="decrease"><a href="#" {{ action "decrease" }}>-</a></span>
12
+ <span class="quantity"> {{ cartItem.quantity }} </span>
13
+ <span class="increase"><a href="#" {{ action "increase" }}>+</a></span>
14
+ {{/if}}
15
+ </div>
16
+ <div class="subtotal r-money">¥{{ cartItem.subtotalString }}</div>
17
+ <div class="delete">
18
+ {{#unless cartItem.hasParent }}
19
+ <a href="#" {{ action "deleteRecord" }}>删除</a>
20
+ {{/unless}}
21
+ </div>
22
+ </li>
23
+ <div class="r-clear"></div>
24
+ </ul>
25
+ </dt>
26
+ {{#if isChildrenHidden}}
27
+ {{#if cartItem.hasChildren}}
28
+ <dd>
29
+ {{#each cartItem.children}}
30
+ <ul>
31
+ <li class="name">{{ name }}</li>
32
+ <li class="others">
33
+ <div class="price">¥{{ priceString }}</div>
34
+ <div class="quantity">
35
+ <span class="quantity-only">{{ quantity }}</span>
36
+ </div>
37
+ <div class="subtotal r-money">¥{{ subtotalString }}</div>
38
+ <div class="delete"></div>
39
+ </li>
40
+ <div class="r-clear"></div>
41
+ </ul>
42
+ {{/each}}
43
+ </dd>
11
44
  {{/if}}
12
- </td>
13
- <td class="subtotal r-money">¥{{ subtotalString }}</td>
14
- <td class="delete">
15
- {{#unless hasParent }}
16
- <a href="#" {{ action "deleteRecord" }}>删除</a>
17
- {{/unless}}
18
- </td>
19
- {{/with}}
45
+ {{/if}}
46
+ {{/unless}}
@@ -2,11 +2,9 @@
2
2
  {{ view RightnowOms.ShowCartableCountView cartableCountBinding="cart.cartableCount" }}
3
3
  </div>
4
4
  <div class="r-cart-items">
5
- <table>
6
5
  {{#each cart.cartItems}}
7
6
  {{ view RightnowOms.ShowCartItemView cartItemBinding="this" }}
8
7
  {{/each}}
9
- </table>
10
8
  <div class="r-bottom-bar">
11
9
  <span>总计:<span class="r-money">¥{{ cart.total }}</span></span>
12
10
  <span><a href="/rightnow_oms/cart">查看我的购物车</a></span>
@@ -1,27 +1,19 @@
1
1
  <h2>我的购物车</h2>
2
2
  <div class="r-cart-items">
3
- <table>
4
- <thead>
5
- <tr>
6
- <th>名称</th>
7
- <th>价格</th>
8
- <th>数量</th>
9
- <th>总价</th>
10
- <th></th>
11
- </tr>
12
- </thead>
13
- <tbody>
14
- {{#each cart.cartItems}}
15
- {{ view RightnowOms.ShowCartItemInDetailView cartItemBinding="this" }}
16
- {{/each}}
17
- </tbody>
18
- <tfoot>
19
- <tr>
20
- <td colspan="4"></td>
21
- <td></td>
22
- </tr>
23
- </tfoot>
24
- </table>
3
+ <ul class='title'>
4
+ <li class="name">名称</li>
5
+ <li class="others">
6
+ <div class="price">价格</div>
7
+ <div class="quantity">数量</div>
8
+ <div class="subtotal">小计</div>
9
+ <div class="delete"></div>
10
+ </li>
11
+ </ul>
12
+ <div class='r-clear'></div>
13
+ {{#each cart.cartItems}}
14
+ {{ view RightnowOms.ShowCartItemInDetailView cartItemBinding="this" }}
15
+ {{/each}}
16
+ <div class='r-clear'></div>
25
17
  </div>
26
18
  <div class="r-bottom-bar">
27
19
  <div class="left-conner">
@@ -30,6 +22,6 @@
30
22
  <div class="right-conner">
31
23
  <span>总价:<span class="r-money">¥{{ cart.total }}</span></span>
32
24
  <span class="r-continue-to-shop"><a href="/"><< 继续购物</a></span>
33
- <span class="r-checkout"><a href="#">去结算 >></a></span>
25
+ <span class="r-checkout"><a {{ bindAttr href="newOrderUrl" }}>去结算 >></a></span>
34
26
  </div>
35
27
  </div>
@@ -1,7 +1,11 @@
1
1
  RightnowOms.ShowCartItemView = Ember.View.extend
2
- tagName: 'tr'
2
+ tagName: 'dl'
3
3
  templateName: 'rightnow_oms/app/templates/cart_items/show'
4
4
 
5
+ toggleChildren: ->
6
+ hidden = @get('isChildrenHidden')
7
+ @set('isChildrenHidden', !hidden)
8
+
5
9
  deleteRecord: ->
6
10
  item = this.get('cartItem')
7
11
  RightnowOms.cartController.removeCartItem(item.get('id'), true)
@@ -1,11 +1,6 @@
1
- RightnowOms.ShowCartItemInDetailView = Ember.View.extend
2
- tagName: 'tr'
1
+ RightnowOms.ShowCartItemInDetailView = RightnowOms.ShowCartItemView.extend
3
2
  templateName: 'rightnow_oms/app/templates/cart_items/show_in_detail'
4
3
 
5
- deleteRecord: ->
6
- item = @get('cartItem')
7
- RightnowOms.cartController.removeCartItem(item.get('id'))
8
-
9
4
  increase: ->
10
5
  item = @get('cartItem')
11
6
  RightnowOms.cartController.increaseCartItem(item.get('id'))
@@ -13,3 +8,11 @@ RightnowOms.ShowCartItemInDetailView = Ember.View.extend
13
8
  decrease: ->
14
9
  item = @get('cartItem')
15
10
  RightnowOms.cartController.decreaseCartItem(item.get('id'))
11
+
12
+ mouseEnter: (e) ->
13
+ $(e.target).parents('.r-cart-items').find('dt').css('background', 'white')
14
+ $(e.target).parents('dt').css('background','#EEE')
15
+
16
+
17
+ mouseLeave: (e) ->
18
+ $(e.target).parents('.r-cart-items').find('dt').css('background', 'white')
@@ -2,6 +2,7 @@ RightnowOms.ShowCartInDetailView = Ember.View.extend
2
2
  templateName: 'rightnow_oms/app/templates/carts/show_in_detail'
3
3
 
4
4
  cartBinding: 'RightnowOms.cartController.content'
5
+ newOrderUrlBinding: 'RightnowOms.config.newOrderUrl'
5
6
 
6
7
  cleanUp: ->
7
8
  RightnowOms.cartController.cleanUp()