ShareBuy view before and after Rivets

Created Diff never expires
62 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
71 lines
23 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
33 lines
var toCurrency = require('../templates/helpers/formatcurrency');


var ShareBuyView = Marionette.ItemView.extend({
var ShareBuyView = Marionette.ItemView.extend({
template: require('../templates/newbuy.hbs'),
template: false,
bindings: {
html: require('../templates/sharebuy.html'),
'[name=symbol]': {
observe: 'symbol',
events: ['blur']
},
'[name=price]': {
observe: 'price',
onGet: 'numToStr',
onSet: 'strToNum'
},
'[name=quantity]': {
observe: 'quantity',
onGet: 'numToStr',
onSet: 'strToNum'
},
'[name=date]': 'date'
},
initialize: function (options) {
initialize: function (options) {
this.state = new Backbone.Model();
this.state = {isNew: !this.pristineModel, hasSymbol: !!this.symbol};
this.state.set('isNew', !this.pristineModel);
if (this.state.isNew && this.symbol) {
this.state.set('hasSymbol', !!this.symbol);
if (this.state.get('isNew') && this.symbol) {
this.model.set('symbol', this.symbol.get('name'));
this.model.set('symbol', this.symbol.get('name'));
}
}
},
},
onBeforeRender: function() {
if (this.view) {
this.view.unbind();
this.view = null;
}
this.attachElContent(this.html);
this.view = rivets.bind(this.el, this);
},
onRender: function () {
onRender: function () {
this.updateMeanPrice();
this.updateMeanPrice();
this.stickit();
this.stickit(this.state, {
'#remove-buy': {
observe: 'isNew',
onGet: function (value) {
return !value
},
visible: true
},
'[name=symbol]':{
attributes: [
{
name: 'disabled',
observe: 'hasSymbol',
onGet: function (value) {
return value
}
}]
}
})
},
},
onDestroy: function() {
if (this.view) {
this.view.unbind();
this.view = null;
}
updateMeanPrice: function() {
updateMeanPrice: function() {
this.$el.find('.mean-price').text(this.symbol ? toCurrency(this.symbol.simulateMeanPrice(this.model)) : '--');
this.state.meanPrice = this.symbol ? this.symbol.simulateMeanPrice(this.model) : undefined;
this.$el.find('.current-mean-price').text(this.symbol ? toCurrency(this.symbol.meanPrice) : '--');
this.state.currentMeanPrice = this.symbol ? this.symbol.meanPrice : undefined;
},
}
strToNum: function (val) {
if (val != null) {
return +val;
}
},
numToStr: function (val) {
if (val != null) {
return val.toString();
}
}
});
});