Skip to content
Snippets Groups Projects
Unverified Commit 944e18b2 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

fixes

parent b0b38773
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ window.osuny.contentEditor = {
}
this.sortHeadingsUrl = this.container.getAttribute('data-sort-headings-url');
this.sortBlocksUrl = this.container.getAttribute('data-sort-blocks-url');
this.initElements();
this.initSortable();
},
......@@ -52,19 +52,15 @@ window.osuny.contentEditor = {
animation: 150,
fallbackOnBody: true,
swapThreshold: 0.65,
onChoose: this.onSortableChoose.bind(this),
onUnchoose: this.onSortableUnchoose.bind(this),
onStart: this.onSortableStart.bind(this),
onMove: this.onSortableMove.bind(this),
onEnd: this.onSortableEnd.bind(this)
});
this.sortableInstances.push(sortableInstance);
}
},
onSortableChoose: function (event) {
'use strict';
},
onSortableStart: function (event) {
'use strict';
var item = event.item,
......@@ -77,6 +73,18 @@ window.osuny.contentEditor = {
}
},
onSortableMove: function (event) {
'use strict';
var draggedKind = event.dragged.dataset.kind,
relatedKind = event.related.dataset.kind;
if (draggedKind === 'block') {
// Prevent dragging a block after a heading, instead of inside
return relatedKind !== 'heading' || !event.willInsertAfter;
}
return true;
},
onSortableEnd: function (event) {
'use strict';
var item = event.item,
......
......@@ -99,10 +99,6 @@ class Communication::Block < ApplicationRecord
template.git_dependencies
end
def last_ordered_element
about.blocks.ordered.last
end
def template
@template ||= template_class.new self, self.attributes['data']
end
......@@ -137,6 +133,10 @@ class Communication::Block < ApplicationRecord
protected
def last_ordered_element
about.blocks.ordered.last
end
def check_accessibility
accessibility_merge template
end
......@@ -146,7 +146,8 @@ class Communication::Block < ApplicationRecord
end
def set_heading_from_about
self.heading = about.headings.ordered.last
# TODO: Ne gère que le 1er niveau actuellement
self.heading = about.headings.root.ordered.last
end
# FIXME @sebou
......
......@@ -26,6 +26,10 @@
# fk_rails_ae82723550 (university_id => universities.id)
#
class Communication::Block::Heading < ApplicationRecord
include Sanitizable
include WithPosition
include WithUniversity
belongs_to :university
belongs_to :about,
polymorphic: true
......@@ -40,8 +44,7 @@ class Communication::Block::Heading < ApplicationRecord
DEFAULT_LEVEL = 2
scope :root, -> { where(level: DEFAULT_LEVEL) }
scope :ordered, -> { order(:position) }
scope :root, -> { where(parent_id: nil) }
before_validation :compute_level
......@@ -51,6 +54,10 @@ class Communication::Block::Heading < ApplicationRecord
protected
def last_ordered_element
about.headings.where(parent_id: self.parent_id).ordered.last
end
def compute_level
self.level = parent ? parent.level + 1
: DEFAULT_LEVEL
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment