summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/nav
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/nav')
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js236
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js36
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js6
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js1
4 files changed, 260 insertions, 19 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js b/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js
index 15a5784d..31e9d802 100644
--- a/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js
@@ -3,24 +3,25 @@ var AddressView = SerializableView.extend({
template: $("#address_template").html(),
+ disabled: false,
+
events: {
},
initialize: function(opt){
this.parent = opt.parent
- this.$el = this.parent.$(".address")
- this.el = this.$el[0]
+ this.checkPhone = 'checkPhone' in opt ? opt.checkPhone : true
+ this.setElement( this.parent.$(".address") )
this.$el.html(this.template)
},
populate: function(data){
- this.parent.$(".address input").val("")
- Object.keys(data).forEach(function(key){
- this.parent$(".address [name=" + key + "]").val(data[key])
- }.bind(this))
- },
-
- deserialize: function(){
+ this.data = data
+ var address = data.Address.split("\n")
+ data.Address1 = address[0]
+ data.Address2 = address[1]
+ this.$(".address input").val("")
+ this.load_data(data)
},
validate_presence: {
@@ -28,12 +29,223 @@ var AddressView = SerializableView.extend({
"Surname": "Please enter your last name.",
"Address1": "Please enter your street address.",
"City": "Please enter your city.",
- "State": "Please choose your state.",
- "Phone": "Please enter your phone number.",
+ "ZipCode": "Please enter your zip code.",
},
validate_fields: function(data, errors){
- if (data.Phone.replace(/[^0-9]/g, "").length < 10) { errors.push([ "Phone", "Phone numbers must be at least 10 digits." ]) }
+ if (this.disabled) { return }
+ if (this.checkPhone && ! data.Phone) { errors.push([ "Phone", "Please enter your phone number." ]) }
+ if (this.checkPhone && data.Phone && data.Phone.replace(/[^0-9]/g, "").length < 10) { errors.push([ "Phone", "Phone numbers must be at least 10 digits." ]) }
+ if (! data.Province || data.Province == "NONE") { errors.push([ "Province", "Please choose your state." ]) }
+ data.Address = data.Address1 + "\n" + data.Address2
+ data.UserId = auth.user_id
+ delete data.Address1
+ delete data.Address2
},
})
+
+
+var COUNTRIES = [
+ ['Country Name', 'NONE'],
+ ['United States', 'US'],
+ ['Abkhazia', 'GE'],
+ ['Afghanistan', 'AF'],
+ ['Albania', 'AL'],
+ ['Algeria', 'DZ'],
+ ['Andorra', 'AD'],
+ ['Angola', 'AO'],
+ ['Antigua and Barbuda', 'AG'],
+ ['Argentina', 'AR'],
+ ['Armenia', 'AM'],
+ ['Australia', 'AU'],
+ ['Austria', 'AT'],
+ ['Azerbaijan', 'AZ'],
+ ['Bahamas', 'BS'],
+ ['Bahrain', 'BH'],
+ ['Bangladesh', 'BD'],
+ ['Barbados', 'BB'],
+ ['Belarus', 'BY'],
+ ['Belgium', 'BE'],
+ ['Belize', 'BZ'],
+ ['Benin', 'BJ'],
+ ['Bhutan', 'BT'],
+ ['Bolivia', 'BO'],
+ ['Bosnia and Herzegovina', 'BA'],
+ ['Botswana', 'BW'],
+ ['Brazil', 'BR'],
+ ['Brunei', 'BN'],
+ ['Bulgaria', 'BG'],
+ ['Burkina Faso', 'BF'],
+ ['Burundi', 'BI'],
+ ['Cambodia', 'KH'],
+ ['Cameroon', 'CM'],
+ ['Canada', 'CA'],
+ ['Cape Verde', 'CV'],
+ ['Central African Republic', 'CF'],
+ ['Chad', 'TD'],
+ ['Chile', 'CL'],
+ ['China', 'CN'],
+ ['Colombia', 'CO'],
+ ['Comoros', 'KM'],
+ ['Congo', 'CD'],
+ ['Congo-Brazzaville', 'CG'],
+ ['Costa Rica', 'CR'],
+ ['Cote d\'Ivoire (Ivory Coast)', 'CI'],
+ ['Croatia', 'HR'],
+ ['Cuba', 'CU'],
+ ['Cyprus', 'CY'],
+ ['Czech Republic', 'CZ'],
+ ['Denmark', 'DK'],
+ ['Djibouti', 'DJ'],
+ ['Dominica', 'DM'],
+ ['Dominican Republic', 'DO'],
+ ['Ecuador', 'EC'],
+ ['Egypt', 'EG'],
+ ['El Salvador', 'SV'],
+ ['Equatorial Guinea', 'GQ'],
+ ['Eritrea', 'ER'],
+ ['Estonia', 'EE'],
+ ['Ethiopia', 'ET'],
+ ['Fiji', 'FJ'],
+ ['Finland', 'FI'],
+ ['France', 'FR'],
+ ['Gabon', 'GA'],
+ ['Gambia', '220'],
+ ['Georgia', 'GE'],
+ ['Germany', 'DE'],
+ ['Ghana', 'GH'],
+ ['Greece', 'GR'],
+ ['Grenada', 'GD'],
+ ['Guatemala', 'GT'],
+ ['Guinea', 'GN'],
+ ['Guinea-Bissau', 'GW'],
+ ['Guyana', 'GY'],
+ ['Haiti', 'HT'],
+ ['Honduras', 'HN'],
+ ['Hungary', 'HU'],
+ ['Iceland', 'IS'],
+ ['India', 'IN'],
+ ['Indonesia', 'ID'],
+ ['Iran', 'IR'],
+ ['Iraq', 'IQ'],
+ ['Ireland', 'IE'],
+ ['Israel', 'IL'],
+ ['Italy', 'IT'],
+ ['Jamaica', 'JM'],
+ ['Japan', 'JP'],
+ ['Jordan', 'JO'],
+ ['Kazakhstan', 'KZ'],
+ ['Kenya', 'KE'],
+ ['Kiribati', 'KI'],
+ ['Kuwait', 'KW'],
+ ['Kyrgyzstan', 'KG'],
+ ['Laos', 'LA'],
+ ['Latvia', 'LV'],
+ ['Lebanon', 'LB'],
+ ['Lesotho', 'LS'],
+ ['Liberia', 'LR'],
+ ['Libya', 'LY'],
+ ['Liechtenstein', 'LI'],
+ ['Lithuania', 'LT'],
+ ['Luxembourg', 'LU'],
+ ['Macedonia', 'MK'],
+ ['Madagascar', 'MG'],
+ ['Malawi', 'MW'],
+ ['Malaysia', 'MY'],
+ ['Maldives', 'MV'],
+ ['Mali', 'ML'],
+ ['Malta', 'MT'],
+ ['Marshall Islands', 'MH'],
+ ['Mauritania', 'MR'],
+ ['Mauritius', 'MU'],
+ ['Mexico', 'MX'],
+ ['Micronesia', 'FM'],
+ ['Moldova', 'MD'],
+ ['Monaco', 'MC'],
+ ['Mongolia', 'MN'],
+ ['Montenegro', 'ME'],
+ ['Morocco', 'MA'],
+ ['Mozambique', 'MZ'],
+ ['Myanmar', 'MM'],
+ ['Nagorno-Karabakh', 'AZ'],
+ ['Namibia', 'NA'],
+ ['Nauru', 'NR'],
+ ['Nepal', 'NP'],
+ ['Netherlands', 'NL'],
+ ['New Zealand', 'NZ'],
+ ['Nicaragua', 'NI'],
+ ['Niger', 'NE'],
+ ['Nigeria', 'NG'],
+ ['North Korea', 'KP'],
+ ['Northern Cyprus', 'CY'],
+ ['Norway', 'NO'],
+ ['Oman', 'OM'],
+ ['Pakistan', 'PK'],
+ ['Palau', 'PW'],
+ ['Panama', 'PA'],
+ ['Papua New Guinea', 'PG'],
+ ['Paraguay', 'PY'],
+ ['Peru', 'PE'],
+ ['Philippines', 'PH'],
+ ['Poland', 'PL'],
+ ['Portugal', 'PT'],
+ ['Qatar', 'QA'],
+ ['Romania', 'RO'],
+ ['Russia', 'RU'],
+ ['Rwanda', 'RW'],
+ ['Saint Kitts and Nevis', 'KN'],
+ ['Saint Lucia', 'LC'],
+ ['Saint Vincent and the Grenadines', 'VC'],
+ ['Samoa', 'WS'],
+ ['San Marino', 'SM'],
+ ['Sao Tome and Principe', 'ST'],
+ ['Saudi Arabia', 'SA'],
+ ['Senegal', 'SN'],
+ ['Serbia', 'RS'],
+ ['Seychelles', 'SC'],
+ ['Sierra Leone', 'SL'],
+ ['Singapore', 'SG'],
+ ['Slovakia', 'SK'],
+ ['Slovenia', 'SI'],
+ ['Solomon Islands', 'SB'],
+ ['Somalia', 'SO'],
+ ['Somaliland', 'SO'],
+ ['South Africa', 'Rand'],
+ ['South Korea', 'KR'],
+ ['South Ossetia', 'GE'],
+ ['Spain', 'ES'],
+ ['Sri Lanka', 'LK'],
+ ['Sudan', 'SD'],
+ ['Suriname', 'SR'],
+ ['Swaziland', 'SZ'],
+ ['Sweden', 'SE'],
+ ['Switzerland', 'CH'],
+ ['Syria', 'SY'],
+ ['Taiwan', 'TW'],
+ ['Tajikistan', 'TJ'],
+ ['Tanzania', 'TZ'],
+ ['Thailand', 'TH'],
+ ['Timor-Leste', 'TL'],
+ ['Togo', 'TG'],
+ ['Tonga', 'TO'],
+ ['Transnistria', 'MD'],
+ ['Trinidad and Tobago', 'TT'],
+ ['Tunisia', 'TN'],
+ ['Turkey', 'TR'],
+ ['Turkmenistan', 'TM'],
+ ['Tuvalu', 'TV'],
+ ['Uganda', 'UG'],
+ ['Ukraine', 'UA'],
+ ['United Arab Emirates', 'AE'],
+ ['United Kingdom', 'GB'],
+ ['Uruguay', 'UY'],
+ ['Uzbekistan', 'UZ'],
+ ['Vanuatu', 'VU'],
+ ['Vatican City', 'VA'],
+ ['Venezuela', 'VE'],
+ ['Vietnam', 'VN'],
+ ['Yemen', 'YE'],
+ ['Zambia', 'ZM'],
+ ['Zimbabwe', 'ZW'],
+]
diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js b/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js
index 33ecab79..1855b7a9 100644
--- a/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js
@@ -1,27 +1,53 @@
-var CreditCardView = View.extend({
+var CreditCardView = SerializableView.extend({
template: $("#creditcard_template").html(),
+ cardOptions: {
+ accept: ['visa', 'mastercard', 'amex'],
+ },
+
events: {
},
initialize: function(opt){
this.parent = opt.parent
- this.parent.$(".cc").html(this.template)
+ this.setElement( this.parent.$(".cc") )
+ this.$el.html(this.template)
+
+ this.$number = this.$("[name=Number]")
+ this.$number.validateCreditCard(this.updateCard.bind(this), this.cardOptions)
},
populate: function(data){
+ this.data = data
+ data.Number = "XXXX XXXX XXXX " + data.Number
+ this.$number.attr("type", "text")
this.parent.$(".cc input").val("")
- Object.keys(data).forEach(function(key){
- this.parent$(".cc [name=" + key + "]").val(data[key])
- }.bind(this))
+ this.$(".cc input").val("")
+ this.load_data(data)
+ },
+
+ updateCard: function(card){
+ // console.log(card)
+ // card.card_type.name
+ // card.card_type.valid
},
validate_presence: {
+ 'Number': 'Please enter your credit card number.',
+ 'Cvv': 'Please enter your security code.',
},
validate_fields: function(data, errors){
+ var card = this.$number.validateCreditCard(this.cardOptions)
+ if (! card.valid) { errors.push([ "Number", "Your card number is invalid." ]) }
+ if (! data.ExpirationMonth || data.ExpirationMonth == "NONE") { errors.push([ "ExpirationMonth", "Please enter the expiration month." ]) }
+ if (! data.ExpirationYear || data.ExpirationYear == "NONE") { errors.push([ "ExpirationYear", "Please select the expiration month." ]) }
+ data.UserId = auth.user_id
+ if (card.valid) {
+ data.Type = card.card_type.name
+ }
},
})
diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js b/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js
index 7563be2d..b2f01208 100644
--- a/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js
@@ -14,7 +14,9 @@ var HeaderView = View.extend({
this.$cart_count = this.$(".cart_count")
},
+ back_state: false,
set_back: function(state){
+ this.back_state = state
if (state) {
this.$burger[0].className = "burger ion-ios-arrow-left"
}
@@ -24,7 +26,7 @@ var HeaderView = View.extend({
},
nav: function(){
- if (app.view.back) {
+ if (this.back_state) {
app.view.back()
}
else {
@@ -43,7 +45,7 @@ var HeaderView = View.extend({
count: 0,
set_cart_count: function(n){
this.count = n
- this.$cart_count.html(n)
+ this.$cart_count.html(n || " ")
},
increment_cart_count: function(){
this.$cart_count.html( ++this.count )
diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js b/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js
index 87e68959..2d8dca43 100644
--- a/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js
+++ b/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js
@@ -34,6 +34,7 @@ var IntroView = View.extend({
else {
heading = e.alpha || 0
}
+ heading = - heading
this.compass.style[transformProp] = "translateZ(0) translateX(-50%) translateY(-50%) rotate(" + heading + "deg)"
},