Skip to content

Instantly share code, notes, and snippets.

@publickeating
Forked from cronco/main.js
Created March 6, 2012 16:04
Show Gist options
  • Save publickeating/1987053 to your computer and use it in GitHub Desktop.
Save publickeating/1987053 to your computer and use it in GitHub Desktop.
sproutcore issue - availableList contentBinding crashes app
/* ... */
var items = Items.store.find('Items.Item');
// Don't need this
//Items.selectedItemsController.set('content',[]);
Items.mainItemsController.set('content', items);
/* ... */
//Don't need this and shouldn't probably ever have to have controllers dependent on each other
//sc_require('controllers/selected_items');
Items.mainItemsController = SC.ArrayController.create(
/** @scope Items.mainItemsController.prototype */ {
/* Don't do any of this --v
selectedBinding: 'Items.selectedItemsController.arrangedObjects',
arrangedObjects: function() {
var sel = Items.selectedItemsController.get('content');
return this.filter(function(item) {
if (sel && sel.get('length')) {
return sel.indexOf(item) === -1;
} else return YES;
});
}.property('content', 'selected'),
selectItem: function() {
var selected = this.get('selection').get('firstObject');
console.log(selected);
Items.selectedItemsController.addObject(selected);
}
*/
});
// ==========================================================================
// Project: Items - mainPage
// Copyright: @2012 My Company, Inc.
// ==========================================================================
/*globals Items */
// This page describes the main user interface for your application.
Items.mainPage = SC.Page.design({
// The main pane is made visible on screen as soon as your app is loaded.
// Add childViews to this pane for views to display immediately on page
// load.
mainPane: SC.MainPane.design({
layerId: 'items',
childViews: 'availableView'.w(),
layout: { width: 400, height: 300, centerX:0, centerY: 0 },
availableView: SC.ScrollView.design({
contentView: SC.View.design({
layout: { maxHeight: 200, top: 0 },
childViews: 'available selected'.w(),
available: SC.View.design({
childViews: 'availableLabel availableList'.w(),
availableLabel: SC.LabelView.design({
displayTitle: "Available Items",
value: "Available Items"
}),
availableList: SC.ListView.design({
textAlign: SC.ALIGN_CENTER,
rowHeight: 10,
columnWidth:300,
// oneWay binding is preferred for content anyway, since it is faster and the listview can't alter
// the content. The selection binding should be two way since the listview alters it.
contentBinding: SC.Binding.oneWay('Items.unselectedItemsController.arrangedObjects'),
selectionBinding: 'Items.mainItemsController.selection',
contentValueKey: 'name',
target: 'Items.mainItemsController',
action: 'selectItem',
}),
}),
selected: SC.View.design({
layout: { top: 100, maxHeight: 200},
childViews: 'selectedLabel selectedList'.w(),
selectedLabel: SC.LabelView.design({
displayTitle: "Selected Items",
value: "Selected Items"
}),
selectedList: SC.ListView.design({
textAlign: SC.ALIGN_CENTER,
rowHeight:10,
columnWidth: 300,
contentBinding:'Items.selectedItemsController.arrangedObjects',
// This should allow you to select an item here to move it back
selectionBinding: 'Items.mainItemsController.selection',
contentValueKey: 'name'
})
})
})
})
})
});
Items.selectedItemsController = SC.ArrayController.create(
/** @scope Items.selectedItemsController.prototype */ {
contentBinding: 'Items.mainItemsController.selection',
orderBy: 'name'
}) ;
Items.selectedItemsController = SC.ArrayController.create(
/** @scope Items.selectedItemsController.prototype */ {
contentBinding: 'Items.mainItemsController.selection'.transform(function(selection) {
var arrangedObjects = Items.mainItemsController.get('arrangedObjects');
// create inverse of selection
selection = selection.copy();
}),
orderBy: 'name'
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment