Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit edb0eb9

Browse files
committed
more progress
1 parent 32e49dc commit edb0eb9

File tree

10 files changed

+108
-49
lines changed

10 files changed

+108
-49
lines changed

js/models/orderMd.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ module.exports = window.Backbone.Model.extend({
104104
response.dispute_resolution.resolution.vendor_payout = response.dispute_resolution.resolution.vendor_payout || 0;
105105
}
106106

107-
response.serverUrl = this.serverUrl;
108-
response.bitcoinValidationRegex = config.bitcoinValidationRegex;
109-
response.transactionType = this.transactionType;
110-
response.userGuid = this.userGuid;
107+
//response.serverUrl = this.serverUrl;
108+
//response.bitcoinValidationRegex = config.bitcoinValidationRegex;
109+
//response.transactionType = this.transactionType;
110+
//response.userGuid = this.userGuid;
111111

112112
response.vendorAvatarURL = localStorage.getItem('userAvatar-'+response.vendor_offer.listing.id.guid);
113113
response.buyerAvatarURL = localStorage.getItem('userAvatar-'+response.buyer_order.order.id.guid);
@@ -203,12 +203,12 @@ module.exports = window.Backbone.Model.extend({
203203
initialize: function(options){
204204
this.userCurrencyCode = options.cCode;
205205
this.userBTCAve = options.btAve;
206-
this.serverUrl = options.serverUrl;
207-
this.transactionType = options.transactionType;
206+
//this.serverUrl = options.serverUrl;
207+
//this.transactionType = options.transactionType;
208208
//this.countries = new countriesMd();
209209
//this.countryArray = this.countries.get('countries');
210-
this.avatarURL = options.avatarURL;
211-
this.userGuid = options.userGuid;
210+
//this.avatarURL = options.avatarURL;
211+
//this.userGuid = options.userGuid;
212212
}
213213

214214
});

js/models/orderShortMd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module.exports = window.Backbone.Model.extend({
2727
currency: response.cCode
2828
}).format(response.btc_total*response.btAve);
2929
}
30+
31+
response.unread = response.unread || 0;
3032
return response;
3133
}
3234
});

js/router.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = Backbone.Router.extend({
2929
[/^@([^\/]+)(.*)$/, "userPageViaHandle"],
3030
["userPageViaHandle", "userPageViaHandle"],
3131
["transactions", "transactions"],
32-
["transactions/:state(/:orderID)", "transactions"],
32+
["transactions/:state(/:orderID)(/:tabState)", "transactions"],
3333
["settings", "settings"],
3434
["settings/:state", "settings"]
3535
];
@@ -315,14 +315,15 @@ module.exports = Backbone.Router.extend({
315315
});
316316
},
317317

318-
transactions: function(state, orderID){
318+
transactions: function(state, orderID, tabState){
319319
"use strict";
320320
this.newView(new transactionsView({
321321
userModel: this.userModel,
322322
userProfile: this.userProfile,
323323
socketView: this.socketView,
324324
state: state,
325-
orderID: orderID
325+
orderID: orderID,
326+
tabState: tabState //opens a tab in the order modal
326327
}),"userPage");
327328
},
328329

js/templates/orderShort.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,24 @@
5959
<div class="btn btn-txt height36 custCol-secondary js-orderShort marginBottom5 width100">
6060
<%= polyglot.t('transactions.OrderDetails') %>
6161
</div>
62-
<% if(ob.transactionType == "purchase" && ob.status == 0){ %>
62+
<div class="btn btn-txt height36 custCol-secondary marginBottom5 width100 positionWrapper js-orderShortDiscusson <% if(!ob.unread){ %> hide <% } %>"
63+
data-order="<%= ob.order_id %>">
64+
<i class="ion-chatbubbles"></i> <%= polyglot.t('Discussion') %>
65+
<div class="badge js-unreadBadge" data-count="<%= ob.unread || 0 %>"></div>
66+
</div>
67+
<% if(ob.transactionType == "purchases" && ob.status == 0){ %>
6368
<div class="btn btn-txt height36 custCol-secondary marginBottom5 width100 js-orderShort">
6469
<%= polyglot.t('transactions.PayPurchase') %>
6570
</div>
66-
<% } else if(ob.transactionType == "sale" && ob.status == 1){ %>
71+
<% } else if(ob.transactionType == "sales" && ob.status == 1){ %>
6772
<div class="btn btn-txt height36 custCol-secondary js-orderShortConfirm marginBottom5 width100">
6873
<% if (ob.contract_type == "digital good" || ob.contract_type == "service") { %>
6974
<%= polyglot.t('transactions.ConfirmOrder') %>
7075
<% } else { %>
7176
<%= polyglot.t('transactions.MarkAsShipped') %>
7277
<% } %>
7378
</div>
74-
<% } else if(ob.transactionType == "purchase" && ob.status == 2){ %>
79+
<% } else if(ob.transactionType == "purchases" && ob.status == 2){ %>
7580
<div class="btn btn-txt height36 custCol-secondary js-orderShortComplete marginBottom5 width100">
7681
<%= polyglot.t('transactions.CompleteOrder') %>
7782
</div>

js/templates/transactionModal.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,11 @@ <h3 class="txt-bright"><%= polyglot.t('CheckExchanges') %> </h3>
569569
<span class="ion-social-bitcoin fontSize12 marginRight2 textOpacity1"></span>
570570
<%= polyglot.t('Funds') %>
571571
</a>
572-
<a class="btn btn-bar btn-tab custCol-secondary fontSize13 js-tab js-discussionTab paddingRight18" data-tab="discussion">
572+
<a class="btn btn-bar btn-tab custCol-secondary fontSize13 js-tab js-discussionTab paddingRight18 positionWrapper" data-tab="discussion">
573573
<span class="ion-chatbubbles fontSize11 marginRight2 textOpacity1"></span>
574574
<%= polyglot.t('Discussion') %>
575575
<span class="pill fontSize12 textOpacity75 marginLeft2 js-discussionCount">0</span>
576+
<div class="badge js-unreadBadge" data-count="<%= ob.unread || 0 %>"></div>
576577
</a>
577578
</div>
578579

js/views/notificationVw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = baseVw.extend({
4646
Backbone.history.navigate('#transactions/sales/' + this.model.get('order_id'), {trigger: true});
4747
break;
4848
case "ORDER":
49-
Backbone.history.navigate('#transactions/sales/' + this.model.get('subject'), {trigger: true});
49+
Backbone.history.navigate('#transactions/sales/' + this.model.get('subject') +'/discussion', {trigger: true});
5050
break;
5151
}
5252

js/views/orderShortVw.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
var __ = require('underscore'),
24
Backbone = require('backbone'),
35
$ = require('jquery'),
@@ -12,9 +14,10 @@ module.exports = baseVw.extend({
1214
className: "flexRow custCol-border",
1315

1416
events: {
15-
'click .js-orderShort': 'openOrderModal',
17+
'click .js-orderShort': 'orderSummary',
1618
'click .js-orderShortConfirm': 'orderConfirm',
17-
'click .js-orderShortComplete': 'orderComplete'
19+
'click .js-orderShortComplete': 'orderComplete',
20+
'click .js-orderShortDiscusson': 'orderDiscussion'
1821
},
1922

2023
initialize: function(){
@@ -31,36 +34,39 @@ module.exports = baseVw.extend({
3134
return this;
3235
},
3336

34-
openOrderModal: function(e){
35-
"use strict";
36-
e.stopPropagation();
37+
openOrderModal: function(tabState){
38+
console.log("open")
3739
window.obEventBus.trigger("openOrderModal", {
3840
'orderID': this.model.get('order_id'),
3941
'status': this.model.get('status'),
40-
'transactionType': this.model.get('transactionType')
42+
'transactionType': this.model.get('transactionType'),
43+
'unread': this.model.get('unread'),
44+
'tabState': tabState
4145
});
4246
},
4347

48+
orderSummary: function(e){
49+
e.stopPropagation();
50+
this.openOrderModal("summary");
51+
},
52+
4453
orderConfirm: function(e){
45-
"use strict";
4654
e.stopPropagation();
47-
window.obEventBus.trigger("openOrderModal", {
48-
'orderID': this.model.get('order_id'),
49-
'status': this.model.get('status'),
50-
'transactionType': this.model.get('transactionType'),
51-
'tabState': "confirm"
52-
});
55+
this.openOrderModal("confirm");
5356
},
5457

5558
orderComplete: function(e){
56-
"use strict";
5759
e.stopPropagation();
58-
window.obEventBus.trigger("openOrderModal", {
59-
'orderID': this.model.get('order_id'),
60-
'status': this.model.get('status'),
61-
'transactionType': this.model.get('transactionType'),
62-
'tabState': "complete"
63-
});
60+
this.openOrderModal("complete");
61+
},
62+
63+
orderDiscussion: function(e){
64+
e.stopPropagation();
65+
this.openOrderModal("discussion");
66+
},
67+
68+
updateUnread: function(changeBy){
69+
this.model.set('unread', this.model.get('unread') + parseInt(changeBy, 10));
6470
}
6571

6672
});

js/views/pageNavVw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module.exports = baseVw.extend({
167167

168168
if (data.hasOwnProperty('notification') || data.hasOwnProperty('message') && data.message.subject) {
169169
notif = data.notification || data.message;
170-
username = notif.handle ? notif.handle : notif.guid.substring(0,10) + '...';
170+
username = notif.handle ? notif.handle : notif.sender.substring(0,10) + '...';
171171
avatarHash = notif.image_hash || notif.avatar_hash;
172172
avatar = avatarHash ? app.serverConfigs.getActive().getServerBaseUrl + '/get_image?hash=' +
173173
avatarHash + '&guid=' + notif.guid : 'imgs/defaultUser.png';

js/views/transactionModalVw.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module.exports = baseVw.extend({
7070
this.orderID = options.orderID;
7171
this.status = options.status;
7272
this.transactionType = options.transactionType;
73+
this.unread = options.unread;
7374
this.parentEl = options.parentEl;
7475
this.countriesArray = options.countriesArray;
7576
this.cCode = options.cCode;
@@ -96,12 +97,12 @@ module.exports = baseVw.extend({
9697
this.model = new orderModel({
9798
cCode: this.cCode,
9899
btAve: this.btAve,
99-
serverUrl: this.serverUrl,
100-
transactionType: this.transactionType,
101-
avatarURL: this.avatarURL,
102-
avatar_hash: this.userProfile.get('avatar_hash'),
103-
orderID: this.orderID,
104-
userGuid: this.userModel.get('guid')
100+
//serverUrl: this.serverUrl,
101+
//transactionType: this.transactionType,
102+
//avatarURL: this.avatarURL,
103+
//avatar_hash: this.userProfile.get('avatar_hash'),
104+
//orderID: this.orderID,
105+
//userGuid: this.userModel.get('guid')
105106
});
106107
this.model.urlRoot = options.serverUrl + "get_order";
107108
this.listenTo(this.model, 'change:priceSet', this.render);
@@ -145,7 +146,7 @@ module.exports = baseVw.extend({
145146
render: function () {
146147
var self = this;
147148
$('.js-loadingModal').addClass("hide");
148-
this.model.set('status', this.status);
149+
//this.model.set('status', this.status);
149150
//makde sure data is valid
150151
if(this.model.get('invalidData')){
151152
messageModal.show(window.polyglot.t('errorMessages.serverError', self.model.get('error')));
@@ -155,7 +156,15 @@ module.exports = baseVw.extend({
155156
loadTemplate('./js/templates/transactionModal.html', function(loadedTemplate) {
156157
//hide the modal when it first loads
157158
self.parentEl.html(self.$el);
158-
self.$el.html(loadedTemplate(self.model.toJSON()));
159+
self.$el.html(loadedTemplate(__.extend({}, self.model.toJSON(), {
160+
unread: self.unread,
161+
serverUrl: self.serverUrl,
162+
bitcoinValidationRegex: config.bitcoinValidationRegex,
163+
transactionType: self.transactionType,
164+
userGuid: self.userModel.get('guid'),
165+
status: self.status
166+
})
167+
));
159168
// add blur to container
160169
$('#obContainer').addClass('blur');
161170
self.delegateEvents(); //reapply events if this is a second render
@@ -269,6 +278,10 @@ module.exports = baseVw.extend({
269278
this.$el.find('.js-tab').removeClass('active');
270279
this.$el.find('.js-' + state).removeClass('hide');
271280
this.$el.find('.js-' + state + 'Tab').addClass('active').removeClass('hide');
281+
282+
if(state == "discussion"){
283+
$.post(app.serverConfigs.getActive().getServerBaseUrl() + '/mark_discussion_as_read', {id: this.orderID});
284+
}
272285

273286
if(state == "discussion" && this.discussionScroller){
274287
this.discussionScroller[0].scrollTop = this.discussionScroller[0].scrollHeight;

js/views/transactionsVw.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports = baseVw.extend({
4242
this.options = options;
4343
this.state = options.state || "purchases";
4444
this.orderID = options.orderID;
45+
this.tabState = options.tabState;
4546
this.userModel = options.userModel;
4647
this.userProfile = options.userProfile;
4748
this.model = new Backbone.Model();
@@ -51,8 +52,8 @@ module.exports = baseVw.extend({
5152
setTheme(profile.primary_color, profile.secondary_color, profile.background_color, profile.text_color);
5253
this.serverUrl = options.userModel.get('serverUrl');
5354
this.cCode = options.userModel.get('currency_code');
54-
this.listenTo(window.obEventBus, "openOrderModal", function(orderID){
55-
self.openOrderModal(orderID);
55+
this.listenTo(window.obEventBus, "openOrderModal", function(options){
56+
self.openOrderModal(options);
5657
});
5758
this.searchTransactions;
5859
this.filterBy; //used for filtering the collections
@@ -140,7 +141,8 @@ module.exports = baseVw.extend({
140141
self.openOrderModal({
141142
'orderID': self.orderID,
142143
'status': orderModel.get('status'),
143-
'transactionType': tType
144+
'transactionType': tType,
145+
'tabState': self.tabState
144146
});
145147
}
146148
}
@@ -163,10 +165,38 @@ module.exports = baseVw.extend({
163165
});
164166
},
165167

168+
findOrderByID: function(orderID){
169+
var orderModelP = this.purchasesCol.findWhere({ order_id: this.orderID}),
170+
orderModelS = this.salesCol.findWhere({ order_id: this.orderID}),
171+
orderModelC = this.casesCol.findWhere({ order_id: this.orderID}),
172+
orderModel = orderModelP || orderModelS || orderModelC;
173+
174+
if(orderModelP){
175+
tType = "purchases";
176+
self.setState('purchases', self.orderID)
177+
} else if(orderModelS){
178+
tType = "sales";
179+
self.setState('sales', self.orderID)
180+
} else if(orderModelC){
181+
tType = "cases";
182+
self.setState('cases', self.orderID)
183+
}
184+
185+
//don't forget to make this part work to get the model when the socket message comes in
186+
return orderModel;
187+
},
188+
166189
handleSocketMessage: function(response) {
167190
var data = JSON.parse(response.data);
168191
if(data.notification && data.notification.order_id){
169192
this.getData();
193+
} else if(data.message && data.message.subject){
194+
//increment the unread count of the order with the message
195+
var orderShortDiscBtn = this.$('.js-orderShortDiscusson[data-order="'+ data.message.subject +'"]');
196+
var orderShortDiscBtnBadge = orderShortDiscBtn.find('.js-unreadBadge');
197+
orderShortDiscBtn.removeClass('hide');
198+
var newCount = Number(orderShortDiscBtnBadge.attr('data-count')) +1;
199+
orderShortDiscBtnBadge.attr('data-count', newCount);
170200
}
171201
},
172202

@@ -423,7 +453,8 @@ module.exports = baseVw.extend({
423453
transactionType: options.transactionType,
424454
userModel: this.userModel,
425455
userProfile: this.userProfile,
426-
socketView: this.socketView
456+
socketView: this.socketView,
457+
unread: options.unread
427458
});
428459
this.registerChild(orderModalView);
429460
}

0 commit comments

Comments
 (0)