Skip to content

Instantly share code, notes, and snippets.

@kuon
Created January 28, 2011 17:28
Show Gist options
  • Save kuon/800597 to your computer and use it in GitHub Desktop.
Save kuon/800597 to your computer and use it in GitHub Desktop.
Accounting.InvoiceEntryItemView = SC.View.extend(SC.Control,{
classNames:"invoice-entry-item",
acceptsFirstResponder:YES,
alternateClass:function() {
return this.get('contentIndex') % 2 === 0 ? "even" : "odd";
}.property('contentIndex'),
_accountChanged:function() {
this.displayDidChange();
}.observes('*content.account.number'),
render:function(ctx) {
var c = this.get('content');
if(!c) return;
ctx.removeClass('sc-collection-item');
ctx.addClass(this.get('alternateClass'));
if(this.get('isSelected')) {
ctx.push('<div class="left">');
ctx.push('<input class="account" type="text" value="',c.getPath('account.number'),'"></input>');
ctx.push('<input class="label" type="text" value="'); ctx.text(c.get('label')); ctx.push('"></input>');
ctx.push('</div>');
ctx.push('<div class="right">');
ctx.push('<input class="quantity" type="text" value="',c.get('quantity'),'"></input>');
ctx.push('<input class="unit_price" type="text" value="',Accounting.formatCurrency(c.get('unitPrice')),'"></input>');
ctx.push('<div class="tax_included"><input type="checkbox"',
c.get('tax_included') ? 'checked="checked"':'',
'"></input></div>');
ctx.push(
'<div class="tax_rate">',
'<select>',
'<option value="0.08">8%</option>',
'<option value="0.025">2.5%</option>',
'<option value="0">0%</option>',
'<option value="0.076">7.6%</option>',
'<option value="0.024">2.4%</option>',
'</select>',
'</div>'
);
ctx.push('<label class="tax_total">', Accounting.formatCurrency(c.get('taxTotal')), '</label>',
'<label class="total_without_tax">', Accounting.formatCurrency(c.get('totalWithoutTax')), '</label>',
'<label class="total_with_tax">', Accounting.formatCurrency(c.get('totalWithTax')), '</label>');
ctx.push('</div>');
}
else {
ctx.push('<div class="left">');
ctx.push('<label class="account">', c.getPath('account.number'), '</label>');
ctx.push('<label class="label">'); ctx.text(c.get('label')); ctx.push('</label>');
ctx.push('</div>');
ctx.push(
'<div class="right">',
'<label class="quantity">', c.get('quantity'), '</label>',
'<label class="unit_price">', Accounting.formatCurrency(c.get('unitPrice')), '</label>',
'<label class="tax_included">', c.get('taxIncluded') ? 'TTC' : 'HT', '</label>',
'<label class="tax_rate">', Accounting.formatPercent(c.get('taxRate')), '</label>',
'<label class="tax_total">', Accounting.formatCurrency(c.get('taxTotal')), '</label>',
'<label class="total_without_tax">', Accounting.formatCurrency(c.get('totalWithoutTax')), '</label>',
'<label class="total_with_tax">', Accounting.formatCurrency(c.get('totalWithTax')), '</label>',
'</div>'
);
}
},
mouseDown:function(evt) {
evt.allowDefault();
this.becomeFirstResponder();
return NO;
},
keyDown:function(evt) {
evt.allowDefault();
return YES;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment