Skip to content

Commit

Permalink
Evarisk#19 [Kanban] fix: edit column name action
Browse files Browse the repository at this point in the history
  • Loading branch information
theodaviddd committed Oct 29, 2024
1 parent 14cb128 commit 67a6dbf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
5 changes: 3 additions & 2 deletions ajax/kanban.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
$action = GETPOST('action');
$categorie = new Categorie($db);

if ($action == 'renameColumn') {
if ($action == 'rename_column') {
$categorie->fetch($category_id);
$categorie->label = $category_name;
$categorie->update($user);

$test = $categorie->update($user);
}

if ($action == 'add_object_to_column') {
Expand Down
5 changes: 1 addition & 4 deletions core/tpl/kanban_view.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
print '<input type="hidden" id="token" value="' . newToken() . '">';
print '<input type="hidden" id="object_type" value="' . $objectLinkedType . '">';
print '<input type="hidden" id="selector_name" value="' . $selectorName . '">';
print '<span class="column-name" ondblclick="window.digikanban.kanban.editColumn(this)">' . htmlspecialchars($column['label']) . '</span>';
print '<i class="fas fa-pencil-alt edit-icon" onclick="window.digikanban.kanban.editColumn(this.previousElementSibling)"></i>';
print '<span class="column-name" onclick="window.digikanban.kanban.editColumn(this)">' . htmlspecialchars($column['label']) . '</span>';
print '</div>';

// Corps de la colonne où les objets sont listés
Expand Down Expand Up @@ -56,7 +55,5 @@
<div class="add-column-text">+ Ajouter une colonne</div>
</div>
</div>

<script src="kanban.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion css/digikanban.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions css/scss/modules/_kanban.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ body {
.kanban-column-header:hover .column-name,
.kanban-column-header:hover .edit-icon {
color: #f1c40f;
cursor: pointer;
}

.kanban-column-header:hover {
Expand Down
7 changes: 3 additions & 4 deletions js/digikanban.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 31 additions & 8 deletions js/modules/kanban.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ window.digikanban.kanban.addColumn = function() {

newColumn.innerHTML = `
<div class="kanban-column-header">
<span class="column-name" ondblclick="window.digikanban.kanban.editColumn(this)">Nouvelle colonne</span>
<i class="fas fa-pencil-alt edit-icon" onclick="window.digikanban.kanban.editColumn(this.previousElementSibling)"></i>
<span class="column-name" onclick="window.digikanban.kanban.editColumn(this)">Nouvelle colonne</span>
</div>
<div class="kanban-column-body">
</div>
Expand All @@ -122,19 +121,43 @@ window.digikanban.kanban.editColumn = function(nameElement) {
input.value = currentName;
input.classList.add('column-name-input');

input.addEventListener('keypress', function(event) {
if (event.key === 'Enter') {
nameElement.innerText = input.value;
nameElement.style.display = 'inline';
input.remove();
}
input.addEventListener('blur', function() {
saveColumnName(input, nameElement);
});

// Affiche l'input et cache le nom actuel
nameElement.style.display = 'none';
nameElement.parentNode.insertBefore(input, nameElement);
input.focus();
}


/**
* Save the column name and revert back to display mode
*/
function saveColumnName(input, nameElement) {
let url = $('#ajax_actions_url').val();

let token = window.saturne.toolbox.getToken();
let object_type = $('#object_type').val();
let category_id = nameElement.closest('.kanban-column').getAttribute('category-id');

$.ajax({
url: url + "?action=rename_column&token=" + token + '&category_name=' + input.value + '&object_type=' + object_type + '&category_id=' + category_id,
type: "POST",
contentType: "application/json",
success: function(response) {
nameElement.innerText = input.value;
nameElement.style.display = 'inline';
input.remove();
},
error: function() {
console.log("Error saving card order.");
}
})

}

/**
* Triggers when element is selected in the select box
*/
Expand Down

0 comments on commit 67a6dbf

Please sign in to comment.