From 50b635f41d93e7a8a602cd7d9a9b480d95acbe75 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Mon, 29 Feb 2016 22:22:28 -0500 Subject: [PATCH 01/12] Adds Worldwide Shipping to editItem - initial code for editing item --- js/models/languagesMd.js | 2 ++ js/router.js | 3 ++- js/views/itemEditVw.js | 48 +++++++++++++++++++++++++++++++++++++++- js/views/userPageVw.js | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/js/models/languagesMd.js b/js/models/languagesMd.js index 7ce20c833..af95fcdca 100644 --- a/js/models/languagesMd.js +++ b/js/models/languagesMd.js @@ -276,6 +276,8 @@ module.exports = Backbone.Model.extend({ ThisUserIsNSFW: "This user is hidden because their page is listed as NSFW", ShowBlockedUser: "Show this user's page except for NSFW listings", ShowNSFWContent: "Show this user's page, and all NSFW listings", + NoShipping: "Digital or Remote (No Shipping)", + WorldwideShipping: "Worldwide", ServerChangeWarningHeadline: "Caution: Record Your Settings", ServerChangeWarning: "We recommend you make a copy of your previous settings, shown below. Your previous username and password will no longer be available beyond this point.", moderatorSettings: { diff --git a/js/router.js b/js/router.js index 41361698e..d7e67b96d 100644 --- a/js/router.js +++ b/js/router.js @@ -71,8 +71,9 @@ module.exports = Backbone.Router.extend({ // user entered a search term deferred.resolve('#home/products/' + routeArray[0].replace('#', '')); } else { + console.log("test") //user entered text that doesn't match a known pattern, assume it's a product search - deferred.resolve('#home/products/'); + deferred.resolve('#home/products/' + routeArray[0]); } return deferred.promise(); diff --git a/js/views/itemEditVw.js b/js/views/itemEditVw.js index be8a4a222..740c10d3b 100644 --- a/js/views/itemEditVw.js +++ b/js/views/itemEditVw.js @@ -31,7 +31,8 @@ module.exports = baseVw.extend({ var self=this, hashArray = this.model.get('vendor_offer').listing.item.image_hashes, nowDate = new Date(), - nowMonth = nowDate.getMonth()+ 1; + nowMonth = nowDate.getMonth()+ 1, + noShipping = false; function padTime(val){ "use strict"; @@ -106,8 +107,10 @@ module.exports = baseVw.extend({ //hide or unhide shipping based on product type if(typeValue === "physical good") { this.enableShipping(); + this.noShipping = false; } else { this.disableShipping(); + this.noShipping = true; } //hide or unhide shipping based on free shipping if(this.model.get('vendor_offer').listing.shipping.free == true){ @@ -122,6 +125,43 @@ module.exports = baseVw.extend({ //add all countries to the Ships To select list var countries = new countriesModel(); var countryList = countries.get('countries'); + countryList.unshift( + { + "name": window.polyglot.t('WorldwideShipping'), + "dataName": "ALL", + "code": "ALL", + "number": "1" + }, + { + "name": "North America", + "dataName": "NORTH_AMERICA", + "code": "NORTH_AMERICA", + "number": "2" + }, + { + "name": "South America", + "dataName": "SOUTH_AMERICA", + "code": "SOUTH_AMERICA", + "number": "3" + }, + { + "name": "Europe", + "dataName": "EUROPE", + "code": "EUROPE", + "number": "4" + }, + { + "name": "Africa", + "dataName": "AFRICA", + "code": "AFRICA", + "number": "5" + }, + { + "name": "Asia", + "dataName": "ASIA", + "code": "ASIA", + "number": "6" + }); var shipsTo = this.$el.find('#shipsTo'); __.each(countryList, function(countryFromList, i){ shipsTo.append(''); @@ -186,9 +226,11 @@ module.exports = baseVw.extend({ if(this.$el.find('input[name=free_shipping]').val() == "false") { this.enableShippingPrice(); } + this.noShipping = false; } else { this.disableShipping(); this.disableShippingPrice(); + this.noShipping = true; } }, @@ -390,6 +432,10 @@ module.exports = baseVw.extend({ return newTag; }); + if(this.noShipping){ + //do some clever stuff to insert value NA/0 if no shipping + } + this.$el.find('#inputCurrencyCode').val(cCode); this.$el.find('#inputShippingCurrencyCode').val(cCode); this.$el.find('#inputShippingOrigin').val(this.model.get('userCountry')); diff --git a/js/views/userPageVw.js b/js/views/userPageVw.js index dcaa3bcf5..d11b99150 100644 --- a/js/views/userPageVw.js +++ b/js/views/userPageVw.js @@ -1244,7 +1244,7 @@ module.exports = baseVw.extend({ saveNewDone: function(newHash) { "use strict"; - this.setState('item', newHash); + this.setState('listing', newHash); this.subRender(); }, From 3cba0bdd814e443ee360e7812f5acffd6756a805 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Tue, 1 Mar 2016 13:40:27 -0500 Subject: [PATCH 02/12] remove log --- js/router.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/router.js b/js/router.js index d7e67b96d..3bffb462e 100644 --- a/js/router.js +++ b/js/router.js @@ -71,7 +71,6 @@ module.exports = Backbone.Router.extend({ // user entered a search term deferred.resolve('#home/products/' + routeArray[0].replace('#', '')); } else { - console.log("test") //user entered text that doesn't match a known pattern, assume it's a product search deferred.resolve('#home/products/' + routeArray[0]); } From 63deb565fe6e1d24cabf32291d307c5760a8c614 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Mon, 7 Mar 2016 18:44:36 -0500 Subject: [PATCH 03/12] adding buttons --- css/obBase.css | 21 ++++++++++++--------- js/templates/itemEdit.html | 17 +++++++++++++++++ js/views/itemEditVw.js | 33 ++------------------------------- js/views/settingsVw.js | 1 + 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/css/obBase.css b/css/obBase.css index 63fe015dc..b511f7e72 100644 --- a/css/obBase.css +++ b/css/obBase.css @@ -2947,15 +2947,19 @@ input[type="checkbox"].fieldItem + label { } input[type="checkbox"].fieldItem + label:before { - content: "\f371"; + content: ""; display: inline-block; - font-family: Ionicons; position: absolute; left: 10px; - top: 0; - font-size: 18px; - width: 15px; - text-align: center; + height: 16px; + width: 16px; + border-radius: 4px; + border: solid 1px #fff; + box-shadow: none; + opacity: 1; + transform: translateY(-50%) translateZ(0); + -webkit-backface-visibility: hidden; + top: 50%; } input[type="checkbox"].fieldItem + label.compact { @@ -2968,9 +2972,8 @@ input[type="checkbox"].fieldItem + label.compact:before { } input[type="checkbox"].fieldItem:checked + label:before { - content: "\f374"; - font-family: Ionicons; - background: transparent; + background: #fff; + box-shadow: inset 0 0 0 4px #086A9E; } input[type="checkbox"].fieldItem + label div, diff --git a/js/templates/itemEdit.html b/js/templates/itemEdit.html index 6040123c3..ebacf47d7 100644 --- a/js/templates/itemEdit.html +++ b/js/templates/itemEdit.html @@ -191,6 +191,23 @@
<%= polyglot.t('Shipping') %>
+
+
+
+ +
+
+
+
+ + +
+
+
diff --git a/js/views/itemEditVw.js b/js/views/itemEditVw.js index 0b6c47cad..2cc21c4fb 100644 --- a/js/views/itemEditVw.js +++ b/js/views/itemEditVw.js @@ -134,43 +134,14 @@ module.exports = baseVw.extend({ } //add all countries to the Ships To select list var countries = new countriesModel(); - var countryList = countries.get('countries'); + //make a copy of the countries array + var countryList = countries.get('countries').slice(0); countryList.unshift( { "name": window.polyglot.t('WorldwideShipping'), "dataName": "ALL", "code": "ALL", "number": "1" - }, - { - "name": "North America", - "dataName": "NORTH_AMERICA", - "code": "NORTH_AMERICA", - "number": "2" - }, - { - "name": "South America", - "dataName": "SOUTH_AMERICA", - "code": "SOUTH_AMERICA", - "number": "3" - }, - { - "name": "Europe", - "dataName": "EUROPE", - "code": "EUROPE", - "number": "4" - }, - { - "name": "Africa", - "dataName": "AFRICA", - "code": "AFRICA", - "number": "5" - }, - { - "name": "Asia", - "dataName": "ASIA", - "code": "ASIA", - "number": "6" }); var shipsTo = this.$el.find('#shipsTo'); __.each(countryList, function(countryFromList, i){ diff --git a/js/views/settingsVw.js b/js/views/settingsVw.js index 7a5de3a79..80dd0dfae 100644 --- a/js/views/settingsVw.js +++ b/js/views/settingsVw.js @@ -375,6 +375,7 @@ module.exports = Backbone.View.extend({ currecyList = __.uniq(currecyList, function(item){return item.code;}); currecyList = currecyList.sort(function(a,b){ + console.log(a.name + " " + b.name) var cA = a.currency.toLowerCase(), cB = b.currency.toLowerCase(); if (cA < cB){ From 6446dd49eaea9c7d5357d0c8d1342d5efe5af9b4 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Tue, 8 Mar 2016 10:50:13 -0500 Subject: [PATCH 04/12] shipping regions and min zero - add shipping regions buttons - default to worldwide - set min for shipping to zero --- js/models/languagesMd.js | 1 + js/templates/itemEdit.html | 44 ++++++++++++++------------------------ js/views/itemEditVw.js | 22 ++++++++++++++++++- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/js/models/languagesMd.js b/js/models/languagesMd.js index 1b9f8fd17..68639e052 100644 --- a/js/models/languagesMd.js +++ b/js/models/languagesMd.js @@ -122,6 +122,7 @@ module.exports = Backbone.Model.extend({ Keywords: "Keywords", ShipsFrom: "Ships From", ShipsTo: "Ships To", + AddShipToRegion: "Add Shipping Region", Optional: "Optional", Customize: "Customize", Save: "Save", diff --git a/js/templates/itemEdit.html b/js/templates/itemEdit.html index ebacf47d7..4faef8831 100644 --- a/js/templates/itemEdit.html +++ b/js/templates/itemEdit.html @@ -194,17 +194,13 @@
<%= polyglot.t('Shipping') %>
- +
-
- - +
@@ -245,16 +241,12 @@
<%= polyglot.t('Shipping') %>
- - min="0.0001" - <% } else { %> - min="<% print((window.currentBitcoin * 0.0005).toFixed(2)) %>" - <% } %> - > -
-
- Minimum is <%= ob.userCurrencyCode == "BTC" ? 0.0001 : (window.currentBitcoin * 0.0005).toFixed(2) %> +
@@ -265,16 +257,12 @@
<%= polyglot.t('Shipping') %>
- - min="0.0001" - <% } else { %> - min="<% print((window.currentBitcoin * 0.0005).toFixed(2)) %>" - <% } %> - > -
-
- Minimum is <%= ob.userCurrencyCode == "BTC" ? 0.0001 : (window.currentBitcoin * 0.0005).toFixed(2) %> +
diff --git a/js/views/itemEditVw.js b/js/views/itemEditVw.js index 6a1b4f23b..2d9a26e39 100644 --- a/js/views/itemEditVw.js +++ b/js/views/itemEditVw.js @@ -27,7 +27,8 @@ module.exports = baseVw.extend({ 'blur input': 'validateInput', 'blur textarea': 'validateInput', 'focus #inputExpirationDate': 'addDefaultTime', - 'click .js-itemEditClearDate': 'clearDate' + 'click .js-itemEditClearDate': 'clearDate', + 'click .js-region': 'selectRegions' }, MAX_PHOTOS: 10, @@ -48,6 +49,16 @@ module.exports = baseVw.extend({ } } + this.regions = { + "EUROPEAN_UNION": ["AUSTRIA", "BELGIUM", "BULGARIA", "CROATIA", "CYPRUS", "CZECH_REPUBLIC", "DENMARK", "ESTONIA", + "FINLAND", "FRANCE", "GERMANY", "GREECE", "HUNGARY", "IRELAND", "ITALY", "LATVIA", "LITHUANIA", "LUXEMBOURG", + "MALTA", "NETHERLANDS", "POLAND", "PORTUGAL", "ROMANIA", "SLOVAKIA", "SLOVENIA", "SPAIN", "SWEDEN", "UNITED_KINGDOM"], + "EUROPEAN_ECONOMIC_AREA": ["AUSTRIA", "BELGIUM", "BULGARIA", "CROATIA", "CYPRUS", "CZECH_REPUBLIC", "DENMARK", + "ESTONIA", "FINLAND", "FRANCE", "GERMANY", "GREECE", "HUNGARY", "ICELAND", "IRELAND", "ITALY", "LATVIA", + "LIECHTENSTEIN", "LITHUANIA", "LUXEMBOURG", "MALTA", "NETHERLANDS", "NORWAY", "POLAND", "PORTUGAL", "ROMANIA", + "SLOVAKIA", "SLOVENIA", "SPAIN", "SWEDEN", "UNITED_KINGDOM"] + }; + this.defaultDate = nowDate.getFullYear() + "-" + padTime(nowMonth) + "-" + padTime(nowDate.getDate()) + "T" + padTime(nowDate.getHours()) + ":" + padTime(nowDate.getMinutes()); this.combinedImagesArray = []; __.each(hashArray, function(hash){ @@ -156,11 +167,14 @@ module.exports = baseVw.extend({ __.each(countryList, function(countryFromList, i){ shipsTo.append(''); }); + shipsTo.val('ALL'); +/* var shipsToValue = this.model.get('vendor_offer').listing.shipping.shipping_regions; //if shipsToValue is empty, set it to the user's country shipsToValue = shipsToValue.length > 0 ? shipsToValue : this.model.get('userCountry'); shipsTo.val(shipsToValue); + */ var keywordTags = this.model.get('vendor_offer').listing.item.keywords; keywordTags = keywordTags ? keywordTags.filter(Boolean) : []; @@ -222,6 +236,12 @@ module.exports = baseVw.extend({ } }, + selectRegions: function(e){ + var setCountries = this.regions[$(e.target).data('region')]; + this.$('#shipsTo').val(setCountries); + this.$('.chosen').trigger('chosen:updated'); + }, + addDefaultTime: function(e){ "use strict"; var timeInput = this.$el.find('#inputExpirationDate'), From a52571f10066e3c31208ae6eab03fd3519f1c1c6 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Tue, 8 Mar 2016 13:46:05 -0500 Subject: [PATCH 05/12] wire up worldwide selection logic --- js/views/itemEditVw.js | 50 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/js/views/itemEditVw.js b/js/views/itemEditVw.js index 2d9a26e39..59c7b4cfd 100644 --- a/js/views/itemEditVw.js +++ b/js/views/itemEditVw.js @@ -59,6 +59,8 @@ module.exports = baseVw.extend({ "SLOVAKIA", "SLOVENIA", "SPAIN", "SWEDEN", "UNITED_KINGDOM"] }; + this.prevShipsToVal = []; + this.defaultDate = nowDate.getFullYear() + "-" + padTime(nowMonth) + "-" + padTime(nowDate.getDate()) + "T" + padTime(nowDate.getHours()) + ":" + padTime(nowDate.getMinutes()); this.combinedImagesArray = []; __.each(hashArray, function(hash){ @@ -80,7 +82,6 @@ module.exports = baseVw.extend({ var context = __.extend({}, self.model.toJSON(), { MAX_PHOTOS: self.MAX_PHOTOS }); self.$el.html(loadedTemplate(context)); - self.setFormValues(); self.$photosModule = self.$('.js-photosModule'); @@ -121,8 +122,12 @@ module.exports = baseVw.extend({ editor.subscribe('blur', self.validateDescription); //set chosen inputs - this.$('.chosen').chosen({width: '100%'}); + this.$('.chosen').chosen({width: '100%'}).change(function(e){ + self.shipsToChange(e); + }); }, 0); + + self.setFormValues(); }); return this; @@ -168,6 +173,8 @@ module.exports = baseVw.extend({ shipsTo.append(''); }); shipsTo.val('ALL'); + this.prevShipsToVal = ['ALL']; + this.$('.chosen').trigger('chosen:updated'); /* var shipsToValue = this.model.get('vendor_offer').listing.shipping.shipping_regions; @@ -237,9 +244,19 @@ module.exports = baseVw.extend({ }, selectRegions: function(e){ - var setCountries = this.regions[$(e.target).data('region')]; - this.$('#shipsTo').val(setCountries); + var setCountries = this.regions[$(e.target).data('region')], + shipsTo = this.$('#shipsTo'), + oldVal = shipsTo.val(), + wwIndex = oldVal.indexOf('ALL'), + newVal; + + if(wwIndex > -1){ + oldVal.splice(wwIndex, 1) + } + newVal = __.union(oldVal, setCountries); + this.$('#shipsTo').val(newVal); this.$('.chosen').trigger('chosen:updated'); + this.prevShipsToVal = newVal; }, addDefaultTime: function(e){ @@ -252,6 +269,26 @@ module.exports = baseVw.extend({ this.$el.find('.js-itemEditClearDateWrapper').removeClass('hide'); }, + shipsToChange: function(e){ + var newVal = $(e.target).val() || [], + newSelection = __.difference(newVal, this.prevShipsToVal), + wwNewIndex = newVal.indexOf('ALL'); + + //is the new value different from ALL? + if(newSelection[0] != "ALL"){ + //if ALL was selected, remove it + if(wwNewIndex > -1){ + newVal.splice(wwNewIndex, 1); + } + } else { + //if the new value ALL, remove everything else + newVal = ["ALL"]; + } + $(e.target).val(newVal); + this.$('.chosen').trigger('chosen:updated'); + this.prevShipsToVal = newVal; + }, + clearDate: function(){ "use strict"; this.$el.find('#inputExpirationDate').val(''); @@ -305,7 +342,7 @@ module.exports = baseVw.extend({ if (!imageFiles.length) return; - imageCount = imageFiles.length + imageCount = imageFiles.length; __.each(imageFiles, function(imageFile, i){ var newImage = document.createElement("img"), @@ -473,8 +510,7 @@ module.exports = baseVw.extend({ keywordsArray = keywordsArray.map(function(tag){ var re = /#/g; - var newTag = tag.replace(re, ''); - return newTag; + return tag.replace(re, ''); }); if(this.noShipping){ From 4e037273cff93fcf3c94d4b884f7dcdff12cbe81 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Tue, 8 Mar 2016 17:19:38 -0500 Subject: [PATCH 06/12] buying flow - handle ALL location in item model - fix formatting on long list of shippable countries in buying flow - show all addresses as ok if shipping is ALL - close modal when purchase page link is clicked - fix formatting on country of origin and other info - don't show United States as country of origin if it was not set. - create human-readable country of origin - if no country of origin is set (digital or service), use the country from the user model - show tooltip if country of origin is too long - stop the purchase ajax call if a new one is made, or if the modal is closed - set ships_to to NA if the product is digital or service --- css/obBase.css | 11 +++ js/models/itemMd.js | 33 ++++++--- js/templates/buyAddresses.html | 117 +++++++++++++++-------------- js/templates/buyDetails.html | 2 +- js/templates/item.html | 130 ++++++++++++++++----------------- js/views/buyAddressesVw.js | 4 +- js/views/buyDetailsVw.js | 8 +- js/views/buyWizardVw.js | 15 +++- js/views/itemEditVw.js | 8 +- js/views/itemVw.js | 4 +- js/views/settingsVw.js | 1 - 11 files changed, 185 insertions(+), 148 deletions(-) diff --git a/css/obBase.css b/css/obBase.css index b511f7e72..1efb9466d 100644 --- a/css/obBase.css +++ b/css/obBase.css @@ -520,6 +520,12 @@ form { box-shadow: 0px 0px 37px -10px rgb(0, 0, 0); } +/* if itemImg is nested, do not show box shadow */ +.userPage-subViews .gridItem:hover .itemImg .itemImg, +.homeView .gridItem:hover .itemImg .itemImg { + box-shadow: none; +} + .userPage-subViews .gridItem .itemImg:active, .homeView .gridItem .itemImg:active { box-shadow: 0px 0px 67px -10px rgb(0, 0, 0); @@ -5106,6 +5112,7 @@ input[type="checkbox"].fieldItem:checked + label .togLabelOff { #ov1 .width100 { width: 100%; + max-width: 100%; box-sizing: border-box; } @@ -5290,6 +5297,10 @@ input[type="checkbox"].fieldItem:checked + label .togLabelOff { display: inline-block; } +#ov1 .zIndex1 { + z-index: 1; /*use on absolutely positioned elemenets that need to stack above other elements with no z-index */ +} + #ov1 .zIndex4 { z-index: 4; } diff --git a/js/models/itemMd.js b/js/models/itemMd.js index c979ed600..c99358f87 100644 --- a/js/models/itemMd.js +++ b/js/models/itemMd.js @@ -33,13 +33,13 @@ module.exports = window.Backbone.Model.extend({ "listing": { "shipping": { "shipping_regions": [ - "UNITED_STATES" + "" ], "est_delivery": { - "international": "N/A", - "domestic": "3-5 Business Days" + "international": "", + "domestic": "" }, - "shipping_origin": "UNITED_STATES", + "shipping_origin": "", "flat_fee": { "fiat": { "price": { @@ -52,16 +52,16 @@ module.exports = window.Backbone.Model.extend({ }, "item": { "category": "", - "sku": "0", + "sku": "", "description": "", "price_per_unit": { "fiat": { "price": 0, - "currency_code": "usd" + "currency_code": "" } }, "title": "", - "process_time": "0", + "process_time": "", "image_hashes": [], "nsfw": false, "keywords": [], @@ -123,13 +123,13 @@ module.exports = window.Backbone.Model.extend({ if(!response.vendor_offer.listing.shipping){ response.vendor_offer.listing.shipping = { "shipping_regions": [ - "UNITED_STATES" + "" ], "est_delivery": { "international": "", "domestic": "" }, - "shipping_origin": "UNITED_STATES", + "shipping_origin": "", "flat_fee": { "fiat": { "price": { @@ -177,6 +177,13 @@ module.exports = window.Backbone.Model.extend({ //add pretty country names to shipping regions response.vendor_offer.listing.shipping.shipping_regionsDisplay = []; __.each(response.vendor_offer.listing.shipping.shipping_regions, function(region, i){ + if(region == "ALL"){ + response.vendor_offer.listing.shipping.shipping_regionsDisplay = [window.polyglot.t('WorldwideShipping')]; + response.worldwide = true; + return; + } else { + response.worldwide = false; + } var matchedCountry = self.countryArray.filter(function(value){ return value.dataName == region; }); @@ -186,6 +193,14 @@ module.exports = window.Backbone.Model.extend({ }); + //find the human readable name for the country of origin + if(response.vendor_offer.listing.shipping && response.vendor_offer.listing.shipping.shipping_origin) { + var matchedCountry = self.countryArray.filter(function (value) { + return value.dataName == response.vendor_offer.listing.shipping.shipping_origin; + }); + response.displayShippingOrigin = matchedCountry[0] ? matchedCountry[0].name : ""; + } + //unescape any html response.vendor_offer.listing.item.description = __.unescape(response.vendor_offer.listing.item.description); diff --git a/js/templates/buyAddresses.html b/js/templates/buyAddresses.html index 0d1eb387e..1801c82de 100644 --- a/js/templates/buyAddresses.html +++ b/js/templates/buyAddresses.html @@ -1,75 +1,72 @@
-
+
- <%= polyglot.t('buyFlow.VendorShipsTo') %>: + <%= polyglot.t('buyFlow.VendorShipsTo') %>: <%= ob.shipsToList %>
-<% if(ob.user.shipping_addresses.length < 1) { %> - -<% } else { %> <% _.each(ob.user.shipping_addresses, function(address, i){ %> -<% if(address.city && address.country && address.displayCountry && address.name && address.postal_code && address.state && address.street && ob.vendor_offer.listing.shipping.shipping_regions.indexOf(address.country) > -1) { %> -
- checked<% } %>/> -
-<% } %> + <% } %> + <% } %> <% });%> - <% _.each(ob.user.shipping_addresses, function(address, i){ %> -<% if(address.city && address.country && address.displayCountry && address.name && address.postal_code && address.state && address.street && ob.vendor_offer.listing.shipping.shipping_regions.indexOf(address.country) < 0) { %> -
- -
diff --git a/js/templates/item.html b/js/templates/item.html index 0e01e3c72..ca1ead9ea 100644 --- a/js/templates/item.html +++ b/js/templates/item.html @@ -1,29 +1,29 @@ -
-
- <%= polyglot.t('AllListings') %> - <% if(ob.vendor_offer.listing.item.category) { %> - - <%= ob.vendor_offer.listing.item.category %> - <% } %> -
-
- -
+
+
+ <%= polyglot.t('AllListings') %> + <% if(ob.vendor_offer.listing.item.category) { %> + + <%= ob.vendor_offer.listing.item.category %> + <% } %>
-

<%= ob.vendor_offer.listing.item.title %>

- +
-
-
-
-
-
- <% if(ob.vendor_offer.listing.item.image_hashes[0]) { %> - - <% } %> +
+
+

<%= ob.vendor_offer.listing.item.title %>

+ + +
+
+
+
+ <% if(ob.vendor_offer.listing.item.image_hashes[0]) { %> + + <% } %> +
<% _.each(ob.vendor_offer.listing.item.image_hashes, function(data, i) { if(i != 0){%> @@ -59,58 +59,56 @@

- - - <% if(ob.vendor_offer.listing.shipping.shipping_origin) { %> -
-
-
<%= ob.vendor_offer.listing.shipping.shipping_origin.replace("_", " ").toLowerCase() %>
-
- <% } %> - - - <% if(ob.vendor_offer.listing.metadata.category) { %> -
-
-
<%= ob.vendor_offer.listing.metadata.category %>
-
- <% } %> - - - - <% if(ob.vendor_offer.listing.item.condition) { %> - + +
+
+
+
+
+ <%= ob.displayShippingOrigin || ob.userCountry %> +
+
+
+ <% if(ob.vendor_offer.listing.metadata.category) { %> +
+
+
<%= ob.vendor_offer.listing.metadata.category %>
+
+ <% } %> + <% if(ob.vendor_offer.listing.item.condition) { %> +
<%= ob.vendor_offer.listing.item.condition %>
- +
<% } %> - <% if( ob.vendor_offer.listing.metadata.category === "physical good" && ob.vendor_offer.listing.shipping.free ) { %> - + <% if( ob.vendor_offer.listing.metadata.category === "physical good" && ob.vendor_offer.listing.shipping.free ) { %> +
<%= polyglot.t('FreeShipping') %>
- +
<% } %> - - - - <% if(ob.vendor_offer.listing.item.keywords != "") { %> -

<%= polyglot.t('Tags') %>

-
- <% _.each(ob.vendor_offer.listing.item.keywords, function(data, i) { - if(data.length < 100 && i < 11) { - %> - -
- #<%= data.replace(/\s+/g, '') %> -
-
- <% } }); %> +
+
+ <% if(ob.vendor_offer.listing.item.keywords != "") { %> +
+

<%= polyglot.t('Tags') %>

+
+
+ <% _.each(ob.vendor_offer.listing.item.keywords, function(data, i) { + if(data.length < 100 && i < 11) { + %> + +
+ #<%= data.replace(/\s+/g, '') %> +
+
+ <% } }); %> +
+ <% } %> +
- <% } %>

diff --git a/js/views/buyAddressesVw.js b/js/views/buyAddressesVw.js index 256b904a7..ef44fea19 100644 --- a/js/views/buyAddressesVw.js +++ b/js/views/buyAddressesVw.js @@ -18,7 +18,7 @@ module.exports = Backbone.View.extend({ this.userModel = options.userModel; //don't render on init, let parent trigger the render //add list of countries the vendor ships to - this.model.set('shipsToList', (this.model.get('vendor_offer').listing.shipping.shipping_regionsDisplay).join(",")); + this.model.set('shipsToList', (this.model.get('vendor_offer').listing.shipping.shipping_regionsDisplay).join(", ")); }, render: function(selected){ @@ -48,7 +48,7 @@ module.exports = Backbone.View.extend({ setAddress: function(index){ "use strict"; var selectedAddress = this.model.get('user').shipping_addresses[index]; - if(selectedAddress && this.model.get('vendor_offer').listing.shipping.shipping_regions.indexOf(selectedAddress.country) > -1){ + if(selectedAddress){ this.trigger("setAddress", selectedAddress); } }, diff --git a/js/views/buyDetailsVw.js b/js/views/buyDetailsVw.js index 7b730f4f6..bb88a5996 100644 --- a/js/views/buyDetailsVw.js +++ b/js/views/buyDetailsVw.js @@ -8,7 +8,8 @@ Backbone.$ = $; module.exports = Backbone.View.extend({ events: { - 'change .js-buyWizardQuantity': 'changeQuantity' + 'change .js-buyWizardQuantity': 'changeQuantity', + 'click .js-goToPurchases': 'goToPurchases' }, initialize: function() { @@ -116,6 +117,11 @@ module.exports = Backbone.View.extend({ this.$el.find('#buyWizardQuantity .numberSpinnerUp, #buyWizardQuantity .numberSpinnerDown').addClass('hide'); }, + goToPurchases: function(){ + window.obEventBus.trigger('closeBuyWizard'); + Backbone.history.navigate('#transactions/purchases', {trigger:true}); + }, + close: function(){ __.each(this.subViews, function(subView) { if(subView.close){ diff --git a/js/views/buyWizardVw.js b/js/views/buyWizardVw.js index 48aa5b029..ba1f15be6 100644 --- a/js/views/buyWizardVw.js +++ b/js/views/buyWizardVw.js @@ -86,6 +86,7 @@ module.exports = Backbone.View.extend({ this.listenTo(window.obEventBus, "socketMessageReceived", function(response){ this.handleSocketMessage(response); }); + this.listenTo(window.obEventBus, "closeBuyWizard", this.closeWizard); //make sure the model has a fresh copy of the user this.model.set('user', this.userModel.attributes); @@ -436,6 +437,9 @@ module.exports = Backbone.View.extend({ return; } + this.$el.find('.js-buyWizardSendPurchase').addClass('hide'); + this.$el.find('.js-buyWizardPendingMsg').removeClass('hide'); + formData.append("id", this.model.get('id')); formData.append("quantity", this.$el.find('.js-buyWizardQuantity').val()); @@ -456,7 +460,11 @@ module.exports = Backbone.View.extend({ formData.append("refund_address", bitCoinReturnAddr); - $.ajax({ + if(this.buyRequest){ + this.buyRequest.abort(); + } + + this.buyRequest = $.ajax({ type: "POST", url: self.model.get('serverUrl') + "purchase_contract", contentType: false, @@ -495,8 +503,6 @@ module.exports = Backbone.View.extend({ payHREF = "bitcoin:"+ data.payment_address+"?amount="+totalBTCPrice+"&label="+storeName+"&message="+message; this.hideMaps(); this.$el.find('.js-buyWizardPay').removeClass('hide'); - this.$el.find('.js-buyWizardSendPurchase').addClass('hide'); - this.$el.find('.js-buyWizardPendingMsg').removeClass('hide'); dataURI = qr(payHREF, {type: 10, size: 10, level: 'M'}); this.$el.find('.js-buyWizardPayQRCode').attr('src', dataURI); this.$el.find('.js-buyWizardPayPrice').text(); @@ -616,6 +622,9 @@ module.exports = Backbone.View.extend({ }); this.unbind(); this.remove(); + if(this.buyRequest){ + this.buyRequest.abort(); + } } }); \ No newline at end of file diff --git a/js/views/itemEditVw.js b/js/views/itemEditVw.js index 59c7b4cfd..9757cfe25 100644 --- a/js/views/itemEditVw.js +++ b/js/views/itemEditVw.js @@ -513,10 +513,6 @@ module.exports = baseVw.extend({ return tag.replace(re, ''); }); - if(this.noShipping){ - //do some clever stuff to insert value NA/0 if no shipping - } - this.$el.find('#inputCurrencyCode').val(cCode); this.$el.find('#inputShippingCurrencyCode').val(cCode); this.$el.find('#inputShippingOrigin').val(this.model.get('userCountry')); @@ -527,6 +523,10 @@ module.exports = baseVw.extend({ formData = new FormData(submitForm); + if(this.noShipping){ + formData.append('ships_to', 'NA'); + } + //add old and new image hashes __.each(this.model.get('imageHashesToUpload'), function(imHash){ //make sure all hashes are valid diff --git a/js/views/itemVw.js b/js/views/itemVw.js index 752945322..96e13b337 100644 --- a/js/views/itemVw.js +++ b/js/views/itemVw.js @@ -28,6 +28,7 @@ module.exports = baseVw.extend({ userModel: this is set by main.js, then by a call to the settings API. */ //don't render immediately, wait for the model to update itself with converted prices + this.userModel = options.userModel; this.listenTo(this.model, 'change:priceSet', this.onPriceSet); this.subViews = []; this.subModels = []; @@ -96,7 +97,8 @@ module.exports = baseVw.extend({ avgRating: self.getAverageRating(), starsTemplate: starsTemplate, activeTab: self.activeTab, - fetchingRatings: self.fetchingRatings + fetchingRatings: self.fetchingRatings, + userCountry: self.userModel.get('displayCountry') }) ) ); diff --git a/js/views/settingsVw.js b/js/views/settingsVw.js index f1edc4998..c1584d5c8 100644 --- a/js/views/settingsVw.js +++ b/js/views/settingsVw.js @@ -384,7 +384,6 @@ module.exports = Backbone.View.extend({ currecyList = __.uniq(currecyList, function(item){return item.code;}); currecyList = currecyList.sort(function(a,b){ - console.log(a.name + " " + b.name) var cA = a.currency.toLowerCase(), cB = b.currency.toLowerCase(); if (cA < cB){ From 19c3255a1b7845796586e70b7ad5ddfc805dfe23 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Tue, 8 Mar 2016 17:29:05 -0500 Subject: [PATCH 07/12] disable back button immediately --- js/views/buyWizardVw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/views/buyWizardVw.js b/js/views/buyWizardVw.js index ba1f15be6..ab02ee149 100644 --- a/js/views/buyWizardVw.js +++ b/js/views/buyWizardVw.js @@ -439,6 +439,7 @@ module.exports = Backbone.View.extend({ this.$el.find('.js-buyWizardSendPurchase').addClass('hide'); this.$el.find('.js-buyWizardPendingMsg').removeClass('hide'); + this.$el.find('.js-buyWizardPurchaseBack').addClass('disabled'); formData.append("id", this.model.get('id')); @@ -512,7 +513,6 @@ module.exports = Backbone.View.extend({ var extUrl = payHREF; require("shell").openExternal(extUrl); }); - this.$el.find('.js-buyWizardPurchaseBack').addClass('disabled'); this.buyDetailsView.lockForm(); }, From 1c021309a32f70919d464b57e63f01da08966b79 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Tue, 8 Mar 2016 18:32:13 -0500 Subject: [PATCH 08/12] fix ship_to when editing - fixes value of ships_to when editing - better error message - removes bad default values - error checks the ships_to value - doesn't allow blank values in descriptions due to stupid Medium-Editor empty tags --- js/models/itemMd.js | 8 ++------ js/templates/itemEdit.html | 19 ++++++++++++++----- js/utils/validateMediumEditor.js | 7 +++++-- js/views/itemEditVw.js | 28 +++++++++++++++++++--------- js/views/userPageVw.js | 8 +++----- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/js/models/itemMd.js b/js/models/itemMd.js index c99358f87..4b3ee9ee4 100644 --- a/js/models/itemMd.js +++ b/js/models/itemMd.js @@ -32,9 +32,7 @@ module.exports = window.Backbone.Model.extend({ "signature": "", "listing": { "shipping": { - "shipping_regions": [ - "" - ], + "shipping_regions": [], "est_delivery": { "international": "", "domestic": "" @@ -122,9 +120,7 @@ module.exports = window.Backbone.Model.extend({ //if the shipping section is not returned it breaks the edit template. Restore it here if(!response.vendor_offer.listing.shipping){ response.vendor_offer.listing.shipping = { - "shipping_regions": [ - "" - ], + "shipping_regions": [], "est_delivery": { "international": "", "domestic": "" diff --git a/js/templates/itemEdit.html b/js/templates/itemEdit.html index 4faef8831..aeaea3443 100644 --- a/js/templates/itemEdit.html +++ b/js/templates/itemEdit.html @@ -211,7 +211,7 @@
<%= polyglot.t('Shipping') %>
-
+
@@ -239,8 +239,8 @@
<%= polyglot.t('Shipping') %>
- - + + <%= polyglot.t('Shipping') %>
- +
@@ -282,7 +287,11 @@
<%= polyglot.t('Shipping') %>
- +
diff --git a/js/utils/validateMediumEditor.js b/js/utils/validateMediumEditor.js index 11ba95720..2f2d98cfa 100644 --- a/js/utils/validateMediumEditor.js +++ b/js/utils/validateMediumEditor.js @@ -2,7 +2,7 @@ var sanitizeHTML = require('sanitize-html'); function checkVal($field) { var fVal = $field.val().trim(); - if (!fVal.length || fVal == "

 

" || fVal == " ") { + if (!fVal.length || fVal == "

 

" || fVal == " " || fVal == "


") { $field.val(''); } @@ -10,7 +10,10 @@ function checkVal($field) { fVal = fVal.replace(/\\([\s\S])|(")/g, "'"); fVal = sanitizeHTML(fVal, { - allowedTags: [ 'h2','h3', 'h4', 'h5', 'h6', 'p', 'a','u','ul', 'ol', 'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'hr', 'br', 'img', 'blockquote' ] + allowedTags: [ 'h2','h3', 'h4', 'h5', 'h6', 'p', 'a','u','ul', 'ol', 'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'hr', 'br', 'img', 'blockquote' ], + exclusiveFilter: function(frame) { + return frame.tag === 'p' && !frame.text.trim(); + } }); $field.val(fVal); diff --git a/js/views/itemEditVw.js b/js/views/itemEditVw.js index 9757cfe25..47791029b 100644 --- a/js/views/itemEditVw.js +++ b/js/views/itemEditVw.js @@ -104,6 +104,8 @@ module.exports = baseVw.extend({ imageDragging: false, sticky: true }, + disableDoubleReturn: true, + disableExtraSpaces: true, paste: { cleanPastedHTML: true, cleanReplacements: [ @@ -172,16 +174,14 @@ module.exports = baseVw.extend({ __.each(countryList, function(countryFromList, i){ shipsTo.append(''); }); - shipsTo.val('ALL'); - this.prevShipsToVal = ['ALL']; - this.$('.chosen').trigger('chosen:updated'); -/* var shipsToValue = this.model.get('vendor_offer').listing.shipping.shipping_regions; //if shipsToValue is empty, set it to the user's country - shipsToValue = shipsToValue.length > 0 ? shipsToValue : this.model.get('userCountry'); + shipsToValue = shipsToValue.length > 0 ? shipsToValue : ["ALL"]; shipsTo.val(shipsToValue); - */ + this.prevShipsToVal = shipsToValue; + this.$('.chosen').trigger('chosen:updated'); + var keywordTags = this.model.get('vendor_offer').listing.item.keywords; keywordTags = keywordTags ? keywordTags.filter(Boolean) : []; @@ -287,6 +287,7 @@ module.exports = baseVw.extend({ $(e.target).val(newVal); this.$('.chosen').trigger('chosen:updated'); this.prevShipsToVal = newVal; + this.$('.js-shipToWrapper').removeClass('invalid'); }, clearDate: function(){ @@ -506,7 +507,8 @@ module.exports = baseVw.extend({ //deleteThisItem, cCode = this.model.get('userCurrencyCode'), submitForm = this.$el.find('#contractForm')[0], - keywordsArray = this.inputKeyword.getTagValues(); + keywordsArray = this.inputKeyword.getTagValues(), + shipsToInput = this.$('#shipsTo'); keywordsArray = keywordsArray.map(function(tag){ var re = /#/g; @@ -520,13 +522,20 @@ module.exports = baseVw.extend({ this.$el.find('#inputPrice').val(this.$el.find('#priceLocal').val()); this.$el.find('#inputShippingDomestic').val(this.$el.find('#shippingPriceLocalLocal').val()); this.$el.find('#inputShippingInternational').val(this.$el.find('#shippingPriceInternationalLocal').val()); - + formData = new FormData(submitForm); if(this.noShipping){ formData.append('ships_to', 'NA'); } + //make sure a ships to value is entered + if(!shipsToInput.val() && !this.noShipping){ + this.$('.js-shipToWrapper').addClass('invalid'); + messageModal.show(window.polyglot.t('errorMessages.saveError'), window.polyglot.t('errorMessages.missingError') + "
"+ invalidInputList+""); + return + } + //add old and new image hashes __.each(this.model.get('imageHashesToUpload'), function(imHash){ //make sure all hashes are valid @@ -601,7 +610,8 @@ module.exports = baseVw.extend({ var invalidInputList = ""; $(submitForm).find('input, textarea').each(function() { if($(this).is(":invalid")){ - invalidInputList += "
"+$(this).attr('id'); + var inputName = $("label[for='"+$(this).attr('id')+"']").text() || $(this).attr('id'); + invalidInputList += "
"+inputName; } }); messageModal.show(window.polyglot.t('errorMessages.saveError'), window.polyglot.t('errorMessages.missingError') + "
"+ invalidInputList+""); diff --git a/js/views/userPageVw.js b/js/views/userPageVw.js index 57d50e94b..aca6c0397 100644 --- a/js/views/userPageVw.js +++ b/js/views/userPageVw.js @@ -26,14 +26,12 @@ var defaultItem = { "signature": "", "listing": { "shipping": { - "shipping_regions": [ - "UNITED_STATES" - ], + "shipping_regions": [], "est_delivery": { "international": "", "domestic": "" }, - "shipping_origin": "UNITED_STATES", + "shipping_origin": "", "flat_fee": { "fiat": { "price": { @@ -51,7 +49,7 @@ var defaultItem = { "price_per_unit": { "fiat": { "price": "", - "currency_code": "usd" + "currency_code": "" } }, "title": "", From 3c4a3d623641e63ce691e66f8fecb0e4965f7cb2 Mon Sep 17 00:00:00 2001 From: Josh Jeffryes Date: Wed, 9 Mar 2016 12:14:36 -0500 Subject: [PATCH 09/12] fix wrong address getting auto-selected --- js/templates/buyAddresses.html | 7 +++++-- js/views/buyAddressesVw.js | 5 +++-- js/views/itemEditVw.js | 4 +--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/js/templates/buyAddresses.html b/js/templates/buyAddresses.html index 1801c82de..0f8e62a34 100644 --- a/js/templates/buyAddresses.html +++ b/js/templates/buyAddresses.html @@ -12,7 +12,10 @@ <% if(address.city && address.country && address.displayCountry && address.name && address.postal_code && address.state && address.street) { %> <% if(ob.worldwide || ob.vendor_offer.listing.shipping.shipping_regions.indexOf(address.country) > -1){ %>
- checked<% } %>/> + checked<% } %> />