Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Brundage committed Nov 28, 2010
2 parents 8c59957 + 3f84ef2 commit 4af0568
Show file tree
Hide file tree
Showing 33 changed files with 543 additions and 256 deletions.
14 changes: 7 additions & 7 deletions Resources/app.js
Expand Up @@ -80,12 +80,12 @@ Ti.include('app/helpers/icons_helper.js');


// Citrus Specific Abstractions // Citrus Specific Abstractions
Ti.include("/app/models/observable.js") Ti.include("/app/models/observable.js")
Ti.include('app/models/object.js'); Ti.include('/app/models/object.js');
Ti.include('app/models/persisted_object.js'); Ti.include('/app/models/persisted_object.js');
Ti.include('app/views/generic_window.js'); Ti.include('/app/views/generic_window.js');
Ti.include('app/views/placeholder_window.js'); Ti.include('/app/views/placeholder_window.js');
Ti.include('app/views/data_collection_window.js'); Ti.include('/app/views/data_collection_window.js');
Ti.include('app/controllers/controller.js'); Ti.include('/app/controllers/controller.js');


var root = new Citrus.Object(); // Make sure root gets event listeners var root = new Citrus.Object(); // Make sure root gets event listeners
Ti.include('app/controllers/main.js'); Ti.include('/app/controllers/main.js');
24 changes: 24 additions & 0 deletions Resources/app/controllers/code_history_controller.coffee
@@ -0,0 +1,24 @@
Ti.include('/app/views/code_history/code_history_table_view_window.js')
Ti.include('/app/models/splash_store.js')

class CodeHistoryController extends Citrus.Controller
scans: []
page: 0

constructor: () ->
d "Code history controller being created"
@window = new Citrus.CodeHistoryTableViewWindow(this)
@window.win.addEventListener("focus", (e) => this.focused(e))

focused: (e) ->
d "Code history being shown."
if @scans.length == 0
this.showNextPage()

showNextPage: () ->
@window.showLoading()
@window.hideLoading()
# Get scans for page and add to scans array
# Add new scans to window

Citrus.CodeHistoryController = CodeHistoryController
37 changes: 37 additions & 0 deletions Resources/app/controllers/code_history_controller.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Resources/app/controllers/code_reader_controller.coffee
Expand Up @@ -30,7 +30,12 @@ class CodeReaderController extends Citrus.Controller
success: (data) -> success: (data) ->
if data?.barcode? if data?.barcode?
Titanium.Media.vibrate() Titanium.Media.vibrate()
new Citrus.SplashController(data.barcode, root.accountStore) controller = new Citrus.SplashController(data.barcode, root.accountStore)
controller.addEventListener "splash:found", (e) ->
root.splashStore.addSplash(e.splash)

controller.tryToShow()

cancel: -> cancel: ->
# alert("Canceled") # alert("Canceled")
error: -> error: ->
Expand Down
7 changes: 6 additions & 1 deletion Resources/app/controllers/code_reader_controller.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
3 changes: 0 additions & 3 deletions Resources/app/controllers/codes.js

This file was deleted.

4 changes: 2 additions & 2 deletions Resources/app/controllers/controller.coffee
@@ -1,3 +1,3 @@
class Controller class Controller extends Citrus.Object


Citrus.Controller = Controller Citrus.Controller = Controller
13 changes: 12 additions & 1 deletion Resources/app/controllers/controller.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 22 additions & 21 deletions Resources/app/controllers/main.coffee
Expand Up @@ -4,40 +4,41 @@ Ti.include('app/helpers/icons_helper.js')
# Main controllers # Main controllers
Ti.include('app/controllers/accounts_controller.js') Ti.include('app/controllers/accounts_controller.js')
Ti.include('app/controllers/code_reader_controller.js') Ti.include('app/controllers/code_reader_controller.js')
Ti.include('app/views/codes/codes_window.js') Ti.include('app/controllers/code_history_controller.js')


root.tabGroup = Titanium.UI.createTabGroup({barColor:'#336699'}) root.tabGroup = Titanium.UI.createTabGroup
Titanium.UI.setBackgroundColor('#000') barColor:'#336699'

Titanium.UI.setBackgroundColor '#000'


# Code Reader tab group # Code Reader tab group
root.CodeReaderController = new Citrus.CodeReaderController() root.CodeReaderController = new Citrus.CodeReaderController()
codeReaderTab = Titanium.UI.createTab({ codeReaderTab = Titanium.UI.createTab
icon:'images/radar.png', icon:'images/radar.png',
title:'Scanner', title:'Scanner',
window: root.CodeReaderController.window.win window: root.CodeReaderController.window.win
})



# Accounts List tab group # Accounts List tab group
root.accountStore = new Citrus.AccountSet() root.accountStore = new Citrus.AccountSet()
root.AccountsController = new Citrus.AccountsController(root.accountStore) root.AccountsController = new Citrus.AccountsController(root.accountStore)


accountsTab = Titanium.UI.createTab({ accountsTab = Titanium.UI.createTab
icon:'images/id-card.png', icon:'images/id-card.png',
title:'Accounts', title:'Accounts',
window: root.AccountsController.window.win window: root.AccountsController.window.win
})


# Scanned Codes list tab group # Scanned Codes list tab group
root.CodesWindow = new Citrus.CodesWindow('Codes','No Codes scanned yet.') root.splashStore = new Citrus.SplashStore()
codesTab = Titanium.UI.createTab({ root.CodeHistoryController = new Citrus.CodeHistoryController()
icon:'images/clock.png',
title:'Scanned Codes', codesTab = Titanium.UI.createTab
window: root.CodesWindow.win icon:'images/clock.png'
}) title:'Scanned Codes'
window: root.CodeHistoryController.window.win


Titanium.include('test.js') Titanium.include('test.js')


root.tabGroup.addTab(tab) for tab in [codeReaderTab, accountsTab, codesTab] root.tabGroup.addTab(tab) for tab in [codeReaderTab, accountsTab, codesTab]
root.tabGroup.setActiveTab(accountsTab) root.tabGroup.setActiveTab(accountsTab)
root.tabGroup.open({transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT}) root.tabGroup.open
transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
7 changes: 4 additions & 3 deletions Resources/app/controllers/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/app/controllers/splash_controller.coffee
Expand Up @@ -7,7 +7,6 @@ class SplashController extends Citrus.Controller
@window = new Citrus.SplashWindow(this) @window = new Citrus.SplashWindow(this)


root.tabGroup.activeTab.open @window.win, {animated:true} root.tabGroup.activeTab.open @window.win, {animated:true}
this.tryToShow()


tryToShow: () -> tryToShow: () ->
d("Trying to show "+@codeData) d("Trying to show "+@codeData)
Expand All @@ -17,6 +16,7 @@ class SplashController extends Citrus.Controller
d("Found a splash in the decoded data, with shortcode "+splash.shortcode) d("Found a splash in the decoded data, with shortcode "+splash.shortcode)
@splash = splash @splash = splash
@splash.actions = this._prepareActions(@splash.actions) @splash.actions = this._prepareActions(@splash.actions)
this.fireEvent "splash:found", {splash:@splash}
@window.displaySplash(@splash) @window.displaySplash(@splash)
, (xhr, status, error) => , (xhr, status, error) =>
e("Error finding a Citrus splash from the decoded data. Status: "+status) e("Error finding a Citrus splash from the decoded data. Status: "+status)
Expand Down
4 changes: 3 additions & 1 deletion Resources/app/controllers/splash_controller.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 13 additions & 14 deletions Resources/app/models/accounts/account_set.coffee
@@ -1,55 +1,54 @@
class AccountSet extends Citrus.Object class AccountSet extends Citrus.Object

constructor: () -> constructor: () ->
@accounts = [] @accounts = []

this.load() this.load()

# Loads the account set from the app properties # Loads the account set from the app properties
load: -> load: ->
# Ti.API.debug("Loading accounts from : ") # Ti.API.debug("Loading accounts from : ")
# Ti.API.debug(Ti.App.Properties.getString("CitrusAccounts")) # Ti.API.debug(Ti.App.Properties.getString("CitrusAccounts"))

return [] unless Ti.App.Properties.hasProperty(this.key()) return [] unless Ti.App.Properties.hasProperty(this.key())
try try
datas = JSON.parse(Ti.App.Properties.getString(this.key())) datas = JSON.parse(Ti.App.Properties.getString(this.key()))
catch e catch e
Ti.API.error("Error parsing account set JSON from properties: ") Ti.API.error("Error parsing account set JSON from properties: ")
Ti.API.error(e) Ti.API.error(e)
return false return false

datas ?= [] datas ?= []
accounts = [] accounts = []
for datum in datas for datum in datas
account = Citrus.PersistedObject.loadFromPersistable(datum) account = Citrus.PersistedObject.loadFromPersistable(datum)
if account if account
Ti.API.info("Loaded "+account.type+" from persistable.") Ti.API.info("Loaded "+account.type+" from persistable.")
accounts.push account accounts.push account

@accounts = accounts @accounts = accounts
return @accounts return @accounts

# Persists the account set so the app can be closed. Works by serializing the accounts # Persists the account set so the app can be closed. Works by serializing the accounts
# to JSON and then saving in the app properties. # to JSON and then saving in the app properties.
save: -> save: ->
Ti.API.debug("Saving accounts store.") Ti.API.debug("Saving accounts store.")
persistable_accounts = [] persistable_accounts = []
for account in @accounts for account in @accounts
persistable_accounts.push(account.persistable()) persistable_accounts.push(account.persistable())


return Ti.App.Properties.setString(this.key(), JSON.stringify(persistable_accounts)) return Ti.App.Properties.setString(this.key(), JSON.stringify(persistable_accounts))

key: -> key: ->
return "CitrusAccounts" return "CitrusAccounts"


addAccount: (account) -> addAccount: (account) ->
Ti.API.debug("Account Added to store.") Ti.API.debug("Account Added to store.")
@accounts.push account @accounts.push account
this.save() this.save()

removeAccount: (account) -> removeAccount: (account) ->
@accounts = _.without(@accounts, account) @accounts = _.without(@accounts, account)
this.save() this.save()

Citrus.AccountSet = AccountSet Citrus.AccountSet = AccountSet
21 changes: 10 additions & 11 deletions Resources/app/models/actions/action.coffee
Expand Up @@ -17,18 +17,17 @@ class Action extends Citrus.Object
actionText: "" actionText: ""


constructor: (attributes) -> constructor: (attributes) ->
if (_.keys(attributes).length == (this.constructor.declares.length + Citrus.Action.alwaysDeclared.length)) unless (_.keys(attributes).length == (this.constructor.declares.length + Citrus.Action.alwaysDeclared.length))
@valid = true
for k, v of attributes
k = k.camelize(true) # Camel case the underscored lowercase Rails text
if _.isFunction(this[k])
@valid = (@valid && this[k].call(v))
else
this[k] = v

else
Ti.API.debug("Wrong amount of arguments passed to action constructor!") Ti.API.debug("Wrong amount of arguments passed to action constructor!")
@valid = false
@valid = true
for k, v of attributes
k = k.camelize(true) # Camel case the underscored lowercase Rails text
if _.isFunction(this[k])
@valid = (@valid && this[k].call(v))
else
this[k] = v



readyToRun: () -> readyToRun: () ->
return true return true
Expand Down
26 changes: 12 additions & 14 deletions Resources/app/models/actions/action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4af0568

Please sign in to comment.