Skip to content

Commit

Permalink
fix new/edit erb
Browse files Browse the repository at this point in the history
  • Loading branch information
antopalidi committed Sep 5, 2024
1 parent 9ea816c commit e8a4675
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ def create
end

def edit
enforce_permission_to(:update, :share_token, share_token: share_token)
@form = form(ShareTokenForm).from_model(share_token)
end

def update
enforce_permission_to(:update, :share_tokens, share_token: current_token)
enforce_permission_to(:update, :share_token, share_token: current_token)
@form = form(ShareTokenForm).from_model(current_token)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= b.label %>
</div>
<% end %>
<div id="expires_at_field_wrapper" class="hidden mt-4 row column">
<div id="expires_at_field_wrapper" class="hide row column">
<%= form.datetime_field :expires_at, label: t("share_tokens.form.custom_expiration", scope: "decidim.admin") %>
</div>
</div>
Expand Down Expand Up @@ -35,9 +35,9 @@

const toggleExpiresAtField = () => {
if (expiresButton.checked) {
expiresAtWrapper.classList.remove("hidden");
expiresAtWrapper.classList.remove("hide");
} else {
expiresAtWrapper.classList.add("hidden");
expiresAtWrapper.classList.add("hide");
expiresAtInput.value = "";
expiresAtInput.removeAttribute("required");
}
Expand Down
56 changes: 29 additions & 27 deletions decidim-admin/app/views/decidim/admin/share_tokens/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<% add_decidim_page_title(t(".title")) %>
<div class="item_show__header">
<h1 class="item_show__header-title">
<%= t ".title", name: resource_title %>
<a class="button button__sm button__secondary" href="<%= share_tokens_path %>"><%= t("share_tokens.index.back_to_share_tokens", scope: "decidim.admin") %></a>
</h1>
</div>
<div class="item__edit-form">
<%= decidim_form_for(@form, url: share_tokens_path(:update, id: current_token), html: { class: "form-defaults form edit_share_token" }) do |f| %>
<div class="card">
<div class="card-section">
<div class="form__wrapper">
<div class="card pt-4">
<div class="row column">
<label for="share_token-token"><%= t("token", scope: "decidim.admin.models.share_token.fields") %></label>
<div class="flex gap-4">
<%= text_field_tag :token, current_token.token, id: "share_token-token", aria: { label: t("token", scope: "decidim.admin.models.share_token.fields") }, disabled: true %>
<button type="button" class="button button__sm button__secondary text-nowrap" data-clipboard-copy="#share_token-token" data-clipboard-content="<%= current_token.url %>" data-clipboard-copy-label="<%= t("copied", scope: "decidim.admin.share_tokens.index") %>" data-clipboard-copy-message="<%= t("copy_message", scope: "decidim.admin.share_tokens.index") %>"><%= t("actions.copy_link", scope: "decidim.admin.share_tokens") %></button>
</div>
</div>
<%= render partial: "form", object: f %>
</div>
<%= decidim_form_for(@form, url: share_tokens_path(:update, id: current_token), html: { class: "form-defaults form edit_share_token" }) do |f| %>
<div class="card">
<div class="card-divider">
<h2 class="card-title">
<div class="flex--sbc">
<%= t ".title", name: resource_title %>
<%= link_to :back do %>
<%= icon "chevron-left", class: "icon--small", role: "img", "aria-hidden": true %>
<%= t("share_tokens.index.back_to_share_tokens", scope: "decidim.admin") %>
<% end %>
</div>
</div>
</h2>
</div>
<div class="item__edit-sticky">
<div class="item__edit-sticky-container">
<%= f.submit t(".update"), class: "button button__sm button__secondary" %>
<div class="card-section">
<div class="row column">
<label for="share_token-token"><%= t("token", scope: "decidim.admin.models.share_token.fields") %></label>
<div class="input-group">
<%= text_field_tag :token, current_token.token, id: "share_token-token", aria: { label: t("token", scope: "decidim.admin.models.share_token.fields") }, disabled: true, class: "input-group-field mb-none" %>
<div class="input-group-button">
<button type="button" class="button" data-clipboard-copy="#share_token-token" data-clipboard-content="<%= current_token.url %>" data-clipboard-copy-label="<%= t("copied", scope: "decidim.admin.share_tokens.index") %>" data-clipboard-copy-message="<%= t("copy_message", scope: "decidim.admin.share_tokens.index") %>">
<%= t("actions.copy_link", scope: "decidim.admin.share_tokens") %>
</button>
</div>
</div>
</div>
<%= render partial: "form", object: f %>
</div>
<% end %>
</div>
</div>

<div class="button--double form-general-submit">
<%= f.submit t(".update") %>
</div>
<% end %>
76 changes: 37 additions & 39 deletions decidim-admin/app/views/decidim/admin/share_tokens/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
<% add_decidim_page_title(t(".title")) %>
<div class="item_show__header">
<h1 class="item_show__header-title">
<%= t ".title", name: resource_title %>
<a class="button button__sm button__secondary" href="<%= share_tokens_path %>"><%= t("share_tokens.index.back_to_share_tokens", scope: "decidim.admin") %></a>
</h1>
</div>
<div class="item__edit-form">
<%= decidim_form_for(@form, url: share_tokens_path(:create), html: { class: "form-defaults form new_share_token" }) do |f| %>
<div class="card">
<div class="card-section">
<div class="form__wrapper">
<div class="card pt-4">
<div class="row column">
<label><%= t("share_tokens.form.token", scope: "decidim.admin") %></label>
<%= f.collection_radio_buttons :automatic_token, [
[t("share_tokens.form.automatic", scope: "decidim.admin"), true],
[t("share_tokens.form.custom", scope: "decidim.admin"), false]
], :last, :first do |b| %>
<div>
<%= b.label do %>
<%= b.radio_button %>
<%= b.text %>
<% end %>
</div>
<% end %>
<div id="token-field-wrapper" class="hidden">
<%= f.text_field :token, label: t("share_tokens.form.custom_token", scope: "decidim.admin"), style: "text-transform: uppercase" %>
</div>
</div>
<%= render partial: "form", object: f %>
</div>
<%= decidim_form_for(@form, url: share_tokens_path(:create), html: { class: "form-defaults form new_share_token" }) do |f| %>
<div class="card">
<div class="card-divider">
<h2 class="card-title">
<div class="flex--sbc">
<%= t ".title", name: resource_title %>
<%= link_to :back do %>
<%= icon "chevron-left", class: "icon--small", role: "img", "aria-hidden": true %>
<%= t("share_tokens.index.back_to_share_tokens", scope: "decidim.admin") %>
<% end %>
</div>
</div>
</h2>
</div>
<div class="item__edit-sticky">
<div class="item__edit-sticky-container">
<%= f.submit t(".create"), class: "button button__sm button__secondary" %>
<div class="card-section">
<div class="row column">
<label><%= t("share_tokens.form.token", scope: "decidim.admin") %></label>
<%= f.collection_radio_buttons :automatic_token, [
[t("share_tokens.form.automatic", scope: "decidim.admin"), true],
[t("share_tokens.form.custom", scope: "decidim.admin"), false]
], :last, :first do |b| %>
<div>
<%= b.radio_button %>
<%= b.label do %>
<%= b.text %>
<% end %>
</div>
<% end %>
<div id="token-field-wrapper" class="hide">
<%= f.text_field :token, label: t("share_tokens.form.custom_token", scope: "decidim.admin"), style: "text-transform: uppercase" %>
</div>
</div>
<%= render partial: "form", object: f %>
</div>
<% end %>
</div>
</div>

<div class="button--double form-general-submit">
<%= f.submit t(".create") %>
</div>
<% end %>

<script>
document.addEventListener("DOMContentLoaded", () => {
Expand All @@ -50,11 +48,11 @@

const toggleTokenField = () => {
if (automaticTokenRadioButton.checked) {
tokenWrapper.classList.add("hidden");
tokenWrapper.classList.add("hide");
tokenInput.value = "";
tokenInput.removeAttribute("required");
} else {
tokenWrapper.classList.remove("hidden");
tokenWrapper.classList.remove("hide");
tokenInput.focus();
}
};
Expand Down

0 comments on commit e8a4675

Please sign in to comment.