Commit 1269a31a authored by Floréal Cabanettes's avatar Floréal Cabanettes

Add link on hover for recipes list in panel (functional), Implements #32

parent 09bcebb9
......@@ -135,6 +135,6 @@ form.top-actions {
display: none;
}
.actions-a-recipe .trash {
.actions-a-recipe .trash, .actions-a-recipe .delete {
color: #aa0000;
}
\ No newline at end of file
......@@ -28,6 +28,22 @@ panel.recipes.init_events = function () {
list_recipes.find("table").find("tr").mouseout(function() {
$(this).find(".actions-a-recipe").hide();
});
list_recipes.find(".actions-a-recipe").find("a.publish,a.unpublish,a.trash,a.restore,a.delete").click(function() {
let all_actions = {"publish": "1", "unpublish": "2", "trash": "3", "restore": "4", "delete": "5"};
let action = null;
for (let action_title in all_actions) {
if ($(this).hasClass(action_title)) {
action = all_actions[action_title];
break;
}
}
panel.recipes.apply_action_to_recipe(this, action);
})
};
panel.recipes.apply_action_to_recipe = function (link, action) {
let id_recipe = $(link).closest("tr").find("input.select-recipe").val();
panel.recipes.submit_grouped_actions(action, [id_recipe])
};
panel.recipes.check_all = function (check) {
......@@ -35,17 +51,18 @@ panel.recipes.check_all = function (check) {
"div.list-recipes table tr th:first-child input[type=checkbox]").prop("checked", check);
};
panel.recipes.submit_grouped_actions = function (action) {
panel.recipes.submit_grouped_actions = function (action, selected=[]) {
if (action === 0) {
alert(django.gettext("Please select an action to do!"))
}
else {
// Get selected recipes:
let selection = $("div.list-recipes table tbody tr td:first-child input[type=checkbox]:checked");
let selected = [];
selection.each(function () {
selected.push(parseInt(this.value));
});
if (selected.length === 0) {
let selection = $("div.list-recipes table tbody tr td:first-child input[type=checkbox]:checked");
selection.each(function () {
selected.push(parseInt(this.value));
});
}
$.post("/panel/" + django.gettext("recipes") + "/change/",
{
selection: selected,
......
......@@ -100,7 +100,8 @@ class RecipesView(View):
"nb_comments": recipe.comment_set.count(),
"thumb": thumb_file,
"id": recipe.id,
"slug": recipe.slug
"slug": recipe.slug,
"trash": recipe.trash,
}
show_recipes.append(show_recipe)
all_dates = list(all_dates)
......
......@@ -130,15 +130,20 @@
<td>
<a class="link-recipe" href="#">{{ recipe.title }}</a>
<div class="actions-a-recipe">
<a href="/{% trans 'recipe' %}/{{ recipe.slug }}">{% trans "Show" %}</a>
{% if staff or recipe.author_id == user.id %}
|
{% if recipe.published %}
<a href="#" class="publish">{% trans "Publish" %}</a>
{% else %}
<a href="#" class="unpublish">{% trans "Unpublish" %}</a>
{% if not recipe.trash %}
<a href="/{% trans 'recipe' %}/{{ recipe.slug }}">{% trans "Show" %}</a>
{% if staff or recipe.author_id == user.id %}
|
{% if recipe.published %}
<a href="#" class="unpublish">{% trans "Unpublish" %}</a>
{% else %}
<a href="#" class="publish">{% trans "Publish" %}</a>
{% endif %}
| <a href="#" class="trash">{% trans "Move to trash" %}</a>
{% endif %}
| <a href="#" class="trash">{% trans "Move to trash" %}</a>
{% elif staff or recipe.author_id == user.id %}
<a href="#" class="restore">{% trans "Restore" %}</a> |
<a href="#" class="delete">{% trans "Delete definitively" %}</a>
{% endif %}
</div>
</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment