Skip to content
Browse files

Cleaned up the action taking flow a bit and added elementary account …

…addition inquiries.
  • Loading branch information...
1 parent 3f84ef2 commit 721179e267c9e4f7c685101e04246d67b206f7ad Harry Brundage committed
View
30 Resources/app/controllers/splash_controller.coffee
@@ -44,10 +44,27 @@ class SplashController extends Citrus.Controller
takeActionFromRow: (row, e) =>
action = row.action
- if action.requiresAccount()
- this.takeAccountBasedActionFromRow(row, e)
+ # Run action if possible, if not offer to make it possible
+ if this.isActionTakeable(action)
+ if action.requiresAccount()
+ this.takeAccountBasedActionFromRow(row, e)
+ else
+ this.takeAccountlessActionFromRow(row, e)
else
- this.takeAccountlessActionFromRow(row, e)
+ d("Cant run action!")
+ if action.requiresAccount() && this.possibleAccountsForAction(action).length == 0
+ # Can't run action because no account has been added.
+ type = action.accountType.replace('Account', '')
+ alertDialog = Titanium.UI.createAlertDialog
+ title: 'Whoops!'
+ message: "You can't run this yet because you haven't added a #{type} account yet. Would you like to add one now?"
+ buttonNames: ["Add #{type}", 'Cancel']
+
+ alertDialog.addEventListener 'click', (e) ->
+ unless e.cancel
+ root.AccountsController.addNewAccountOfType(action.accountType)
+ alertDialog.show()
+
takeAccountlessActionFromRow: (row, e) ->
action = row.action
@@ -122,10 +139,9 @@ class SplashController extends Citrus.Controller
row.displaySuccess()
_actionFailure: (row, xhr, status, error) ->
- Titanium.API.error("Action failed!")
- Titanium.API.error(status)
- d(error)
- d(xhr.responseText)
+ er "Action Failed! xhr:", xhr, "status:", status, "error", error
+ if error? && error.alertText? && _.isString(error.alertText)
+ alert error.alertText
row.displayError()
_prepareActions: (actions) ->
View
34 Resources/app/controllers/splash_controller.js
@@ -58,12 +58,30 @@
}, this));
};
SplashController.prototype.takeActionFromRow = function(row, e) {
- var action;
+ var action, alertDialog, type;
action = row.action;
- if (action.requiresAccount()) {
- return this.takeAccountBasedActionFromRow(row, e);
+ if (this.isActionTakeable(action)) {
+ if (action.requiresAccount()) {
+ return this.takeAccountBasedActionFromRow(row, e);
+ } else {
+ return this.takeAccountlessActionFromRow(row, e);
+ }
} else {
- return this.takeAccountlessActionFromRow(row, e);
+ d("Cant run action!");
+ if (action.requiresAccount() && this.possibleAccountsForAction(action).length === 0) {
+ type = action.accountType.replace('Account', '');
+ alertDialog = Titanium.UI.createAlertDialog({
+ title: 'Whoops!',
+ message: "You can't run this yet because you haven't added a " + type + " account yet. Would you like to add one now?",
+ buttonNames: ["Add " + type, 'Cancel']
+ });
+ alertDialog.addEventListener('click', function(e) {
+ if (!e.cancel) {
+ return root.AccountsController.addNewAccountOfType(action.accountType);
+ }
+ });
+ return alertDialog.show();
+ }
}
};
SplashController.prototype.takeAccountlessActionFromRow = function(row, e) {
@@ -141,10 +159,10 @@
return row.displaySuccess();
};
SplashController.prototype._actionFailure = function(row, xhr, status, error) {
- Titanium.API.error("Action failed!");
- Titanium.API.error(status);
- d(error);
- d(xhr.responseText);
+ er("Action Failed! xhr:", xhr, "status:", status, "error", error);
+ if ((error != null) && (error.alertText != null) && _.isString(error.alertText)) {
+ alert(error.alertText);
+ }
return row.displayError();
};
SplashController.prototype._prepareActions = function(actions) {
View
17 Resources/app/models/actions/twitter/follow_action.coffee
@@ -5,6 +5,21 @@ class FollowAction extends Citrus.TwitterAction
buttonText: "Follow"
action: (account, success, failure) ->
- account.api.addFriend(@followeeId, success, failure)
+ account.api.addFriend(@followeeId, success, (xhr, status, error) ->
+ if xhr?
+ d xhr.responseText
+ if xhr.responseText.match(/already on your list/)
+ alert(account.screenName + " is already following this user!")
+ return success({})
+ try
+ msg = JSON.parse xhr.responseText
+ catch e
+ return failure(error)
+
+ if msg? && msg.error?
+ failure(null, null, {alertText: msg.error})
+ else
+ failure(error)
+ )
Citrus.Actions.Twitter.FollowAction = FollowAction
View
23 Resources/app/models/actions/twitter/follow_action.js
@@ -17,7 +17,28 @@
FollowAction.prototype.type = "TwitterFollowAction";
FollowAction.prototype.buttonText = "Follow";
FollowAction.prototype.action = function(account, success, failure) {
- return account.api.addFriend(this.followeeId, success, failure);
+ return account.api.addFriend(this.followeeId, success, function(xhr, status, error) {
+ var msg;
+ if (xhr != null) {
+ d(xhr.responseText);
+ if (xhr.responseText.match(/already on your list/)) {
+ alert(account.screenName + " is already following this user!");
+ return success({});
+ }
+ }
+ try {
+ msg = JSON.parse(xhr.responseText);
+ } catch (e) {
+ return failure(error);
+ }
+ if ((msg != null) && (msg.error != null)) {
+ return failure(null, null, {
+ alertText: msg.error
+ });
+ } else {
+ return failure(error);
+ }
+ });
};
return FollowAction;
}();
View
45 Resources/app/views/splash/actions/action_table_view_row.coffee
@@ -26,31 +26,30 @@ class ActionTableViewRow extends Citrus.Object
row.object = this
return row
- displayButton: (style, title) ->
+ displayButton: (style, title, opts) ->
style ?= Titanium.UI.iPhone.SystemButton.BORDERED
title ?= if _.isFunction(@action.buttonText) then @action.buttonText() else @action.buttonText
key = (String(style)+"style" || "nostyle")
@buttons ?= {} # Keep an array to hold the different styled buttons since changing styles is apparently devastating to the Ti runtime
shittyTI = style == Titanium.UI.iPhone.SystemButton.SPINNER
- unless @buttons[key]?
- # Set up opts. Get around Titanium bugs by not setting the enabled or title attributes if
- # the style is the spinner type (which is proxied by a different object in titanium which
- # barfs when it gets these option)
- opts = {
- right:5
- color: "#000"
- width: this.buttonWidth()
- height: 25
- }
- unless shittyTI
- opts.style = style if style?
- else
- opts.style = style
- opts.enabled = true
- opts.height = "auto"
- opts.width = "auto"
+
+ # Set up opts. Get around Titanium bugs by not setting the enabled or title attributes if
+ # the style is the spinner type (which is proxied by a different object in titanium which
+ # barfs when it gets these option)
+ opts = _.extend({
+ right: 5
+ color: "#000"
+ width: this.buttonWidth()
+ height: 25
+ }, (opts || {}))
+
+ unless shittyTI
+ opts.style = style if style?
+ else
+ opts.systemButton = style
+ unless @buttons[key]?
button = Ti.UI.createButton opts
unless shittyTI
@@ -63,10 +62,12 @@ class ActionTableViewRow extends Citrus.Object
@buttons[key] = button
@row.add(button)
+ for k, v of opts
+ unless _.include(["style", "systemButton"], k)
+ @buttons[key][k] = v
for k, b of @buttons
b.hide()
@buttons[key].title = title
- @buttons[key].enabled = @takeable
@buttons[key].show()
true
@@ -97,14 +98,14 @@ class ActionTableViewRow extends Citrus.Object
d("Trying to display progress")
@state = Citrus.ActionTableViewRow.InProgress
@takeable = false
- this.displayButton(Titanium.UI.iPhone.SystemButton.ACTION, " ")
+ this.displayButton(Titanium.UI.iPhone.SystemButton.SPINNER, "Running ...")
# Updates the row to show the user it's done running its action and it worked!
displaySuccess: ->
d("Trying to display success")
@state = Citrus.ActionTableViewRow.Success
@takeable = false
- this.displayButton(Titanium.UI.iPhone.SystemButton.PLAIN, "Done!")
+ this.displayButton(Titanium.UI.iPhone.SystemButton.PLAIN, "Done!", {enabled: false, color: "#ccc"})
d("Success displayed")
# Updates the row to show that the action failed.
@@ -113,7 +114,7 @@ class ActionTableViewRow extends Citrus.Object
retry ?= true
@state = Citrus.ActionTableViewRow.Error
@takeable = retry
- this.displayButton(null, if retry then "Retry?" else "Error!")
+ this.displayButton(null,(if retry then "Retry?" else "Error!"), {color: 'red'})
d("Error displayed")
icon: ->
View
50 Resources/app/views/splash/actions/action_table_view_row.js
@@ -38,30 +38,27 @@
row.object = this;
return row;
};
- ActionTableViewRow.prototype.displayButton = function(style, title) {
- var b, button, k, key, opts, shittyTI, _ref, _ref2;
+ ActionTableViewRow.prototype.displayButton = function(style, title, opts) {
+ var b, button, k, key, shittyTI, v, _ref, _ref2;
style != null ? style : style = Titanium.UI.iPhone.SystemButton.BORDERED;
title != null ? title : title = _.isFunction(this.action.buttonText) ? this.action.buttonText() : this.action.buttonText;
key = String(style) + "style" || "nostyle";
(_ref = this.buttons) != null ? _ref : this.buttons = {};
shittyTI = style === Titanium.UI.iPhone.SystemButton.SPINNER;
- if (this.buttons[key] == null) {
- opts = {
- right: 5,
- color: "#000",
- width: this.buttonWidth(),
- height: 25
- };
- if (!shittyTI) {
- if (style != null) {
- opts.style = style;
- }
- } else {
+ opts = _.extend({
+ right: 5,
+ color: "#000",
+ width: this.buttonWidth(),
+ height: 25
+ }, opts || {});
+ if (!shittyTI) {
+ if (style != null) {
opts.style = style;
- opts.enabled = true;
- opts.height = "auto";
- opts.width = "auto";
}
+ } else {
+ opts.systemButton = style;
+ }
+ if (this.buttons[key] == null) {
button = Ti.UI.createButton(opts);
if (!shittyTI) {
button.addEventListener("click", __bind(function(e) {
@@ -75,6 +72,13 @@
this.buttons[key] = button;
this.row.add(button);
}
+ for (k in opts) {
+ if (!__hasProp.call(opts, k)) continue;
+ v = opts[k];
+ if (!_.include(["style", "systemButton"], k)) {
+ this.buttons[key][k] = v;
+ }
+ }
_ref2 = this.buttons;
for (k in _ref2) {
if (!__hasProp.call(_ref2, k)) continue;
@@ -82,7 +86,6 @@
b.hide();
}
this.buttons[key].title = title;
- this.buttons[key].enabled = this.takeable;
this.buttons[key].show();
return true;
};
@@ -117,13 +120,16 @@
d("Trying to display progress");
this.state = Citrus.ActionTableViewRow.InProgress;
this.takeable = false;
- return this.displayButton(Titanium.UI.iPhone.SystemButton.ACTION, " ");
+ return this.displayButton(Titanium.UI.iPhone.SystemButton.SPINNER, "Running ...");
};
ActionTableViewRow.prototype.displaySuccess = function() {
d("Trying to display success");
this.state = Citrus.ActionTableViewRow.Success;
this.takeable = false;
- this.displayButton(Titanium.UI.iPhone.SystemButton.PLAIN, "Done!");
+ this.displayButton(Titanium.UI.iPhone.SystemButton.PLAIN, "Done!", {
+ enabled: false,
+ color: "#ccc"
+ });
return d("Success displayed");
};
ActionTableViewRow.prototype.displayError = function(retry) {
@@ -131,7 +137,9 @@
retry != null ? retry : retry = true;
this.state = Citrus.ActionTableViewRow.Error;
this.takeable = retry;
- this.displayButton(null, retry ? "Retry?" : "Error!");
+ this.displayButton(null, (retry ? "Retry?" : "Error!"), {
+ color: 'red'
+ });
return d("Error displayed");
};
ActionTableViewRow.prototype.icon = function() {
View
4 Resources/app/views/splash/splash_window.coffee
@@ -70,7 +70,7 @@ class SplashWindow extends Citrus.GenericWindow
@retryButton.show()
-# Displays non Citrus decoded data as a simple qr code scanner.
+ # Displays non Citrus decoded data as a simple qr code scanner.
displayDecodedData: (data) ->
unless @noticeLabel?
@noticeLabel = Ti.UI.createLabel {
@@ -101,6 +101,8 @@ class SplashWindow extends Citrus.GenericWindow
Titanium.Platform.openURL(link)
@win.add(@dataView)
+ else
+ @dataView.url = 'app/views/splash/local_webview.html'
html = Citrus.redirectifyLinks(sc.helpers.makeClickable(data, {autolink: true, screenname: true}))
@dataView.html = html
View
2 Resources/app/views/splash/splash_window.js
@@ -122,6 +122,8 @@
}
}, this));
this.win.add(this.dataView);
+ } else {
+ this.dataView.url = 'app/views/splash/local_webview.html';
}
html = Citrus.redirectifyLinks(sc.helpers.makeClickable(data, {
autolink: true,

0 comments on commit 721179e

Please sign in to comment.
Something went wrong with that request. Please try again.