forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement nested assemblies navigation (decidim#13662)
- Loading branch information
Showing
17 changed files
with
168 additions
and
197 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
decidim-assemblies/app/packs/entrypoints/decidim_assemblies_admin_list.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 @@ | ||
import "src/decidim/assemblies/admin/assemblies_list" |
72 changes: 72 additions & 0 deletions
72
decidim-assemblies/app/packs/src/decidim/assemblies/admin/assemblies_list.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,72 @@ | ||
/* eslint-disable require-jsdoc */ | ||
|
||
class AdminAssembliesListComponent { | ||
run() { | ||
this.rebindArrows(); | ||
} | ||
|
||
rebindArrows() { | ||
this.unbindArrows(); | ||
this.bindArrows(); | ||
} | ||
|
||
bindArrows() { | ||
document.querySelectorAll("[data-arrow-up]").forEach((element) => { | ||
element.addEventListener("click", this._onClickUpArrow); | ||
}); | ||
document.querySelectorAll("[data-arrow-down]").forEach((element) => { | ||
element.addEventListener("click", this._onClickDownArrow); | ||
}); | ||
} | ||
|
||
unbindArrows() { | ||
document.querySelectorAll("[data-arrow-up]").forEach((element) => { | ||
element.removeEventListener("click", this._onClickUpArrow); | ||
}); | ||
document.querySelectorAll("[data-arrow-down]").forEach((element) => { | ||
element.removeEventListener("click", this._onClickDownArrow); | ||
}); | ||
} | ||
|
||
_onClickDownArrow(event) { | ||
event.preventDefault(); | ||
|
||
const target = event.currentTarget; | ||
const assembly = target.closest("[data-assembly-id]"); | ||
const upArrow = assembly.querySelector("[data-arrow-up]"); | ||
|
||
target.classList.toggle("hidden"); | ||
upArrow.classList.toggle("hidden"); | ||
} | ||
|
||
_onClickUpArrow(event) { | ||
event.preventDefault(); | ||
|
||
const target = event.currentTarget; | ||
const assembly = target.closest("[data-assembly-id]"); | ||
const parentLevel = assembly.dataset.level; | ||
const downArrow = assembly.querySelector("[data-arrow-down]"); | ||
|
||
target.classList.toggle("hidden"); | ||
downArrow.classList.toggle("hidden"); | ||
|
||
// Get all following tr elements | ||
let nextElement = assembly.nextElementSibling; | ||
while (nextElement) { | ||
const currentLevel = nextElement.dataset.level; | ||
const nextSibling = nextElement.nextElementSibling; | ||
|
||
if (currentLevel > parentLevel) { | ||
nextElement.remove(); | ||
} else { | ||
break; | ||
} | ||
nextElement = nextSibling; | ||
} | ||
} | ||
} | ||
|
||
window.Decidim.AdminAssembliesListComponent = AdminAssembliesListComponent; | ||
const component = new AdminAssembliesListComponent(); | ||
|
||
component.run(); |
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 |
---|---|---|
|
@@ -40,3 +40,5 @@ | |
|
||
<%= decidim_paginate @assemblies %> | ||
</div> | ||
|
||
<%= append_javascript_pack_tag "decidim_assemblies_admin_list" %> |
10 changes: 10 additions & 0 deletions
10
decidim-assemblies/app/views/decidim/assemblies/admin/assemblies/index.js.erb
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,10 @@ | ||
$('[data-assembly-id="<%= parent_assembly_id %>"]').after( | ||
'<%= j(render partial: "decidim/assemblies/admin/assemblies/assembly_row", | ||
collection: @assemblies, | ||
as: :assembly, | ||
locals: { view: :index }).strip.html_safe %>' | ||
); | ||
|
||
var component = new window.Decidim.AdminAssembliesListComponent(); | ||
|
||
component.run(); |
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
Oops, something went wrong.