Skip to content

Instantly share code, notes, and snippets.

@ttdonovan
Created November 17, 2008 21:57
Show Gist options
  • Select an option

  • Save ttdonovan/25923 to your computer and use it in GitHub Desktop.

Select an option

Save ttdonovan/25923 to your computer and use it in GitHub Desktop.
_currSelGuid: null, // keep track of current selection guid
// myController.addProbe(selection)
refreshRecordWhenSelected: function () {
// cannot observe selection for changes because of SC.SelectionSupport#updateSelectionAfterContentChange in sproutcore/mixins/selection_support.js
// if (!this.didChangeFor('refreshRecordWhenSelected', 'selection')) { return ; }
var sel = this.get('selection'),
record = null ;
if (sel.length == 1) {
record = sel.first() ;
} else {
this.set('_currSelGuid', null) ; // empty current selection
return ; // empty selection or invalid number of selections
}
// check if record is different from current selection
if (record.guid != this.get('_currSelGuid')) {
if (!record.newRecord) { record.refresh(); }
this.set('_currSelGuid', record.guid) ; // set current selection for selection observation
}
}.observes('selection')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment