-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Wenwei Cai <stanley.w.cai@gmail.com>
- Loading branch information
Showing
18 changed files
with
294 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
*~ | ||
*.bak |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
Spine = require('spine') | ||
{Panel} = require('spine.mobile') | ||
$ = Spine.$ | ||
Stock = require('models/stock') | ||
|
||
class StockAdd extends Panel | ||
title: 'Stock Add' | ||
|
||
elements: | ||
'form': 'form' | ||
|
||
events: | ||
'submit form': 'submit' | ||
|
||
constructor: -> | ||
super | ||
|
||
@log 'StockAdd instantiated!' | ||
|
||
@addButton('Cancel', @back) | ||
@addButton('Add', @submit).addClass('right') | ||
|
||
@active @render | ||
|
||
render: -> | ||
@log 'StockAdd renderred!' | ||
@html require('views/stocks/add')() | ||
|
||
back: -> | ||
@navigate('/stocks', trans: 'left') | ||
|
||
submit: (e) -> | ||
e.preventDefault() | ||
stock = Stock.fromForm(@form) | ||
console.log stock | ||
if stock.save() | ||
@navigate('/stocks', trans: 'left') | ||
|
||
deactive: -> | ||
super | ||
@form.blur() | ||
|
||
|
||
class StockDetails extends Panel | ||
title: 'Stock Details' | ||
|
||
constructor: -> | ||
super | ||
|
||
@log 'StockDetails instantiated!' | ||
Stock.bind('change', @render) | ||
@active (params) -> @change(params.id) | ||
@addButton('back', @back) | ||
|
||
render: => | ||
return unless @item | ||
@html require('views/stocks/details')(@item) | ||
|
||
back: -> | ||
@navigate('/stocks', trans: 'left') | ||
|
||
change: (id) -> | ||
@item = Stock.find(id) | ||
@render | ||
|
||
|
||
class StockList extends Panel | ||
events: | ||
'tap .item': 'click' | ||
|
||
title: 'Stocks' | ||
|
||
constructor: -> | ||
super | ||
|
||
@log 'StockList instantiated!' | ||
Stock.bind('refresh change', @render) | ||
@addButton('Add', @add).addClass('right') | ||
|
||
click: (e) -> | ||
console.log 'click' | ||
console.log $(e.target).html() | ||
item = $(e.target).item() | ||
@navigate('/stocks', item.id, trans: 'right') | ||
|
||
add: -> | ||
@navigate('/stocks/add', trans: 'right') | ||
|
||
render: => | ||
console.log "render" | ||
items = Stock.all() | ||
@html require('views/stocks/item')(items) | ||
|
||
|
||
class Stocks extends Spine.Controller | ||
constructor: -> | ||
super | ||
|
||
@log 'Stocks instantiated!' | ||
@list = new StockList | ||
@detail = new StockDetails | ||
@add = new StockAdd | ||
|
||
Stock.fetch() | ||
|
||
@routes | ||
'/stocks/add': (params) -> @add.active(params) | ||
'/stocks/:id': (params) -> @detail.active(params) | ||
'/stocks': (params) -> @list.active(params) | ||
|
||
|
||
module.exports = Stocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
require('lib/setup') | ||
|
||
Spine = require('spine') | ||
Spine = require('spine') | ||
{Stage} = require('spine.mobile') | ||
Stocks = require('controllers/stocks') | ||
|
||
class App extends Stage.Global | ||
constructor: -> | ||
super | ||
@log 'StockApp instantiated!' | ||
@stocks = new Stocks | ||
|
||
module.exports = App | ||
Spine.Route.setup(shim: true) | ||
@log 'go StockList' | ||
@navigate '/stocks' | ||
|
||
module.exports = App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Spine = require('spine') | ||
|
||
Spine.Model.Local = | ||
extended: -> | ||
this.change(this.saveLocal) | ||
this.fetch(this.loadLocal) | ||
|
||
saveLocal: -> | ||
result = JSON.stringify(this) | ||
localStorage[@className] = result | ||
|
||
loadLocal: -> | ||
result = localStorage[@className] | ||
this.refresh(result or [], clear: true) | ||
|
||
module.exports = Spine.Model.Local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Spine = require('spine') | ||
$ = jQuery | ||
|
||
class Stock extends Spine.Model | ||
@configure 'Stock', 'name', 'code', 'currentPrice' | ||
|
||
@extend Spine.Model.Local | ||
|
||
constructor: -> | ||
super | ||
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' | ||
@fetchPriceFromSite item for item in @all() | ||
@saveLocal() | ||
|
||
@fetchPriceFromSite: (item) -> | ||
return unless item | ||
console.log item | ||
### | ||
if code.charAt(0) == '6' | ||
url = @endpoint + 'sh' + code | ||
else | ||
url = @endpoint + 'sz' + code | ||
### | ||
console.log Spine.Model.host | ||
url = "#{@endpoint}sh601006" | ||
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 | ||
|
||
module.exports = Stock |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<form> | ||
<label> | ||
<span>Code</span> | ||
<input type="text" name="code"> | ||
</label> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% if @name: %> | ||
<p><%= @name %></p> | ||
<% end %> | ||
|
||
<% if @code: %> | ||
<p><%= @code %></p> | ||
|
||
<% if @currentPrice: %> | ||
<p><%= @currentPrice %></p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="item"> | ||
<table> | ||
<tr> | ||
<td><%= @name %></td> | ||
<td><%= @code %></td> | ||
<td><%= @currentPrice %></td> | ||
</tr> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
.contacts.listView > article | ||
&:empty::after | ||
display: block | ||
text-align: center | ||
margin: 10% 0 | ||
content: "No contacts" | ||
|
||
.contacts.showView > article | ||
padding: 20px | ||
|
||
img | ||
max-width: 150px | ||
max-height: 150px |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
{ | ||
"name": "app", | ||
"name": "StockApp", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"serveup": "~0.0.5", | ||
"hem": "~0.1.8", | ||
"es5-shimify": "~0.0.1", | ||
"json2ify": "~0.0.1", | ||
"jqueryify": "~0.0.1", | ||
"jquery.tmpl": "~0.0.1", | ||
"spine": "~1.0.7", | ||
"spine.mobile": "~1.0.0", | ||
"gfx": "~0.0.4" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"es5-shimify", | ||
"json2ify", | ||
"jqueryify", | ||
"jquery.tmpl", | ||
"gfx", | ||
"spine", | ||
"spine/lib/local", | ||
|