Created
May 8, 2012 03:46
-
-
Save ryugoo/2632397 to your computer and use it in GitHub Desktop.
http://ti.masuidrive.jp/topic.php?id=1019」 Answer 1 - CoffeeScript
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
### | |
FAQ Answer Program | |
### | |
# Immediate Function | |
do -> | |
### | |
Titanium Window Object | |
### | |
win1 = Ti.UI.createWindow | |
title : "左側のウィンドウ" | |
win2 = Ti.UI.createWindow | |
title : "右側のウィンドウ" | |
### | |
Titanium Tab Group & Tab Object | |
### | |
tabGroup = Ti.UI.createTabGroup() | |
tab1 = Ti.UI.createTab | |
title : "左側のタブ" | |
window : win1 | |
tabGroup.addTab tab1 | |
tab2 = Ti.UI.createTab | |
title : "右側のタブ" | |
window : win2 | |
tabGroup.addTab tab2 | |
# 今現在開いているタブを登録する | |
tabGroup.addEventListener "focus", (e) -> | |
Ti.App.AppCurrentTab = e.tab | |
### | |
Titanium View Object | |
### | |
view1 = Ti.UI.createView | |
width : Ti.UI.FILL, | |
height : Ti.UI.FILL, | |
backgroundColor : "#FFFFFF", | |
layout : "Vertical" | |
win1.add view1 | |
view2 = Ti.UI.createView | |
width : Ti.UI.FILL, | |
height : Ti.UI.FILL, | |
backgroundColor : "#FFFFFF", | |
layout : "Vertical" | |
win2.add view2 | |
### | |
Titanium Button Object | |
### | |
setButton = Ti.UI.createButton | |
title : "登録" | |
# setButton を押したときのイベントを登録する | |
setButton.addEventListener "click", (e) -> | |
log = {} | |
log.Black = tf1.value | |
log.White = tf2.value | |
log.Place = tf3.value | |
# 更新 | |
logs.push log | |
updateLog logs, true | |
# win1 の右側のナビボタンを setButton にする | |
win1.rightNavButton = setButton | |
### | |
Titanium TextField Object | |
### | |
tf1 = Ti.UI.createTextField | |
color : "#336699" | |
hintText : "Black Player Name" | |
height : 44 | |
borderWidth : 1 | |
top : 11 | |
width : Ti.UI.FILL | |
tf2 = Ti.UI.createTextField | |
color : "#336699" | |
hintText : "White Player Name" | |
height : 44 | |
borderWidth : 1 | |
top : 11 | |
width : Ti.UI.FILL | |
tf3 = Ti.UI.createTextField | |
color : "#336699" | |
hintText : "Place" | |
height : 44 | |
borderWidth : 1 | |
top : 11 | |
width : Ti.UI.FILL | |
view1.add tf1 | |
view1.add tf2 | |
view1.add tf3 | |
### | |
Titanium TableView Object | |
### | |
table = Ti.UI.createTableView | |
data : [] | |
editable : true | |
view2.add table | |
### | |
Log Array - Object | |
### | |
logs = [ | |
black : "" | |
white : "" | |
place : "" | |
] | |
# Detail Window | |
detailWindow = (_place) -> | |
detailWin = Ti.UI.createWindow() | |
# detailWin が開いたらアラートで登録した場所情報を表示する | |
detailWin.addEventListener "open", (e) -> | |
alert _place | |
# 今開いているタブで detailWin を開く | |
Ti.App.AppCurrentTab.open detailWin | |
# Update Function | |
updateLog = (_logs, _timing) -> | |
message | |
try | |
currentData = [] | |
for log in _logs | |
row = Ti.UI.createTableViewRow | |
hasChild : true | |
row.addEventListener "click", (e) -> | |
detailWindow log.Place | |
view = Ti.UI.createView | |
height : 44 | |
layout : "Horizontal" | |
backgroundColor : "transparent" | |
black = Ti.UI.createLabel | |
text : "黒 " + log.Black | |
width : Ti.UI.SIZE | |
height : Ti.UI.SIZE | |
font : | |
fontWeight : "bold" | |
fontSize : 8 | |
white = Ti.UI.createLabel | |
text : "白" + log.White | |
width : Ti.UI.SIZE | |
height : Ti.UI.SIZE | |
font : | |
fontWeight : "bold" | |
fontSize : 8 | |
view.add black | |
view.add white | |
row.add view | |
currentData.push row | |
table.setData currentData | |
message = "登録に成功しました!" | |
catch e | |
message = "登録時にエラーが発生しました" | |
_timing = true | |
# updateLog の _timing が true だったらアラートを出す | |
if _timing | |
alert message | |
updateLog logs, false | |
### | |
Application Start | |
### | |
tabGroup.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment