rightnow_oms 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG +12 -0
  2. data/README.md +145 -66
  3. data/app/assets/javascripts/rightnow_oms/app/app.js.coffee +12 -4
  4. data/app/assets/javascripts/rightnow_oms/app/controllers/cart.js.coffee +17 -32
  5. data/app/assets/javascripts/rightnow_oms/app/models/cart.js.coffee +50 -28
  6. data/app/assets/javascripts/rightnow_oms/app/models/cart_item.js.coffee +28 -49
  7. data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/show.handlebars +30 -0
  8. data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/{show_in_detail.hjs → show_in_detail.handlebars} +3 -3
  9. data/app/assets/javascripts/rightnow_oms/app/templates/carts/{show.hjs → show.handlebars} +4 -3
  10. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_cartable_count.handlebars +2 -0
  11. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_in_detail.handlebars +30 -0
  12. data/app/assets/javascripts/rightnow_oms/app/views/cart_items/show_in_detail.js.coffee +4 -1
  13. data/app/assets/javascripts/rightnow_oms/application.js.coffee +10 -0
  14. data/app/assets/javascripts/rightnow_oms/cart_items.js +10 -0
  15. data/app/assets/javascripts/rightnow_oms/config/app.js.coffee +5 -0
  16. data/app/assets/javascripts/rightnow_oms/config/locales/en.js.coffee +24 -0
  17. data/app/assets/javascripts/rightnow_oms/config/locales/zh_CN.js.coffee +24 -0
  18. data/app/assets/javascripts/rightnow_oms/lib/ember/data/my_rest_adapter.js.coffee +2 -167
  19. data/app/assets/javascripts/rightnow_oms/vendor/cldr.js +240 -0
  20. data/app/assets/javascripts/rightnow_oms/vendor/ember-data.js +1530 -587
  21. data/app/assets/javascripts/rightnow_oms/vendor/ember-data.min.js +1 -1
  22. data/app/assets/javascripts/rightnow_oms/vendor/ember-i18n.js +123 -0
  23. data/app/assets/javascripts/rightnow_oms/vendor/{ember-0.9.5.js → ember.js} +1584 -928
  24. data/app/assets/javascripts/rightnow_oms/vendor/ember.min.js +5 -5
  25. data/app/assets/stylesheets/rightnow_oms/carts.css.scss +93 -85
  26. data/app/controllers/rightnow_oms/cart_items_controller.rb +2 -2
  27. data/app/controllers/rightnow_oms/orders_controller.rb +27 -5
  28. data/app/models/rightnow_oms/cart.rb +1 -0
  29. data/app/models/rightnow_oms/cart_item.rb +1 -0
  30. data/app/models/rightnow_oms/order.rb +26 -2
  31. data/app/views/rightnow_oms/cart_items/_list.html.haml +24 -0
  32. data/app/views/rightnow_oms/orders/show.html.haml +2 -0
  33. data/config/initializers/rightnow_oms.rb +4 -0
  34. data/config/initializers/validates_timeliness.rb +40 -0
  35. data/config/locales/validates_timeliness.en.yml +16 -0
  36. data/config/locales/validates_timeliness.zh-CN.yml +16 -0
  37. data/db/migrate/20120224051751_add_required_arrival_time_to_rightnow_oms_orders.rb +6 -0
  38. data/db/migrate/20120302085200_add_tastes_to_rightnow_oms_order_items.rb +6 -0
  39. data/lib/rightnow_oms.rb +5 -1
  40. data/lib/rightnow_oms/controller_extension.rb +33 -0
  41. data/lib/rightnow_oms/controller_helpers.rb +4 -21
  42. data/lib/rightnow_oms/version.rb +1 -1
  43. metadata +71 -35
  44. data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/show.hjs +0 -23
  45. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_cartable_count.hjs +0 -1
  46. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_in_detail.hjs +0 -27
  47. data/app/assets/javascripts/rightnow_oms/application.js +0 -8
@@ -1,46 +1,44 @@
1
1
  RightnowOms.CartItem = DS.Model.extend
2
- cartable_id: DS.attr('integer')
2
+ cartable_id: DS.attr('number')
3
3
  cartable_type: DS.attr('string')
4
4
  name: DS.attr('string')
5
5
  original_price: DS.attr('string')
6
- base_quantity: DS.attr('integer')
6
+ base_quantity: DS.attr('number')
7
7
  price: DS.attr('money')
8
- quantity: DS.attr('integer')
8
+ quantity: DS.attr('number')
9
9
  group: DS.attr('string')
10
- parent_id: DS.attr('integer')
11
10
  mergable: DS.attr('boolean')
11
+ parent_id: DS.attr('number')
12
+ cart: DS.belongsTo('RightnowOms.Cart')
13
+ parent: DS.belongsTo('RightnowOms.CartItem', { key: 'parent_id' })
14
+ children: DS.hasMany('RightnowOms.CartItem', { embedded: true })
12
15
 
13
- priceString: (->
16
+ priceString: Ember.computed(->
14
17
  round(@get('price'), 2)
15
18
  ).property('price')
16
19
 
17
- subtotal: (->
20
+ subtotal: Ember.computed(->
18
21
  @get('price') * @get('quantity')
19
22
  ).property('price', 'quantity')
20
23
 
21
- subtotalString: (->
24
+ subtotalString: Ember.computed(->
22
25
  round(@get('subtotal'), 2)
23
26
  ).property('subtotal')
24
27
 
25
- children: (->
26
- RightnowOms.CartItem.findByParentId(@get('id'))
27
- ).property().cacheable()
28
+ hasChildren: Ember.computed(->
29
+ @get('children')? && @getPath('children.length') > 0
30
+ ).property('children')
28
31
 
29
- parent: (->
30
- if @get('parent_id')?
31
- RightnowOms.CartItem.all().filterProperty('id', @get('parent_id'))
32
- ).property('parent_id')
32
+ hasParent: Ember.computed(->
33
+ @get('parent')?
34
+ ).property('parent')
33
35
 
34
- hasChildren: (->
35
- @set('children', RightnowOms.CartItem.findByParentId(@get('id')))
36
- @get('children') && @getPath('children.length') > 0
37
- ).property()
36
+ addChild: (child) ->
37
+ child.parent_id = @get('id')
38
+ childItem = RightnowOms.CartItem.createRecord(child)
39
+ @get('children').pushObject(childItem)
38
40
 
39
- hasParent: (->
40
- @get('parent_id')?
41
- ).property('parent_id')
42
-
43
- isDecreasable: (->
41
+ isDecreasable: Ember.computed(->
44
42
  @get('quantity') > 1
45
43
  ).property('quantity')
46
44
 
@@ -61,34 +59,15 @@ RightnowOms.CartItem = DS.Model.extend
61
59
  @set('quantity', @get('quantity') - @get('base_quantity'))
62
60
 
63
61
  deleteRecord: ->
62
+ # If having children, remove the children from the local store.
63
+ # No use to delete the children explicitly since it will be remove
64
+ # automatically on remote.
64
65
  if @get('hasChildren')
65
- @get('children').forEach((child) ->
66
- child.deleteRecord()
67
- )
66
+ @get('children').forEach(@get('children').removeObject, @get('children'))
68
67
 
69
68
  @_super()
70
69
 
71
70
  isProcessing: ->
72
- @get('isSaving') || @get('children').someProperty('isSaving', true)
73
-
74
- RightnowOms.CartItem.reopenClass
75
- all: ->
76
- RightnowOms.store.findAll(RightnowOms.CartItem)
77
-
78
- findById: (id) ->
79
- @all().filterProperty('id', id).get('firstObject')
80
-
81
- findByParentId: (parentId) ->
82
- @all().filterProperty('parent_id', parentId)
83
-
84
- findByName: (name) ->
85
- @all().filterProperty('name', name).get('firstObject')
86
-
87
- findByCartableAndParentId: (cartableId, cartableType, parentId) ->
88
- @all().filter((item) ->
89
- if item.get('cartable_id') == cartableId && item.get('cartable_type') == cartableType
90
- if parentId?
91
- return true if item.get('parent_id') == parentId
92
- else
93
- return true
94
- ).get('firstObject')
71
+ @get('isSaving') ||
72
+ @get('children').someProperty('isSaving', true) ||
73
+ @get('children').someProperty('isDirty', true)
@@ -0,0 +1,30 @@
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 r-money">{{t currency.unit}}{{ cartItem.priceString }}x{{ cartItem.quantity }}</div>
7
+ <div class="delete">
8
+ <a href="#" {{ action "deleteRecord" }}>{{t buttons.delete}}</a>
9
+ </li>
10
+ </li>
11
+ <div class='r-clear' />
12
+ </ul>
13
+ </dt>
14
+ {{#if isChildrenHidden}}
15
+ {{#if cartItem.hasChildren}}
16
+ <dd>
17
+ {{#each cartItem.children }}
18
+ <ul class='child'>
19
+ <li class="name">{{ name }}</li>
20
+ <li class="others">
21
+ <div class="price r-money">{{t currency.unit}}{{ priceString }}x{{ quantity }}</div>
22
+ <div class="delete" />
23
+ </li>
24
+ <div class="r-clear" />
25
+ </ul>
26
+ {{/each}}
27
+ </dd>
28
+ {{/if}}
29
+ {{/if}}
30
+ {{/unless}}
@@ -3,7 +3,7 @@
3
3
  <ul>
4
4
  <li class="name" {{ action "toggleChildren" }}>{{ cartItem.name }}</li>
5
5
  <li class="others">
6
- <div class='price'>¥{{ cartItem.priceString }}</div>
6
+ <div class='price'>{{t currency.unit}}{{ cartItem.priceString }}</div>
7
7
  <div class="quantity">
8
8
  {{#if hasParent }}
9
9
  <span class="quantity-only">{{ cartItem.quantity }}</span>
@@ -13,10 +13,10 @@
13
13
  <span class="increase"><a href="#" {{ action "increase" }}>+</a></span>
14
14
  {{/if}}
15
15
  </div>
16
- <div class="subtotal r-money">¥{{ cartItem.subtotalString }}</div>
16
+ <div class="subtotal r-money">{{t currency.unit}}{{ cartItem.subtotalString }}</div>
17
17
  <div class="delete">
18
18
  {{#unless cartItem.hasParent }}
19
- <a href="#" {{ action "deleteRecord" }}>删除</a>
19
+ <a href="#" {{ action "deleteRecord" }}>{{t buttons.delete}}</a>
20
20
  {{/unless}}
21
21
  </div>
22
22
  </li>
@@ -2,11 +2,12 @@
2
2
  {{ view RightnowOms.ShowCartableCountView cartableCountBinding="cart.cartableCount" }}
3
3
  </div>
4
4
  <div class="r-cart-items">
5
- {{#each cart.cartItems}}
5
+ {{#each cart.cart_items}}
6
6
  {{ view RightnowOms.ShowCartItemView cartItemBinding="this" }}
7
7
  {{/each}}
8
8
  <div class="r-bottom-bar">
9
- <span>总计:<span class="r-money">¥{{ cart.total }}</span></span>
10
- <span><a href="/rightnow_oms/cart">查看我的购物车</a></span>
9
+ <span>{{t cart.total}} <span class="r-money">{{t
10
+ currency.unit}}{{ cart.total }}</span></span>
11
+ <span><a href="/rightnow_oms/cart">{{t buttons.check_cart}}</a></span>
11
12
  </div>
12
13
  </div>
@@ -0,0 +1,2 @@
1
+ <a href="/rightnow_oms/cart">{{t
2
+ cart.cartable.counter}} ({{cartableCount}})</a>
@@ -0,0 +1,30 @@
1
+ <h2>{{t titles.cart}}</h2>
2
+ <div class="r-cart-items">
3
+ <ul class='title'>
4
+ <li class="name">{{t cart_item.name}}</li>
5
+ <li class="others">
6
+ <div class="price">{{t cart_item.price}}</div>
7
+ <div class="quantity">{{t cart_item.quantity tagName="div"}}</div>
8
+ <div class="subtotal">{{t cart_item.total}}</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>
17
+ </div>
18
+ <div class="r-bottom-bar">
19
+ <div class="left-conner">
20
+ <span class="r-cleanup-cart"><a href="#" {{ action cleanUp }}>{{t
21
+ buttons.clean_cart}}</a></span>
22
+ </div>
23
+ <div class="right-conner">
24
+ <span>{{t cart.total}} <span class="r-money">{{t currency.unit}}{{ cart.total }}</span></span>
25
+ <span class="r-continue-to-shop"><a href="/"><< {{t
26
+ buttons.continue_to_shop}}</a></span>
27
+ <span class="r-checkout"><a {{ bindAttr href="newOrderUrl" }}>{{t
28
+ buttons.new_order}}>></a></span>
29
+ </div>
30
+ </div>
@@ -9,10 +9,13 @@ RightnowOms.ShowCartItemInDetailView = RightnowOms.ShowCartItemView.extend
9
9
  item = @get('cartItem')
10
10
  RightnowOms.cartController.decreaseCartItem(item.get('id'))
11
11
 
12
+ deleteRecord: ->
13
+ item = this.get('cartItem')
14
+ RightnowOms.cartController.removeCartItem(item.get('id'))
15
+
12
16
  mouseEnter: (e) ->
13
17
  $(e.target).parents('.r-cart-items').find('dt').css('background', 'white')
14
18
  $(e.target).parents('dt').css('background','#EEE')
15
19
 
16
-
17
20
  mouseLeave: (e) ->
18
21
  $(e.target).parents('.r-cart-items').find('dt').css('background', 'white')
@@ -0,0 +1,10 @@
1
+ #= require_tree ./lib
2
+ #
3
+ #= require ./app/app
4
+ #= require ./config/app
5
+ #= require ./app/models/cart_item
6
+ #= require ./app/models/cart
7
+ #= require_tree ./app/controllers
8
+ #= require_tree ./app/views
9
+ #= require_tree ./app/templates
10
+
@@ -0,0 +1,10 @@
1
+ //= require jquery
2
+ $(function() {
3
+ $('.r-cart-items dd').hide();
4
+ $('dt').click(function(e) {
5
+ var next = $(this).next();
6
+ if(next.is('dd')) {
7
+ next.toggle();
8
+ }
9
+ });
10
+ });
@@ -0,0 +1,5 @@
1
+ #= require_tree ./locales
2
+ #
3
+ RightnowOms.configure (config) ->
4
+ config.set 'autoCommit', true
5
+ config.set 'defaultLocale', 'en'
@@ -0,0 +1,24 @@
1
+ RightnowOms.configure (config)->
2
+ config.set 'locales.en',
3
+ 'cart.cartable.counter': 'Shopping Cart '
4
+ 'cart.total': 'Total'
5
+
6
+ 'cart_item.name': 'Name'
7
+ 'cart_item.price': 'Price'
8
+ 'cart_item.quantity': 'Quantity'
9
+ 'cart_item.total': 'Total'
10
+
11
+ 'currency.unit': '$'
12
+
13
+ 'buttons.check_cart': 'Check Cart'
14
+ 'buttons.delete': 'Delete'
15
+ 'buttons.clean_cart': 'Clean Up'
16
+ 'buttons.continue_to_shop': 'Continue To Shop'
17
+ 'buttons.new_order': 'Submit'
18
+
19
+ 'titles.cart': 'My Shopping Cart'
20
+
21
+ 'alerts.saving_cart': 'Cart is saving, please wait...'
22
+
23
+ 'confirmations.delete_cart_item': 'Are you sure to delete this cart items?'
24
+ 'confirmations.clean_up_cart': 'Are you sure to clean up the cart?'
@@ -0,0 +1,24 @@
1
+ RightnowOms.configure (config)->
2
+ config.set 'locales.zh_CN',
3
+ 'cart.cartable.counter': '购物车'
4
+ 'cart.total': '总计'
5
+
6
+ 'cart_item.name': '名称'
7
+ 'cart_item.price': '价格'
8
+ 'cart_item.quantity': '数量'
9
+ 'cart_item.total': '小计'
10
+
11
+ 'currency.unit': '¥'
12
+
13
+ 'buttons.check_cart': '查看我的购物车'
14
+ 'buttons.delete': '删除'
15
+ 'buttons.clean_cart': '清空购物车'
16
+ 'buttons.continue_to_shop': '继续购物'
17
+ 'buttons.new_order': '提交订单'
18
+
19
+ 'titles.cart': '我的购物车'
20
+
21
+ 'alerts.saving_cart': '正在保存购物车,请稍后。。。'
22
+
23
+ 'confirmations.delete_cart_item': '您确定要删除该商品吗?'
24
+ 'confirmations.clean_up_cart': '您确定要清空您的购物车吗?'
@@ -1,163 +1,5 @@
1
- get = Ember.get
2
- set = Ember.set
3
- getPath = Ember.getPath
4
-
5
1
  DS.MyRESTAdapter = DS.RESTAdapter.extend
6
- createRecord: (store, type, model) ->
7
- root = @rootForType(type)
8
- url = @buildUrl(type)
9
- data = {}
10
-
11
- data[root] = get(model, 'data')
12
-
13
- @ajax(url, "POST", {
14
- data: data,
15
- success: (json) ->
16
- store.didCreateRecord(model, json[root])
17
- })
18
-
19
- createRecords: (store, type, models) ->
20
- if (get(@, 'bulkCommit') == false)
21
- return @_super(store, type, models)
22
-
23
- root = @rootForType(type)
24
- plural = @pluralize(root)
25
-
26
- data = {}
27
- data[plural] = models.map((model) ->
28
- get(model, 'data')
29
-
30
- )
31
- @ajax(@buildUrl(type), "POST", {
32
- data: data,
33
- success: (json) ->
34
- store.didCreateRecords(type, models, json[plural])
35
- })
36
-
37
- updateRecord: (store, type, model) ->
38
- root = @rootForType(type)
39
-
40
- data = {}
41
- data[root] = get(model, 'data')
42
-
43
- @ajax(@buildUrl(type, @getPrimaryKeyValue(type, model)), "PUT", {
44
- data: data,
45
- success: (json) ->
46
- store.didUpdateRecord(model)
47
- })
48
-
49
- updateRecords: (store, type, models) ->
50
- if (get(@, 'bulkCommit') == false)
51
- return @_super(store, type, models)
52
-
53
- root = @rootForType(type)
54
- plural = @pluralize(root)
55
-
56
- data = {}
57
- data[plural] = models.map((model) ->
58
- get(model, 'data')
59
- )
60
-
61
- @ajax(@buildUrl(type), "POST", {
62
- data: data,
63
- success: (json) ->
64
- store.didUpdateRecords(models, json[plural])
65
- })
66
-
67
- deleteRecord: (store, type, model) ->
68
- root = @rootForType(type)
69
- url = @buildUrl(type, @getPrimaryKeyValue(type, model))
70
-
71
- @ajax(url, "DELETE", {
72
- success: (json) ->
73
- store.didDeleteRecord(model)
74
- })
75
-
76
- deleteRecords: (store, type, models) ->
77
- if (get(@, 'bulkCommit') == false)
78
- return @_super(store, type, models)
79
-
80
- root = @rootType(type)
81
- plural = @pluralize(root)
82
- primaryKey = getPath(type, 'proto.primaryKey')
83
-
84
- data = {}
85
- data[plural] = models.map((model) ->
86
- get(model, primaryKey)
87
- )
88
-
89
- @ajax(@buildUrl(type) + "/delete", "POST", {
90
- data: data
91
- success: (json) ->
92
- store.didDeleteRecords(models)
93
- })
94
-
95
- find: (store, type, id) ->
96
- url = ''
97
- root = @rootForType(type)
98
-
99
- if @isSingleton(type)
100
- url = @buildUrl(type)
101
- else
102
- url = @buildUrl(type, id)
103
-
104
- @ajax(url, "GET", {
105
- success: (json) ->
106
- store.load(type, json[root])
107
- })
108
-
109
- findMany: (store, type, ids) ->
110
- root = @rootForType(type)
111
- plural = @pluralize(root)
112
-
113
- @ajax(@buildUrl(type), "GET", {
114
- data: { ids: ids },
115
- success: (json) ->
116
- store.loadMany(type, ids, json[plural])
117
- })
118
- url = "/" + plural
119
-
120
- findAll: (store, type) ->
121
- root = @rootForType(type)
122
- plural = @pluralize(root)
123
-
124
- @ajax(@buildUrl(type), "GET", {
125
- success: (json) ->
126
- store.loadMany(type, json[plural])
127
- })
128
-
129
- findQuery: (store, type, query, modelArray) ->
130
- root = @rootForType(type)
131
- plural = @pluralize(root)
132
-
133
- @ajax(@buildUrl(type), "GET", {
134
- data: query,
135
- success: (json) ->
136
- modelArray.load(json[plural])
137
- })
138
-
139
- # HELPERS
140
-
141
- plurals: {}
142
-
143
- # define a plurals hash in your subclass to define
144
- # special-case pluralization
145
- pluralize: (name) ->
146
- @plurals[name] || name + "s"
147
-
148
- rootForType: (type) ->
149
- if type.url
150
- return type.url
151
-
152
- # use the last part of the name as the URL
153
- parts = type.toString().split(".")
154
- name = parts[parts.length - 1]
155
- name.replace(/([A-Z])/g, '_$1').toLowerCase().slice(1)
156
-
157
- getPrimaryKeyValue: (type, model)->
158
- primaryKey = getPath(type, 'proto.primaryKey')
159
- get(model, primaryKey)
160
-
2
+ # @private
161
3
  buildUrl: (type, suffix) ->
162
4
  url = [""]
163
5
  root = @rootForType(type)
@@ -171,13 +13,6 @@ DS.MyRESTAdapter = DS.RESTAdapter.extend
171
13
 
172
14
  url.join('/')
173
15
 
16
+ # @private
174
17
  isSingleton: (type) ->
175
18
  if type.isSingleton then type.isSingleton else false
176
-
177
- ajax: (url, type, hash) ->
178
- hash.url = url
179
- hash.type = type
180
- hash.dataType = "json"
181
-
182
- jQuery.ajax(hash)
183
-