Commit 04bc285f by Vedran Karacic

Hide empty fields in coupon details view.

parent a6c44a1a
...@@ -33,6 +33,16 @@ define([ ...@@ -33,6 +33,16 @@ define([
percentageDiscountCodeVoucher = Mock_Coupons.percentageDiscountCodeVoucher; percentageDiscountCodeVoucher = Mock_Coupons.percentageDiscountCodeVoucher;
valueDiscountCodeVoucher = Mock_Coupons.valueDiscountCodeVoucher; valueDiscountCodeVoucher = Mock_Coupons.valueDiscountCodeVoucher;
verifiedSeat = Mock_Coupons.verifiedSeat; verifiedSeat = Mock_Coupons.verifiedSeat;
jasmine.addMatchers({
toExist: function () {
return {
compare: function (actual) {
return { pass: $.contains(document.documentElement, $(actual)[0]) };
}
};
}
});
}); });
it('should compare view.model with model sent', function () { it('should compare view.model with model sent', function () {
...@@ -181,8 +191,8 @@ define([ ...@@ -181,8 +191,8 @@ define([
expect(view.$('.invoice-payment-date .value').text()).toEqual( expect(view.$('.invoice-payment-date .value').text()).toEqual(
view.formatDateTime(model.get('invoice_payment_date')) view.formatDateTime(model.get('invoice_payment_date'))
); );
expect(SpecUtils.visibleElement(view, '.invoice_discount_type', '.info-item')).toBe(false); expect(view.$('.invoice_discount_type')).not.toExist();
expect(SpecUtils.visibleElement(view, '.invoice_discount_value', '.info-item')).toBe(false); expect(view.$('.invoice_discount_value')).not.toExist();
}); });
it('should render postpaid invoice data.', function() { it('should render postpaid invoice data.', function() {
...@@ -192,25 +202,24 @@ define([ ...@@ -192,25 +202,24 @@ define([
'invoice_discount_value': 50, 'invoice_discount_value': 50,
}); });
view.render(); view.render();
expect(view.$('.invoice-discount-type .value').text()).toEqual(model.get('invoice_discount_type'));
expect(view.$('.invoice-discount-value .value').text()).toEqual( expect(view.$('.invoice-discount-value .value').text()).toEqual(
view.invoiceDiscountValue( view.invoiceDiscountValue(
model.get('invoice_discount_type'), model.get('invoice_discount_type'),
model.get('invoice_discount_value') model.get('invoice_discount_value')
) )
); );
expect(SpecUtils.visibleElement(view, '.invoice-number', '.info-item')).toBe(false); expect(view.$('.invoice-number')).not.toExist();
expect(SpecUtils.visibleElement(view, '.invoiced-amount', '.info-item')).toBe(false); expect(view.$('.invoiced-amount')).not.toExist();
expect(SpecUtils.visibleElement(view, '.invoice-payment-date', '.info-item')).toBe(false); expect(view.$('.invoice-payment-date')).not.toExist();
}); });
it('should render not-applicable invoice data.', function() { it('should render not-applicable invoice data.', function() {
view.model.set('invoice_type', 'Not-Applicable'); view.model.set('invoice_type', 'Not-Applicable');
view.render(); view.render();
expect(SpecUtils.visibleElement(view, '.invoice_discount_type', '.info-item')).toBe(false); expect(view.$('.invoice_discount_type')).not.toExist();
expect(SpecUtils.visibleElement(view, '.invoice-number', '.info-item')).toBe(false); expect(view.$('.invoice-number')).not.toExist();
expect(SpecUtils.visibleElement(view, '.invoiced-amount', '.info-item')).toBe(false); expect(view.$('.invoiced-amount')).not.toExist();
expect(SpecUtils.visibleElement(view, '.invoice-payment-date', '.info-item')).toBe(false); expect(view.$('.invoice-payment-date')).not.toExist();
}); });
it('should display tax deducted source input field.', function() { it('should display tax deducted source input field.', function() {
...@@ -220,7 +229,7 @@ define([ ...@@ -220,7 +229,7 @@ define([
view.model.set('tax_deduction', 'No'); view.model.set('tax_deduction', 'No');
view.render(); view.render();
expect(SpecUtils.visibleElement(view, '.tax-deducted-source-value', '.info-item')).toBe(false); expect(view.$('.tax-deducted-source-value')).not.toExist();
}); });
it('should download voucher report in the new tab', function () { it('should download voucher report in the new tab', function () {
......
...@@ -67,7 +67,6 @@ define([ ...@@ -67,7 +67,6 @@ define([
if (invoice_payment_date) { if (invoice_payment_date) {
invoice_payment_date = this.formatDateTime(invoice_payment_date); invoice_payment_date = this.formatDateTime(invoice_payment_date);
} }
return { return {
'invoice_type': this.model.get('invoice_type'), 'invoice_type': this.model.get('invoice_type'),
'invoice_number': this.model.get('invoice_number'), 'invoice_number': this.model.get('invoice_number'),
...@@ -81,7 +80,7 @@ define([ ...@@ -81,7 +80,7 @@ define([
formatSeatTypes: function() { formatSeatTypes: function() {
var courseSeatTypes = this.model.get('course_seat_types'); var courseSeatTypes = this.model.get('course_seat_types');
if (courseSeatTypes) { if (courseSeatTypes && courseSeatTypes[0] !== '[]') {
if(courseSeatTypes.length === 1){ if(courseSeatTypes.length === 1){
return courseSeatTypes[0]; return courseSeatTypes[0];
} else { } else {
...@@ -108,7 +107,12 @@ define([ ...@@ -108,7 +107,12 @@ define([
var html, var html,
category = this.model.get('categories')[0].name, category = this.model.get('categories')[0].name,
invoice_data = this.formatInvoiceData(), invoice_data = this.formatInvoiceData(),
template_data; template_data,
price = null;
if (this.model.get('price') !== '0.00') {
price = _s.sprintf('$%s', this.model.get('price'));
}
template_data = { template_data = {
category: category, category: category,
...@@ -117,7 +121,7 @@ define([ ...@@ -117,7 +121,7 @@ define([
discountValue: this.discountValue(), discountValue: this.discountValue(),
endDateTime: this.formatDateTime(this.model.get('end_date')), endDateTime: this.formatDateTime(this.model.get('end_date')),
lastEdited: this.formatLastEditedData(this.model.get('last_edited')), lastEdited: this.formatLastEditedData(this.model.get('last_edited')),
price: _s.sprintf('$%s', this.model.get('price')), price: price,
startDateTime: this.formatDateTime(this.model.get('start_date')), startDateTime: this.formatDateTime(this.model.get('start_date')),
usage: this.usageLimitation() usage: this.usageLimitation()
}; };
...@@ -127,7 +131,6 @@ define([ ...@@ -127,7 +131,6 @@ define([
this.$el.html(html); this.$el.html(html);
this.renderCourseData(); this.renderCourseData();
this.renderInvoiceData();
this.delegateEvents(); this.delegateEvents();
this.dynamic_catalog_view = new DynamicCatalogView({ this.dynamic_catalog_view = new DynamicCatalogView({
...@@ -149,60 +152,10 @@ define([ ...@@ -149,60 +152,10 @@ define([
this.model.get('course_id'), this.model.get('course_id'),
this.model.get('seat_type')) this.model.get('seat_type'))
); );
this.$('.catalog-query').addClass('hidden');
this.$('.seat-types').addClass('hidden');
this.$('.course-info').removeClass('hidden');
} else if (this.model.get('catalog_type') === 'Multiple courses') {
this.$('.course-info').addClass('hidden');
this.$('.catalog-query').removeClass('hidden');
this.$('.seat-types').removeClass('hidden');
} }
return this; return this;
}, },
renderInvoiceData: function() {
var invoice_type = this.model.get('invoice_type'),
tax_deducted = this.model.get('tax_deduction'),
prepaid_fields = [
'.invoice-number',
'.invoiced-amount',
'.invoice-payment-date'
],
postpaid_fields = [
'.invoice-discount-type',
'.invoice-discount-value'
];
if (tax_deducted === 'Yes') {
this.$('.tax-deducted-source-value').removeClass('hidden');
} else if (tax_deducted === 'No') {
this.$('.tax-deducted-source-value').addClass('hidden');
}
if (invoice_type === 'Prepaid') {
_.each(prepaid_fields, function(field) {
this.$(field).removeClass('hidden');
}, this);
_.each(postpaid_fields, function(field) {
this.$(field).addClass('hidden');
}, this);
} else if (invoice_type === 'Postpaid') {
_.each(prepaid_fields, function(field) {
this.$(field).addClass('hidden');
}, this);
_.each(postpaid_fields, function(field) {
this.$(field).removeClass('hidden');
}, this);
} else if (invoice_type === 'Not-Applicable') {
_.each(prepaid_fields, function(field) {
this.$(field).addClass('hidden');
}, this);
_.each(postpaid_fields, function(field) {
this.$(field).addClass('hidden');
}, this);
}
},
downloadCouponReport: function (event) { downloadCouponReport: function (event) {
var url = _s.sprintf('/api/v2/coupons/coupon_reports/%d', this.model.id); var url = _s.sprintf('/api/v2/coupons/coupon_reports/%d', this.model.id);
......
<div class="container"> <div class="container">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li><a href="/coupons/"><%= gettext('Coupons') %></a></li> <li><a href="/coupons/"><%= gettext('Coupons') %></a></li>
<li class="active"><%= coupon['title'] %></li> <li class="active"><%= coupon.title %></li>
</ol> </ol>
<div class="page-header"> <div class="page-header">
<h1 class="hd-1 emphasized"> <h1 class="hd-1 emphasized">
<span class="coupon-title"><%= coupon['title'] %></span> <span class="coupon-title"><%= coupon.title %></span>
<div class="pull-right"> <div class="pull-right">
<a class="btn btn-primary btn-small" href="/coupons/<%= coupon['id'] %>/edit/" id="CouponEdit"> <a class="btn btn-primary btn-small" href="/coupons/<%= coupon.id %>/edit/" id="CouponEdit">
<%= gettext('Edit Coupon') %> <%= gettext('Edit Coupon') %>
</a> </a>
</div> </div>
</h1> </h1>
<h3 class="hd-3"> <h3 class="hd-3">
<span class="coupon-type"><%= coupon['coupon_type'] %></span> <span class="coupon-type"><%= coupon.coupon_type %></span>
</h3> </h3>
</div> </div>
<div class="coupon-information"> <div class="coupon-information">
<div class="heading"><%= gettext('Code Status:') %> <div class="heading"><%= gettext('Code Status:') %>
<span class="code-status value <% if(coupon['code_status'] == 'ACTIVE') { %>active <% } %>"><%= coupon['code_status'] %></span> <span class="code-status value <% if(coupon.code_status == 'ACTIVE') { %>active <% } %>"><%= coupon.code_status %></span>
<div class="pull-right"> <div class="pull-right">
<%= gettext('Last edit:') %> <%= gettext('Last edit:') %>
<span><%= lastEdited %></span> <span><%= lastEdited %></span>
...@@ -29,10 +29,12 @@ ...@@ -29,10 +29,12 @@
<div class="heading"><%= gettext('Category') %></div> <div class="heading"><%= gettext('Category') %></div>
<div class="value"><%= category %></div><br /> <div class="value"><%= category %></div><br />
</div> </div>
<% if(coupon.note) {%>
<div class="info-item grid-item note"> <div class="info-item grid-item note">
<div class="heading"><%= gettext('Note') %></div> <div class="heading"><%= gettext('Note') %></div>
<div class="value"><%= coupon['note'] %></div><br /> <div class="value"><%= coupon.note %></div><br />
</div> </div>
<%}%>
<div class="info-item grid-item discount-value"> <div class="info-item grid-item discount-value">
<div class="heading"><%= gettext('Discount Value:') %></div> <div class="heading"><%= gettext('Discount Value:') %></div>
<div class="value"><%= discountValue %></div> <div class="value"><%= discountValue %></div>
...@@ -40,10 +42,12 @@ ...@@ -40,10 +42,12 @@
<div class="info-item grid-item course-info"> <div class="info-item grid-item course-info">
<div class="heading"><%= gettext('Valid for courses:') %></div> <div class="heading"><%= gettext('Valid for courses:') %></div>
</div> </div>
<% if(coupon.catalog_query) {%>
<div class="info-item grid-item catalog-query"> <div class="info-item grid-item catalog-query">
<div class="heading"><%= gettext('Catalog Query:') %></div> <div class="heading"><%= gettext('Catalog Query:') %></div>
<div class="value"><%= coupon['catalog_query'] %></div> <div class="value"><%= coupon.catalog_query %></div>
</div> </div>
<%}%>
<div class="info-item grid-item date-info"> <div class="info-item grid-item date-info">
<div class="start-date-info"> <div class="start-date-info">
<div class="heading"><%= gettext('Valid from:') %></div> <div class="heading"><%= gettext('Valid from:') %></div>
...@@ -54,54 +58,64 @@ ...@@ -54,54 +58,64 @@
<div class="value"><%= endDateTime %></div> <div class="value"><%= endDateTime %></div>
</div> </div>
</div> </div>
<% if(courseSeatType) {%>
<div class="info-item grid-item seat-types"> <div class="info-item grid-item seat-types">
<div class="heading"><%= gettext('Seat Types:') %></div> <div class="heading"><%= gettext('Seat Types:') %></div>
<div class="value"><%= courseSeatType %></div> <div class="value"><%= courseSeatType %></div>
<div class="catalog_buttons"></div> <div class="catalog_buttons"></div>
</div> </div>
<%}%>
<div class="info-item grid-item usage-limitations"> <div class="info-item grid-item usage-limitations">
<div class="heading"><%= gettext('Usage Limitations:') %></div> <div class="heading"><%= gettext('Usage Limitations:') %></div>
<div class="value"><%= usage %></div> <div class="value"><%= usage %></div>
</div> </div>
<% if(coupon.max_uses) {%>
<div class="info-item grid-item max-uses"> <div class="info-item grid-item max-uses">
<div class="heading"><%= gettext('Maximum Uses:') %></div> <div class="heading"><%= gettext('Maximum Uses:') %></div>
<div class="value"><%= coupon['max_uses'] %></div> <div class="value"><%= coupon.max_uses %></div>
</div> </div>
<%}%>
<div class="info-item grid-item codes"> <div class="info-item grid-item codes">
<div class="heading"><%= gettext('Download Voucher(s):') %></div> <div class="heading"><%= gettext('Download Voucher(s):') %></div>
<a href="/<%= coupon['id'] %>/" class="btn btn-primary btn-small pull-left voucher-report-button"><%= gettext('Download') %></a> <a href="/<%= coupon.id %>/" class="btn btn-primary btn-small pull-left voucher-report-button"><%= gettext('Download') %></a>
</div> </div>
<div class="info-item grid-item client-info"> <div class="info-item grid-item client-info">
<div class="heading"><%= gettext('Client:') %></div> <div class="heading"><%= gettext('Client:') %></div>
<div class="value"><%= coupon['client'] %></div> <div class="value"><%= coupon.client %></div>
</div> </div>
<div class="info-item grid-item invoice-type"> <div class="info-item grid-item invoice-type">
<div class="heading"><%= gettext('Invoice Type:') %></div> <div class="heading"><%= gettext('Invoice Type:') %></div>
<div class="value"><%= invoice_type %></div> <div class="value"><%= invoice_type %></div>
</div> </div>
<% if(invoice_number) {%>
<div class="info-item grid-item invoice-number"> <div class="info-item grid-item invoice-number">
<div class="heading"><%= gettext('Invoice Number:') %></div> <div class="heading"><%= gettext('Invoice Number:') %></div>
<div class="value"><%= invoice_number %></div> <div class="value"><%= invoice_number %></div>
</div> </div>
<%}%>
<% if(price) {%>
<div class="info-item grid-item invoiced-amount"> <div class="info-item grid-item invoiced-amount">
<div class="heading"><%= gettext('Invoiced Amount:') %></div> <div class="heading"><%= gettext('Invoiced Amount:') %></div>
<div class="value"><%= price %></div> <div class="value"><%= price %></div>
</div> </div>
<div class="info-item grid-item invoice-discount-type"> <%}%>
<div class="heading"><%= gettext('Invoice Discount Type:') %></div> <% if(invoice_discount_value) {%>
<div class="value"><%= invoice_discount_type %></div>
</div>
<div class="info-item grid-item invoice-discount-value"> <div class="info-item grid-item invoice-discount-value">
<div class="heading"><%= gettext('Invoice Discount Value:') %></div> <div class="heading"><%= gettext('Invoice Discount Value:') %></div>
<div class="value"><%= invoice_discount_value %></div> <div class="value"><%= invoice_discount_value %></div>
</div> </div>
<%}%>
<% if(invoice_payment_date) {%>
<div class="info-item grid-item invoice-payment-date"> <div class="info-item grid-item invoice-payment-date">
<div class="heading"><%= gettext('Invoice Payment Date:') %></div> <div class="heading"><%= gettext('Invoice Payment Date:') %></div>
<div class="value"><%= invoice_payment_date %></div> <div class="value"><%= invoice_payment_date %></div>
</div> </div>
<%}%>
<% if(tax_deducted_source_value) {%>
<div class="info-item grid-item tax-deducted-source-value"> <div class="info-item grid-item tax-deducted-source-value">
<div class="heading"><%= gettext('Tax Deducted Source:') %></div> <div class="heading"><%= gettext('Tax Deducted Source:') %></div>
<div class="value"><%= tax_deducted_source_value %></div> <div class="value"><%= tax_deducted_source_value %></div>
</div> </div>
<%}%>
</div> </div>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment