-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
UI for list site settings #2207
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
app/assets/javascripts/admin/components/list_setting_component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
Provide a nice GUI for a pipe-delimited list in the site settings. | ||
|
||
@param settingValue is a reference to SiteSetting.value. | ||
|
||
@class Discourse.ListSettingComponent | ||
@extends Ember.Component | ||
@namespace Discourse | ||
@module Discourse | ||
**/ | ||
Discourse.ListSettingComponent = Ember.Component.extend({ | ||
layoutName: 'components/list-setting', | ||
|
||
init: function() { | ||
this._super(); | ||
this.on("focusOut", this.uncacheValue); | ||
this.set('children', []); | ||
}, | ||
|
||
canAddNew: true, | ||
|
||
readValues: function() { | ||
return this.get('settingValue').split('|'); | ||
}.property('settingValue'), | ||
|
||
/** | ||
Transfer the debounced value into the settingValue parameter. | ||
|
||
This will cause a redraw of the child textboxes. | ||
|
||
@param newFocus {Number|undefined} Which list index to focus on next, or undefined to not refocus | ||
**/ | ||
uncacheValue: function(newFocus) { | ||
var oldValue = this.get('settingValue'), | ||
newValue = this.get('settingValueCached'), | ||
self = this; | ||
|
||
if (newValue !== undefined && newValue !== oldValue) { | ||
this.set('settingValue', newValue); | ||
} | ||
|
||
if (newFocus !== undefined && newFocus > 0) { | ||
Em.run.schedule('afterRender', function() { | ||
var children = self.get('children'); | ||
if (newFocus < children.length) { | ||
$(children[newFocus].get('element')).focus(); | ||
} else if (newFocus === children.length) { | ||
$(self.get('element')).children().children('.list-add-value').focus(); | ||
} | ||
}); | ||
} | ||
}, | ||
|
||
setItemValue: function(index, item) { | ||
var values = this.get('readValues'); | ||
values[index] = item; | ||
|
||
// Remove blank items | ||
values = values.filter(function(s) { return s !== ''; }); | ||
this.setProperties({ | ||
settingValueCached: values.join('|'), | ||
canAddNew: true | ||
}); | ||
}, | ||
|
||
actions: { | ||
addNewItem: function() { | ||
var newValue = this.get('settingValue') + '|'; | ||
this.setProperties({ | ||
settingValue: newValue, | ||
settingValueCached: newValue, | ||
canAddNew: false | ||
}); | ||
|
||
var self = this; | ||
Em.run.schedule('afterRender', function() { | ||
var children = self.get('children'); | ||
$(children[children.length - 1].get('element')).focus(); | ||
}); | ||
} | ||
} | ||
}); |
44 changes: 44 additions & 0 deletions
44
app/assets/javascripts/admin/components/list_setting_item_component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
One item in a ListSetting. | ||
|
||
@param parent is the ListSettingComponent. | ||
|
||
@class Discourse.ListSettingItemComponent | ||
@extends Ember.Component, Ember.TextSupport | ||
@namespace Discourse | ||
@module Discourse | ||
**/ | ||
Discourse.ListSettingItemComponent = Ember.Component.extend(Ember.TextSupport, { | ||
classNames: ['ember-text-field'], | ||
tagName: "input", | ||
attributeBindings: ['type', 'value', 'size', 'pattern'], | ||
|
||
_initialize: function() { | ||
// _parentView is the #each | ||
// parent is the ListSettingComponent | ||
this.setProperties({ | ||
value: this.get('_parentView.content'), | ||
index: this.get('_parentView.contentIndex') | ||
}); | ||
this.get('parent').get('children')[this.get('index')] = this; | ||
}.on('init'), | ||
|
||
markTab: function(e) { | ||
var keyCode = e.keyCode || e.which; | ||
|
||
if (keyCode === 9) { | ||
this.set('nextIndex', this.get('index') + (e.shiftKey ? -1 : 1)); | ||
} | ||
}.on('keyDown'), | ||
|
||
reloadList: function() { | ||
var nextIndex = this.get('nextIndex'); | ||
this.set('nextIndex', undefined); // one use only | ||
this.get('parent').uncacheValue(nextIndex); | ||
}.on('focusOut'), | ||
|
||
_elementValueDidChange: function() { | ||
this._super(); | ||
this.get('parent').setItemValue(this.get('index'), this.get('value')); | ||
} | ||
}); |
17 changes: 17 additions & 0 deletions
17
app/assets/javascripts/admin/templates/site_settings/setting_list.js.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class='setting-label'> | ||
<h3>{{unbound setting}}</h3> | ||
</div> | ||
<div class="setting-value"> | ||
{{list-setting settingValue=value}} | ||
<div class='desc'>{{unbound description}}</div> | ||
</div> | ||
{{#if dirty}} | ||
<div class='setting-controls'> | ||
<button class='btn ok no-text' {{action save this}}><i class='fa fa-check'></i></button> | ||
<button class='btn cancel no-text' {{action cancel this}}><i class='fa fa-times'></i></button> | ||
</div> | ||
{{else}} | ||
{{#if overridden}} | ||
<button class='btn' href='#' {{action resetDefault this}}>{{i18n admin.site_settings.reset}}</button> | ||
{{/if}} | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/assets/javascripts/discourse/templates/components/list-setting.js.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="ac-wrap clearfix input-setting-list"> | ||
{{#each readValues}} | ||
{{list-setting-item parent=view action=update classNames="list-input-item"}} | ||
{{/each}} | ||
{{#if canAddNew}} | ||
<button class="btn no-text list-add-value" {{action addNewItem}}><i class="fa fa-plus"></i></button> | ||
{{/if}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class SiteSettingCommaToPipe < ActiveRecord::Migration | ||
def up | ||
execute <<SQL | ||
UPDATE site_settings | ||
SET value = replace(value, ',', '|') | ||
WHERE name = 'white_listed_spam_host_domains' | ||
; | ||
SQL | ||
execute <<SQL | ||
UPDATE site_settings | ||
SET value = replace(value, ',', '|') | ||
WHERE name = 'exclude_rel_nofollow_domains' | ||
; | ||
SQL | ||
end | ||
|
||
def down | ||
execute <<SQL | ||
UPDATE site_settings | ||
SET value = replace(value, '|', ',') | ||
WHERE name = 'white_listed_spam_host_domains' | ||
; | ||
SQL | ||
execute <<SQL | ||
UPDATE site_settings | ||
SET value = replace(value, '|', ',') | ||
WHERE name = 'exclude_rel_nofollow_domains' | ||
; | ||
SQL | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does adding
}.on("focusOut"),
work here instead of having it in theinit
function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the
focusOut
event is on the item components. I'm testing an alternate method right now...