Permalink
Browse files

Made PayPal and Responder actions actions almost work

  • Loading branch information...
1 parent 23aff52 commit 72d57ab2331cf870dc80e457f2c13ad126a4f468 Harry Brundage committed Nov 9, 2010
View
2 Resources/app.js
@@ -1,7 +1,7 @@
// App.js
// Module Includes
-Ti.Paypal = require('ti.paypal');
+// Ti.Paypal = require('ti.paypal');
// Namespaces
var Citrus = {};
View
6 Resources/app/controllers/code_reader_controller.coffee
@@ -5,13 +5,9 @@ Ti.include('app/controllers/splash_controller.js')
class CodeReaderController extends Citrus.Controller
constructor: ->
@window = new Citrus.CodeReaderWindow(this, 'Scanner','Scan a code!')
- @code = null
focused: (e) ->
- if @code?
- # Show the code
- else
- this.attemptScan()
+ this.attemptScan()
attemptScan: ->
Titanium.TiBar.scan({
View
8 Resources/app/controllers/code_reader_controller.js
@@ -13,17 +13,11 @@
Ti.include('app/controllers/splash_controller.js');
CodeReaderController = function() {
this.window = new Citrus.CodeReaderWindow(this, 'Scanner', 'Scan a code!');
- this.code = null;
return this;
};
__extends(CodeReaderController, Citrus.Controller);
CodeReaderController.prototype.focused = function(e) {
- var _ref;
- if (typeof (_ref = this.code) !== "undefined" && _ref !== null) {
-
- } else {
- return this.attemptScan();
- }
+ return this.attemptScan();
};
CodeReaderController.prototype.attemptScan = function() {
return Titanium.TiBar.scan({
View
3 Resources/app/controllers/splash_controller.coffee
@@ -131,6 +131,7 @@ class SplashController extends Citrus.Controller
_prepareActions: (actions) ->
for action in actions
if action.requiresResponders()
- action.respondWith(_actionSuccess, _actionFailure)
+ action.respondWith(this._actionSuccess, this._actionFailure)
return actions
+
Citrus.SplashController = SplashController
View
2 Resources/app/controllers/splash_controller.js
@@ -150,7 +150,7 @@
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
action = _ref[_i];
if (action.requiresResponders()) {
- action.respondWith(_actionSuccess, _actionFailure);
+ action.respondWith(this._actionSuccess, this._actionFailure);
}
}
return actions;
View
1 Resources/app/models/actions/action.coffee
@@ -92,3 +92,4 @@ _.extend Citrus.Actions, {
Ti.include("/app/models/actions/platform/platform_action.js")
Ti.include("/app/models/actions/twitter/twitter_action.js")
Ti.include("/app/models/actions/foursquare/foursquare_action.js")
+Ti.include("/app/models/actions/paypal/paypal_action.js")
View
1 Resources/app/models/actions/action.js
@@ -106,4 +106,5 @@
Ti.include("/app/models/actions/platform/platform_action.js");
Ti.include("/app/models/actions/twitter/twitter_action.js");
Ti.include("/app/models/actions/foursquare/foursquare_action.js");
+ Ti.include("/app/models/actions/paypal/paypal_action.js");
}).call(this);
View
2 Resources/app/models/actions/paypal/paypal_action.coffee
@@ -1,4 +1,4 @@
-class PaypalAction extends Citrus.RespondingAction
+class PaypalAction extends Citrus.ResponderAction
@declares: []
type: "PaypalAction"
buttonText: "PaypalAction"
View
4 Resources/app/models/actions/paypal/paypal_action.js
@@ -9,9 +9,9 @@
child.__super__ = parent.prototype;
};
PaypalAction = function() {
- return Citrus.RespondingAction.apply(this, arguments);
+ return Citrus.ResponderAction.apply(this, arguments);
};
- __extends(PaypalAction, Citrus.RespondingAction);
+ __extends(PaypalAction, Citrus.ResponderAction);
PaypalAction.declares = [];
PaypalAction.prototype.type = "PaypalAction";
PaypalAction.prototype.buttonText = "PaypalAction";
View
6 Resources/app/views/splash/actions/action_table_view_row.coffee
@@ -72,7 +72,7 @@ class ActionTableViewRow extends Citrus.Object
displayText: ->
text = Ti.UI.createLabel {
top: 2
- left: 40
+ left: this.textOffset()
color:'#000'
text: this.text()
font:{fontSize:16, fontWeight:'bold'}
@@ -120,8 +120,10 @@ class ActionTableViewRow extends Citrus.Object
return "Run"
text: ->
- @action.actionText
+ return @action.actionText
+ textOffset: ->
+ return 40
Citrus.ActionRows = {}
Citrus.registerActionViewRow = (klass) ->
Citrus.ActionRows[klass::type] = klass
View
5 Resources/app/views/splash/actions/action_table_view_row.js
@@ -87,7 +87,7 @@
var text;
text = Ti.UI.createLabel({
top: 2,
- left: 40,
+ left: this.textOffset(),
color: '#000',
text: this.text(),
font: {
@@ -138,6 +138,9 @@
ActionTableViewRow.prototype.text = function() {
return this.action.actionText;
};
+ ActionTableViewRow.prototype.textOffset = function() {
+ return 40;
+ };
Citrus.ActionRows = {};
Citrus.registerActionViewRow = function(klass) {
return (Citrus.ActionRows[klass.prototype.type] = klass);
View
23 Resources/app/views/splash/actions/paypal_action_table_view_row.coffee
@@ -1,13 +1,21 @@
+Ti.Paypal = require('ti.paypal')
+
class PaypalActionTableViewRow extends Citrus.ActionRows.ActionTableViewRow
type: "PaypalActionTableViewRow"
+ textOffset: () ->
+ return 5
+
displayPhoto: ->
return true
+
displayButton: ->
- @button = Ti.Paypal.createPaypalButton {
- width: 294
- height: 40
+ opts = {
+ width: "auto"
+ height: "auto"
+ top: 4
+ right: 162
appId: "APP-80W284485P519543T"
- buttonStyle: Ti.Paypal.BUTTON_294x43
+ buttonStyle: Ti.Paypal.BUTTON_152x33
paypalEnvironment: Ti.Paypal.PAYPAL_ENV_SANDBOX
feePaidByReceiver: false
transactionType: Ti.Paypal.PAYMENT_TYPE_DONATION
@@ -22,5 +30,12 @@ class PaypalActionTableViewRow extends Citrus.ActionRows.ActionTableViewRow
merchantName: @action.merchantName
}
}
+ d(opts)
+ @button = Ti.Paypal.createPaypalButton opts
+ d(@button)
+ @button.addEventListener "paymentSuccess", @action.success
+ @button.addEventListener "paymentError", (e) -> @action.error(null, null, e)
+ @button.addEventListener "paymentCancled", (e) -> d("Payment canceled.")
+ @row.add(@button)
Citrus.registerActionViewRow PaypalActionTableViewRow
View
28 Resources/app/views/splash/actions/paypal_action_table_view_row.js
@@ -8,20 +8,27 @@
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
};
+ Ti.Paypal = require('ti.paypal');
PaypalActionTableViewRow = function() {
return Citrus.ActionRows.ActionTableViewRow.apply(this, arguments);
};
__extends(PaypalActionTableViewRow, Citrus.ActionRows.ActionTableViewRow);
PaypalActionTableViewRow.prototype.type = "PaypalActionTableViewRow";
+ PaypalActionTableViewRow.prototype.textOffset = function() {
+ return 5;
+ };
PaypalActionTableViewRow.prototype.displayPhoto = function() {
return true;
};
PaypalActionTableViewRow.prototype.displayButton = function() {
- return (this.button = Ti.Paypal.createPaypalButton({
- width: 294,
- height: 40,
+ var opts;
+ opts = {
+ width: "auto",
+ height: "auto",
+ top: 4,
+ right: 162,
appId: "APP-80W284485P519543T",
- buttonStyle: Ti.Paypal.BUTTON_294x43,
+ buttonStyle: Ti.Paypal.BUTTON_152x33,
paypalEnvironment: Ti.Paypal.PAYPAL_ENV_SANDBOX,
feePaidByReceiver: false,
transactionType: Ti.Paypal.PAYMENT_TYPE_DONATION,
@@ -35,7 +42,18 @@
itemDescription: "Donation",
merchantName: this.action.merchantName
}
- }));
+ };
+ d(opts);
+ this.button = Ti.Paypal.createPaypalButton(opts);
+ d(this.button);
+ this.button.addEventListener("paymentSuccess", this.action.success);
+ this.button.addEventListener("paymentError", function(e) {
+ return this.action.error(null, null, e);
+ });
+ this.button.addEventListener("paymentCancled", function(e) {
+ return d("Payment canceled.");
+ });
+ return this.row.add(this.button);
};
Citrus.registerActionViewRow(PaypalActionTableViewRow);
}).call(this);
View
7 Resources/app/views/splash/splash_window.coffee
@@ -1,6 +1,7 @@
Ti.include("/app/views/splash/splash_info_table_view_row.js")
Ti.include("/app/views/splash/actions/action_table_view_row.js")
Ti.include("/app/views/splash/actions/twitter_action_table_view_row.js")
+Ti.include("/app/views/splash/actions/paypal_action_table_view_row.js")
class SplashWindow extends Citrus.GenericWindow
# Sets up the loading indicator
@@ -29,14 +30,16 @@ class SplashWindow extends Citrus.GenericWindow
@win.remove(@table) if @table?
rows = this.getActionRows()
rows.unshift this.getInfoRow()
+ d(rows)
+
@table = Titanium.UI.createTableView({
data: rows
editable: false
allowsSelection: false
})
-
- @win.add(@table)
this.hideLoading()
+ @win.add(@table)
+ d("Table added")
# If a splash couldn't be fetched, this displays the notification and an optional retry button
displayError: (msg, retry, callback) ->
View
5 Resources/app/views/splash/splash_window.js
@@ -11,6 +11,7 @@
Ti.include("/app/views/splash/splash_info_table_view_row.js");
Ti.include("/app/views/splash/actions/action_table_view_row.js");
Ti.include("/app/views/splash/actions/twitter_action_table_view_row.js");
+ Ti.include("/app/views/splash/actions/paypal_action_table_view_row.js");
SplashWindow = function(controller) {
SplashWindow.__super__.constructor.apply(this, arguments);
this.win = Ti.UI.createWindow({
@@ -41,13 +42,15 @@
}
rows = this.getActionRows();
rows.unshift(this.getInfoRow());
+ d(rows);
this.table = Titanium.UI.createTableView({
data: rows,
editable: false,
allowsSelection: false
});
+ this.hideLoading();
this.win.add(this.table);
- return this.hideLoading();
+ return d("Table added");
};
SplashWindow.prototype.displayError = function(msg, retry, callback) {
var _ref;

0 comments on commit 72d57ab

Please sign in to comment.