Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Second update

now click to StockList is working

Signed-off-by: Wenwei Cai <stanley.w.cai@gmail.com>
  • Loading branch information...
commit 72cf622a8f74778103d9908b4e577fe5240edde6 1 parent 14ca5bc
Wenwei Cai authored
11 app/controllers/stocks.coffee
View
@@ -75,20 +75,23 @@ class StockList extends Panel
@log 'StockList instantiated!'
Stock.bind('refresh change', @render)
+ @active Stock.updateAll
+ @addButton('Refresh', @render)
@addButton('Add', @add).addClass('right')
click: (e) ->
console.log 'click'
- console.log $(e.target).html()
- item = $(e.target).item()
+ console.log $(e.currentTarget)
+ item = Stock.all()[$(e.currentTarget).index()]
@navigate('/stocks', item.id, trans: 'right')
add: ->
@navigate('/stocks/add', trans: 'right')
render: =>
- console.log "render"
+ console.log "render #{Stock.count()}"
items = Stock.all()
+ console.log require('views/stocks/item')(items)
@html require('views/stocks/item')(items)
@@ -101,7 +104,9 @@ class Stocks extends Spine.Controller
@detail = new StockDetails
@add = new StockAdd
+ console.log "start fetch"
Stock.fetch()
+ console.log "fetch done"
@routes
'/stocks/add': (params) -> @add.active(params)
1  app/index.coffee
View
@@ -1,6 +1,7 @@
require('lib/setup')
Spine = require('spine')
+$ = Spine.$
{Stage} = require('spine.mobile')
Stocks = require('controllers/stocks')
1  app/lib/setup.coffee
View
@@ -1,7 +1,6 @@
require('json2ify')
require('es5-shimify')
require('jqueryify')
-require('jquery.tmpl')
require('spine')
require('spine/lib/local')
27 app/models/stock.coffee
View
@@ -8,35 +8,32 @@ class Stock extends Spine.Model
constructor: ->
super
- Spine.Model.host = 'http://hq.sinajs.cn'
+ # Spine.Model.host = 'http://hq.sinajs.cn'
# @default: -> new @(name: 'GREE Electronics', code: '000651', 'currentPrice': 0.0)
@endpoint: 'http://hq.sinajs.cn/list='
@fetch: ->
super
- console.log 'aaa'
+ @updateAll
+
+ @updateAll: =>
+ console.log "fetch #{@count()}"
@fetchPriceFromSite item for item in @all()
@saveLocal()
-
- @fetchPriceFromSite: (item) ->
+
+ @fetchPriceFromSite: (item) =>
return unless item
console.log item
- ###
- if code.charAt(0) == '6'
- url = @endpoint + 'sh' + code
+ if item.code.charAt(0) == '6'
+ url = @endpoint + 'sh' + item.code
else
- url = @endpoint + 'sz' + code
- ###
- console.log Spine.Model.host
- url = "#{@endpoint}sh601006"
+ url = @endpoint + 'sz' + item.code
console.log url
$.get url, (data) =>
left = data.indexOf '"'
right = data.lastIndexOf '"'
- items = (data.substring left + 1, right).split(",")
- item.name = items[0]
- item.currentPrice = items[3]
- console.log item
+ vals = (data.substring left + 1, right).split(",")
+ item.updateAttributes(name: vals[0], currentPrice: vals[3])
module.exports = Stock
3  package.json
View
@@ -7,8 +7,7 @@
"es5-shimify": "~0.0.1",
"json2ify": "~0.0.1",
"jqueryify": "~0.0.1",
- "jquery.tmpl": "~0.0.1",
- "spine": "~1.0.7",
+ "spine": "~1.0.6",
"spine.mobile": "~1.0.0",
"gfx": "~0.0.4"
}
1  slug.json
View
@@ -3,7 +3,6 @@
"es5-shimify",
"json2ify",
"jqueryify",
- "jquery.tmpl",
"gfx",
"spine",
"spine/lib/local",
Please sign in to comment.
Something went wrong with that request. Please try again.