mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 04:36:05 +08:00
DEV: introduces prettier for es6 files
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
export default Ember.Component.extend({
|
||||
classNameBindings: [':value-list'],
|
||||
classNameBindings: [":value-list"],
|
||||
|
||||
_enableSorting: function() {
|
||||
const self = this;
|
||||
@ -10,16 +10,16 @@ export default Ember.Component.extend({
|
||||
let over = null;
|
||||
let nodePlacement;
|
||||
|
||||
this.$().on('dragstart.discourse', '.values .value', function(e) {
|
||||
this.$().on("dragstart.discourse", ".values .value", function(e) {
|
||||
dragging = e.currentTarget;
|
||||
e.dataTransfer.effectAllowed = 'move';
|
||||
e.dataTransfer.effectAllowed = "move";
|
||||
e.dataTransfer.setData("text/html", e.currentTarget);
|
||||
});
|
||||
|
||||
this.$().on('dragend.discourse', '.values .value', function() {
|
||||
this.$().on("dragend.discourse", ".values .value", function() {
|
||||
Ember.run(function() {
|
||||
dragging.parentNode.removeChild(placeholder);
|
||||
dragging.style.display = 'block';
|
||||
dragging.style.display = "block";
|
||||
|
||||
// Update data
|
||||
const from = Number(dragging.dataset.index);
|
||||
@ -27,7 +27,7 @@ export default Ember.Component.extend({
|
||||
if (from < to) to--;
|
||||
if (nodePlacement === "after") to++;
|
||||
|
||||
const collection = self.get('collection');
|
||||
const collection = self.get("collection");
|
||||
const fromObj = collection.objectAt(from);
|
||||
collection.replace(from, 1);
|
||||
collection.replace(to, 0, [fromObj]);
|
||||
@ -36,10 +36,12 @@ export default Ember.Component.extend({
|
||||
return false;
|
||||
});
|
||||
|
||||
this.$().on('dragover.discourse', '.values', function(e) {
|
||||
this.$().on("dragover.discourse", ".values", function(e) {
|
||||
e.preventDefault();
|
||||
dragging.style.display = 'none';
|
||||
if (e.target.className === "placeholder") { return; }
|
||||
dragging.style.display = "none";
|
||||
if (e.target.className === "placeholder") {
|
||||
return;
|
||||
}
|
||||
over = e.target;
|
||||
|
||||
const relY = e.originalEvent.clientY - over.offsetTop;
|
||||
@ -49,54 +51,61 @@ export default Ember.Component.extend({
|
||||
if (relY > height) {
|
||||
nodePlacement = "after";
|
||||
parent.insertBefore(placeholder, e.target.nextElementSibling);
|
||||
} else if(relY < height) {
|
||||
} else if (relY < height) {
|
||||
nodePlacement = "before";
|
||||
parent.insertBefore(placeholder, e.target);
|
||||
}
|
||||
});
|
||||
}.on('didInsertElement'),
|
||||
}.on("didInsertElement"),
|
||||
|
||||
_removeSorting: function() {
|
||||
this.$().off('dragover.discourse').off('dragend.discourse').off('dragstart.discourse');
|
||||
}.on('willDestroyElement'),
|
||||
this.$()
|
||||
.off("dragover.discourse")
|
||||
.off("dragend.discourse")
|
||||
.off("dragstart.discourse");
|
||||
}.on("willDestroyElement"),
|
||||
|
||||
_setupCollection: function() {
|
||||
const values = this.get('values');
|
||||
if (this.get('inputType') === "array") {
|
||||
this.set('collection', values || []);
|
||||
const values = this.get("values");
|
||||
if (this.get("inputType") === "array") {
|
||||
this.set("collection", values || []);
|
||||
} else {
|
||||
this.set('collection', (values && values.length) ? values.split("\n") : []);
|
||||
this.set("collection", values && values.length ? values.split("\n") : []);
|
||||
}
|
||||
}.on('init').observes('values'),
|
||||
}
|
||||
.on("init")
|
||||
.observes("values"),
|
||||
|
||||
_saveValues: function() {
|
||||
if (this.get('inputType') === "array") {
|
||||
this.set('values', this.get('collection'));
|
||||
if (this.get("inputType") === "array") {
|
||||
this.set("values", this.get("collection"));
|
||||
} else {
|
||||
this.set('values', this.get('collection').join("\n"));
|
||||
this.set("values", this.get("collection").join("\n"));
|
||||
}
|
||||
},
|
||||
|
||||
inputInvalid: Ember.computed.empty('newValue'),
|
||||
inputInvalid: Ember.computed.empty("newValue"),
|
||||
|
||||
keyDown(e) {
|
||||
if (e.keyCode === 13) {
|
||||
this.send('addValue');
|
||||
this.send("addValue");
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
addValue() {
|
||||
if (this.get('inputInvalid')) { return; }
|
||||
if (this.get("inputInvalid")) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.get('collection').addObject(this.get('newValue'));
|
||||
this.set('newValue', '');
|
||||
this.get("collection").addObject(this.get("newValue"));
|
||||
this.set("newValue", "");
|
||||
|
||||
this._saveValues();
|
||||
},
|
||||
|
||||
removeValue(value) {
|
||||
const collection = this.get('collection');
|
||||
const collection = this.get("collection");
|
||||
collection.removeObject(value);
|
||||
this._saveValues();
|
||||
}
|
||||
|
Reference in New Issue
Block a user