Skip to content

Instantly share code, notes, and snippets.

@chrishyle
Created July 9, 2009 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishyle/143877 to your computer and use it in GitHub Desktop.
Save chrishyle/143877 to your computer and use it in GitHub Desktop.
MyApp.RowView = SC.ListItemView.extend({
classNames: ['sc-theme myApp-list-item'],
hasStatusIcon: YES,
hasMyField: YES,
statusIconKey: null,
myFieldKey: null,
mySecondFieldKey: null,
myThirdFieldKey: null,
render: function(context, firstTime) {
var content = this.get('content') ;
var del = this.displayDelegate ;
var key, value ;
// handle checkbox
key = this.getDelegateProperty('contentCheckboxKey', del) ;
if (key) {
value = content ? (content.get ? content.get(key) : content[key]) : NO ;
this.renderCheckbox(context, value);
context.addClass('has-checkbox');
}
//handle status icon
if (this.getDelegateProperty('hasStatusIcon', del)) {
key = this.getDelegateProperty('statusIconKey', del) ;
value = (key && content) ? (content.get ? content.get(key) : content[key]) : null ;
this.renderStatusIcon(context, value);
context.addClass('has-status-icon');
}
// handle myField
if (this.getDelegateProperty('hasMyField', del)) {
key = this.getDelegateProperty('myFieldKey', del) ;
value = (key && content) ? (content.get ? content.get(key) : content[key]) : content ;
if (value && SC.typeOf(value) !== SC.T_STRING) value = value.toString();
if (this.get('escapeHTML')) value = SC.RenderContext.escapeHTML(value);
this.renderMyField(context, value);
}
// handle mySecondField -- always invoke
key = this.getDelegateProperty('mySecondFieldKey', del) ;
value = (key && content) ? (content.get ? content.get(key) : content[key]) : content ;
if (value && SC.typeOf(value) !== SC.T_STRING) value = value.toString();
if (this.get('escapeHTML')) value = SC.RenderContext.escapeHTML(value);
this.renderMySecondField(context, value);
// handle myThirdField -- always invoke
key = this.getDelegateProperty('myThirdFieldKey', del) ;
value = (key && content) ? (content.get ? content.get(key) : content[key]) : content ;
if (value && SC.typeOf(value) !== SC.T_STRING) value = value.toString();
if (this.get('escapeHTML')) value = SC.RenderContext.escapeHTML(value);
this.renderMyThirdField(context, value);
// handle action
key = this.getDelegateProperty('listItemActionProperty', del) ;
value = (key && content) ? (content.get ? content.get(key) : content[key]) : null ;
if (value) {
this.renderAction(context, value);
context.addClass('has-action');
}
},
renderStatusIcon: function(context, icon){
// get a class name and url to include if relevant
var url = null, className = null ;
if (icon && SC.ImageView.valueIsUrl(icon)) {
url = icon; className = '' ;
} else {
className = icon; url = SC.BLANK_IMAGE_URL ;
}
// generate the img element...
context.push('<div class="statusIcon table-view-column">')
.begin('img')
.addClass('status-icon table-view-column').addClass(className)
.attr('src', url)
.push('</div>')
.end();
},
renderMyField: function(context, label) {
context.push('<div class="myField table-view-column">', label || '', '</div>') ;
},
renderMySecondField: function(context, label) {
context.push('<div class="mySecondField table-view-column">', label || '', '</div>') ;
},
renderMyThirdField: function(context, label) {
context.push('<div class="myThirdField table-view-column">', label || '', '</div>') ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment