Skip to content

Commit

Permalink
terribly ugly fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JSlote committed Aug 29, 2016
1 parent f4b5658 commit 5acd36c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 47 deletions.
20 changes: 10 additions & 10 deletions app/views/partials/main.pug
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ div#recent-listings(ng-controller="recentListingsController", ng-class="{'minimi
| Load more
span(ng-if="recentListings.length >= totalListings") That's all she wrote!

div.modal-wrapper(
ng-class="{'visible':offer.active}",
ng-htb-self-mousedown="offer.active = false"
)
div.modal.offer
h2 Make an Offer
textarea(ng-model="offer.message")
div.bottom-buttons
button.cancel(ng-click="offer.active = false") Cancel
button(ng-click="makeOffer()") Send email
div.modal-wrapper(
ng-class="{'visible':offer.active}",
ng-htb-self-mousedown="offer.active = false"
)
div.modal.offer
h2 Make an Offer
textarea(ng-model="offer.message")
div.bottom-buttons
button.cancel(ng-click="offer.active = false") Cancel
button(ng-click="makeOffer()") Send email
87 changes: 50 additions & 37 deletions public/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,52 +417,22 @@ hitsTheBooks.controller('recentListingsController',

$scope.recentListings = [];
$scope.totalListings = 0; // how many listings the backend has
$scope.offersDict = {};
$scope.offer = {
$scope.$parent.offer = {
active: false,
listing: null,
message: null
}
$scope.$watch('offers', function() {
// When offers change, update offers dict
$scope.offersDict = {};
for (var i = 0; i < $scope.offers.length; i++) {
$scope.offersDict[$scope.offers[i].listingID] = true;
};
});
$scope.$on(AUTH_EVENTS.loginSuccess,
function() {
refreshOffers();
}
);

var refreshOffers = function() {
Api.getOffers().then( function(offers) {
$scope.offers = offers;
}, function(err) {
console.log(err);
});
}
$scope.makeOfferInit = function(listing) {
$scope.offer.listing = listing;
$scope.offer.message =
"Hi "+$scope.offer.listing.user.name.fullName+",\n\n"
+ "I'm interested in [buying/renting] your copy of \""+$scope.offer.listing.book.name+".\" "
$scope.$parent.offer.listing = listing;
$scope.$parent.offer.message =
"Hi "+$scope.$parent.offer.listing.user.name.fullName+",\n\n"
+ "I'm interested in [buying/renting] your copy of \""+$scope.$parent.offer.listing.book.name+".\" "
+ "Please let me know when we could meet.\n\n"
+ "Thanks"
+ ($rootScope.currentUser ? (",\n"+$rootScope.currentUser.name.fullName) : "!")
$scope.offer.active = true;
$scope.$parent.offer.active = true;
}
$scope.makeOffer = function() {
Api.makeOffer($scope.offer.listing.listingID, $scope.offer.message)
.then( function (data) {
refreshOffers();
$scope.offer.active = false;
}, function (err) {
console.log(err);
})
}


var updateRecentListings = function() {
Api.getRecentListings({
Expand Down Expand Up @@ -511,12 +481,55 @@ hitsTheBooks.controller('recentListingsController',
}
});

hitsTheBooks.controller('mainController', function($scope, $rootScope, $stateParams, $state, $document, offers) {
hitsTheBooks.controller('mainController', function($scope, $rootScope, $stateParams, $state, $document, offers, Api, AUTH_EVENTS) {
$scope.offers = offers;
if ($stateParams.flash) {
$scope.flashMessage($stateParams.flash);
}

$scope.$on(AUTH_EVENTS.loginSuccess,
function() {
refreshOffers();
}
);

var refreshOffers = function() {
Api.getOffers().then( function(offers) {
$scope.offers = offers;
}, function(err) {
console.log(err);
});
}

$scope.offersDict = {};
var updateOffersDict = function(){
// When offers change, update offers dict
$scope.offersDict = {};
for (var i = 0; i < $scope.offers.length; i++) {
$scope.offersDict[$scope.offers[i].listingID] = true;
};
}
$scope.$watch('offers', updateOffersDict);
updateOffersDict();

$scope.makeOffer = function() {
Api.makeOffer($scope.offer.listing.listingID, $scope.offer.message)
.then( function (data) {
refreshOffers();
$scope.offer.active = false;
}, function (err) {
console.log(err);
})
}

var refreshOffers = function() {
Api.getOffers().then( function(offers) {
$scope.offers = offers;
}, function(err) {
console.log(err);
});
}

$scope.displayedSearch = 'books';
var streamSearchDelay = 250; //ms
var initSearch = false;
Expand Down

0 comments on commit 5acd36c

Please sign in to comment.