2014-03-30 13:32:33 +08:00
|
|
|
/**
|
|
|
|
Provide a nice GUI for a pipe-delimited list in the site settings.
|
|
|
|
|
|
|
|
@param settingValue is a reference to SiteSetting.value.
|
2014-06-01 22:36:26 +08:00
|
|
|
@param choices is a reference to SiteSetting.choices
|
2014-12-16 03:41:08 +08:00
|
|
|
**/
|
|
|
|
export default Ember.Component.extend({
|
2014-08-10 23:46:04 +08:00
|
|
|
|
|
|
|
_select2FormatSelection: function(selectedObject, jqueryWrapper, htmlEscaper) {
|
|
|
|
var text = selectedObject.text;
|
|
|
|
if (text.length <= 6) {
|
|
|
|
jqueryWrapper.closest('li.select2-search-choice').css({"border-bottom": '7px solid #'+text});
|
|
|
|
}
|
|
|
|
return htmlEscaper(text);
|
|
|
|
},
|
|
|
|
|
2014-12-16 03:41:08 +08:00
|
|
|
_initializeSelect2: function(){
|
|
|
|
var options = {
|
2014-08-10 23:46:04 +08:00
|
|
|
multiple: false,
|
|
|
|
separator: "|",
|
|
|
|
tokenSeparators: ["|"],
|
|
|
|
tags : this.get("choices") || [],
|
|
|
|
width: 'off',
|
2015-04-10 07:13:51 +08:00
|
|
|
dropdownCss: this.get("choices") ? {} : {display: 'none'},
|
|
|
|
selectOnBlur: this.get("choices") ? false : true
|
2014-08-10 23:46:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var settingName = this.get('settingName');
|
|
|
|
if (typeof settingName === 'string' && settingName.indexOf('colors') > -1) {
|
2014-12-16 03:41:08 +08:00
|
|
|
options.formatSelection = this._select2FormatSelection;
|
2014-08-10 23:46:04 +08:00
|
|
|
}
|
2014-12-16 03:41:08 +08:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
this.$("input").select2(options).on("change", function(obj) {
|
|
|
|
self.set("settingValue", obj.val.join("|"));
|
|
|
|
self.refreshSortables();
|
|
|
|
});
|
2014-06-01 22:36:26 +08:00
|
|
|
|
|
|
|
this.refreshSortables();
|
2014-12-16 03:41:08 +08:00
|
|
|
}.on('didInsertElement'),
|
2014-03-30 13:32:33 +08:00
|
|
|
|
2014-06-01 22:36:26 +08:00
|
|
|
refreshOnReset: function() {
|
|
|
|
this.$("input").select2("val", this.get("settingValue").split("|"));
|
|
|
|
}.observes("settingValue"),
|
2014-03-30 13:32:33 +08:00
|
|
|
|
2014-06-01 22:36:26 +08:00
|
|
|
refreshSortables: function() {
|
2014-12-16 03:41:08 +08:00
|
|
|
var self = this;
|
2014-06-01 22:36:26 +08:00
|
|
|
this.$("ul.select2-choices").sortable().on('sortupdate', function() {
|
2014-12-16 03:41:08 +08:00
|
|
|
self.$("input").select2("onSortEnd");
|
|
|
|
});
|
2014-03-30 13:32:33 +08:00
|
|
|
}
|
|
|
|
});
|
2014-06-01 22:36:26 +08:00
|
|
|
|
|
|
|
|