Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaller and bigger fixes for experimental select #1449

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

SC.ItemFilter = {


filterItems: function(value) {
this._searchedValue = value;
this.invokeOnceLater('doFilterItems', 250);
Expand All @@ -11,21 +11,24 @@ SC.ItemFilter = {
if (!this._initialItems) this._initialItems = this.get('items');

var value = this._searchedValue,
itemTitleKey = this.get('itemSearchKey') || this.get('itemTitleKey'),
itemTitleKey = this.get('itemSearchKey') || this.get('itemTitleKey') || 'title',
items = this.searchItems(this._initialItems, value, itemTitleKey);

this.set('items', items);
},

searchItems: function(items, value, key) {
var regexp, ret;

if (value) {
items = items.filter(function(item) {
regexp = new RegExp(value, "i");
ret = items.filter(function(item) {
var itemValue = key ? SC.get(item, key) : item;
return SC.typeOf(itemValue) === SC.T_STRING ? itemValue.search(new RegExp(value, "i")) !== -1 : false;
return SC.typeOf(itemValue) === SC.T_STRING ? itemValue.search(reg) !== -1 : false;
});
}

return items;
return ret;
},

};
Expand Down
25 changes: 20 additions & 5 deletions frameworks/experimental/frameworks/select_ext/views/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,31 @@ sc_require("mixins/item_filter");

SC.ComboBoxView = SC.View.extend(SC.ItemFilter, {

/**
* Items to use as search items
* @type {[type]}
*/
items: null,

/**
* What property of the item should be used as title
* @type {String}
*/
itemTitleKey: 'title',

/**
* The value of the selected item
*/
value: null,

selectedMenuItem: null,

textFieldView: SC.TextFieldView,

createChildViews: function() {
var that = this,
var that = this,
view;

view = that.createChildView(this.get('textFieldView'), {
isEnabledBinding: SC.Binding.from('isEnabled', this).oneWay(),
valueBinding: SC.Binding.from('value', this),
Expand All @@ -25,9 +40,9 @@ SC.ComboBoxView = SC.View.extend(SC.ItemFilter, {
if (that._menu) {
that._menu.remove();
}

var value = this.get('value');

if (value !== that._lastValue) {
that._lastValue = value;
that.filterItems(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

SC.MenuSeachPane = SC.AutoResizingMenuPane.extend({
SC.MenuSearchPane = SC.AutoResizingMenuPane.extend({

// Prevent the text field from loosing the focus
// UPDATE: Not working and still buggy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ SC.MultiSelectView = SC.CollectionView.extend({

selectOnMouseDown: NO,

/**
* What to to display when empty
* @type {String}
*/
emptyName: null,

init: function () {
sc_super();

this._currentPopup = null;
this.invokeOnce('schedulePopupSetupIfNeeded');
this._showOrHideEmptyName();
},

_showOrHideEmptyName: function () {
// this should show the message from emptyName
}.observes('emptyName', 'selection'),

// renderDelegateName: 'multiSelectViewRenderDelegate',
//
exampleView: SC.View.extend({
Expand Down Expand Up @@ -255,19 +266,20 @@ SC.MultiSelectView = SC.CollectionView.extend({
}.observes('_selectedValue'),

allItems: function () {
console.log('allItmes');
var sel = this.get('selection');
var titleKey = this.get('contentValueKey');
var me = this;
var count = 0;
return this.get('content').map(function (item, index) {
var ret = this.get('content').map(function (item, index) {
return SC.Object.create({
title: SC.get(item, titleKey),
value: index,
item: item
});
});
}.property().cacheable(),
return ret;
}.property('length').cacheable(),

_updateAllItems: function () {
this.setupPopup();
}.observes('length'),

createPopup: function (popup) {
return popup.create({
Expand Down Expand Up @@ -328,6 +340,7 @@ SC.MultiSelectView = SC.CollectionView.extend({
//when mouseDown is over an empty area in the view, ie not one of the already selected
// options, it should show the popup.
mouseDown: function (evt) {
if (!this.get('isEnabled')) return false;
// sc_super();
// if (!this.get('isEnabled')) return YES;
// this.set('_mouseDown', YES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ SC.SelectSearchView = SC.SelectView.extend({
return searchValue? this.searchItems(ret, searchValue, itemTitleKey): ret;
}.property().cacheable(),

menu: SC.MenuSeachPane.extend(SC.SelectViewMenu, {
menu: SC.MenuSearchPane.extend(SC.SelectViewMenu, {
searchView: function() {
return this.get('selectView');
}.property('selectView').cacheable(),
Expand Down