tududi/app/views/notes/_form.erb
2024-02-12 13:16:03 +02:00

62 lines
2.5 KiB
Text

<% form_action = note.new_record? ? '/note/create' : "/note/#{note.id}" %>
<% form_id ||= 'noteForm' %>
<% form_method = note.new_record? ? 'post' : 'patch' %>
<form id="<%= form_id %>" action="<%= form_action %>" method="post">
<% unless note.new_record? %>
<input type="hidden" name="_method" value="<%= form_method %>">
<% end %>
<fieldset>
<div class="row mb-3">
<div class="col-md-12">
<div class="input-group input-group-lg">
<input type="text" id="note_name_<%= note.id || 'new_' + context %>" name="title" value="<%= note.title %>" class="form-control" placeholder="+ Add Title" required>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-12">
<label for="note_project" class="form-label">Project (optional):</label>
<select id="note_project_<%= note.id || 'new_' + context %>" name="project_id" class="form-select">
<option value="">No Project</option>
<% current_user.projects.each do |project| %>
<option value="<%= project.id %>" <%= 'selected' if note.project_id == project.id %>><%= project.name %></option>
<% end %>
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-md-12">
<textarea rows="10" id="note_content_<%= note.id || 'new_' + context %>" name="content" class="form-control no-focus-outline" rows="5" placeholder="Note content..." required><%= note.content %></textarea>
</div>
</div>
<div class="row mb-3">
<div class="col-md-12">
<input name="tags" id="note_tags_<%= note.id || 'new_' + context %>" class="form-control" value="<%= note.tags&.map(&:name)&.join(',') %>" placeholder="Add Tags">
</div>
</div>
<div class="mt-4">
<button type="submit" class="btn btn-primary">
<%= note.new_record? ? 'Create Note' : 'Update Note' %>
</button>
<% unless note.new_record? %>
<button type="submit" class="btn btn-danger" onclick="deleteNote('<%= note.id %>')">
<i class="bi bi-trash"></i>
</button>
<% end %>
</div>
</fieldset>
</form>
<% if !note.new_record? %>
<form id="delete_note_<%= note.id %>" action="/note/<%= note.id %>" method="post" class="d-none">
<input type="hidden" name="_method" value="delete">
</form>
<% end %>
<script>
function deleteNote(noteId) {
if (confirm('Are you sure you want to delete this note?')) {
event.preventDefault();
var form = document.getElementById('delete_note_' + noteId);
form.submit();
}
}
</script>