Navigation Menu

Skip to content

Commit

Permalink
Save default search field
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 14, 2012
1 parent 795271c commit 1ef9502
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
20 changes: 20 additions & 0 deletions lib/database/domain.js
Expand Up @@ -180,6 +180,26 @@ Domain.prototype = {
return fields;
},

get defaultSearchField() {
var fieldName = this.getConfiguration(this.defaultSearchFieldConfigurationKey);
var field = this.getIndexField(fieldName);
return field.exists() ? field : null ;
},
set defaultSearchField(value) {
if (!value) {
this.deleteConfiguration(this.defaultSearchFieldConfigurationKey);
} else {
if (typeof value == 'string')
value = this.getIndexField(value);
if (value.exists())
this.setConfiguration(this.defaultSearchFieldConfigurationKey, value.name);
}
return value;
},
get defaultSearchFieldConfigurationKey() {
return 'default_search_field';
},

get id() {
return this._id === undefined ? DEFAULT_ID : this._id ;
},
Expand Down
35 changes: 29 additions & 6 deletions lib/database/index-field.js
Expand Up @@ -148,7 +148,7 @@ IndexField.prototype = {
if (this.type == 'uint')
return false;

if (!this.column || this._facetEnabled !== undefined)
if (!this.exists() || this._facetEnabled !== undefined)
return !!this._facetEnabled;

var value = this.domain.getConfiguration(this.facetEnabledConfigurationKey);
Expand All @@ -158,7 +158,7 @@ IndexField.prototype = {
if (this.type == 'uint')
throw new Error('facet option cannot be configured for the type ' + this.type + '.');

this._facetEnabled = value;
this._facetEnabled = !!value;
return value;
},
setFacetEnabled: function(value) {
Expand All @@ -173,7 +173,7 @@ IndexField.prototype = {
if (this.type == 'uint')
return true;

if (!this.column || this._resultEnabled !== undefined)
if (!this.exists() || this._resultEnabled !== undefined)
return !!this._resultEnabled;

var value = this.domain.getConfiguration(this.resultEnabledConfigurationKey);
Expand All @@ -183,7 +183,7 @@ IndexField.prototype = {
if (this.type == 'uint')
throw new Error('returnable option cannot be configured for the type ' + this.type + '.');

this._resultEnabled = value;
this._resultEnabled = !!value;
return value;
},
setResultEnabled: function(value) {
Expand All @@ -198,7 +198,7 @@ IndexField.prototype = {
if (this.type == 'text' || this.type == 'uint')
return true;

if (!this.column || this._searchEnabled !== undefined)
if (!this.exists() || this._searchEnabled !== undefined)
return !!this._searchEnabled;

var value = this.domain.getConfiguration(this.searchEnabledConfigurationKey);
Expand All @@ -208,7 +208,7 @@ IndexField.prototype = {
if (this.type == 'text' || this.type == 'uint')
throw new Error('searchable option cannot be configured for the type ' + this.type + '.');

this._searchEnabled = value;
this._searchEnabled = !!value;
return value;
},
setSearchEnabled: function(value) {
Expand All @@ -219,6 +219,21 @@ IndexField.prototype = {
return 'column_' + this.name + '_option_search_enabled';
},

get defaultSearchField() {
if (!this.exists())
return false;

return this == this.domain.defaultSearchField;
},
set defaultSearchField(value) {
this._defaultSearchField = !!value;
return value;
},
setDefaultSearchField: function(value) {
this.defaultSearchField = value;
return value;
},

get options() {
var options = [];
if (this.searchEnabled) options.push('Search');
Expand Down Expand Up @@ -286,13 +301,19 @@ IndexField.prototype = {
if (this._searchEnabled !== undefined)
this.domain.setConfiguration(this.searchEnabledConfigurationKey,
this._searchEnabled);

if (this._defaultSearchField !== undefined) {
delete this._defaultSearchField;
this.domain.defaultSearchField = this;
}
},
deleteSync: function() {
// backup information for re-creation
this._type = this.type;
this._facetEnabled = this.facetEnabled;
this._resultEnabled = this.resultEnabled;
this._searchEnabled = this.searchEnabled;
this._defaultSearchField = this.defaultSearchField;

if (this._type == 'uint' || this._type == 'literal') {
this.context.commandSync('table_remove', {
Expand All @@ -307,6 +328,8 @@ IndexField.prototype = {
this.domain.deleteConfiguration(this.facetEnabledConfigurationKey);
this.domain.deleteConfiguration(this.resultEnabledConfigurationKey);
this.domain.deleteConfiguration(this.searchEnabledConfigurationKey);
if (this._defaultSearchField)
this.domain.defaultSearchField = null;
},
reindexSync: function() {
var name = this.name;
Expand Down

0 comments on commit 1ef9502

Please sign in to comment.