smaller refactorings continued

This commit is contained in:
azivner
2018-04-01 11:42:12 -04:00
parent fad0ec757b
commit acc82f39c4
13 changed files with 96 additions and 100 deletions

View File

@@ -15,6 +15,18 @@ function LabelsModel() {
this.labels = ko.observableArray();
this.updateLabelPositions = function() {
let position = 0;
// we need to update positions by searching in the DOM, because order of the
// labels in the viewmodel (self.labels()) stays the same
$labelsBody.find('input[name="position"]').each(function() {
const label = self.getTargetLabel(this);
label().position = position++;
});
};
this.loadLabels = async function() {
const noteId = noteDetailService.getCurrentNoteId();
@@ -32,17 +44,7 @@ function LabelsModel() {
$labelsBody.sortable({
handle: '.handle',
containment: $labelsBody,
update: function() {
let position = 0;
// we need to update positions by searching in the DOM, because order of the
// labels in the viewmodel (self.labels()) stays the same
$labelsBody.find('input[name="position"]').each(function() {
const label = self.getTargetLabel(this);
label().position = position++;
});
}
update: this.updateLabelPositions
});
};
@@ -80,6 +82,8 @@ function LabelsModel() {
return;
}
self.updateLabelPositions();
const noteId = noteDetailService.getCurrentNoteId();
const labelsToSave = self.labels()