diff --git a/app/controllers/emails_controller.rb b/app/controllers/emails_controller.rb index 7721089..7a5fed7 100644 --- a/app/controllers/emails_controller.rb +++ b/app/controllers/emails_controller.rb @@ -16,4 +16,17 @@ class EmailsController < ApplicationController @email.destroy redirect_to emails_url, notice: 'Email was successfully destroyed.' end + + def batch + case params[:batch_action] + when "mark_inbox" + Email.where(id: params[:ids]).update_all(inbox: true) + flash[:notice] = "#{helpers.pluralize(params[:ids].count,"email","emails")} have been marked « inbox »" + when "mark_not_inbox" + Email.where(id: params[:ids]).update_all(inbox: false) + flash[:notice] = "#{helpers.pluralize(params[:ids].count,"email","emails")} have been marked « not inbox »" + end + return_url = params[:return_url].presence || emails_url + redirect_to return_url + end end diff --git a/app/javascript/controllers/checkboxes_controller.js b/app/javascript/controllers/checkboxes_controller.js new file mode 100644 index 0000000..d901242 --- /dev/null +++ b/app/javascript/controllers/checkboxes_controller.js @@ -0,0 +1,14 @@ +import { Controller } from "stimulus" + +export default class extends Controller { + static targets = [ "checkboxesGroup", "checkboxesItem" ] + + syncCheckedState() { + this.checkboxesItemTargets.forEach((element, index) => { + element.checked = this.groupCheckedState + }) + } + get groupCheckedState() { + return this.checkboxesGroupTarget.checked + } +} diff --git a/app/views/emails/_list.html.erb b/app/views/emails/_list.html.erb index a323d7a..a03b2da 100644 --- a/app/views/emails/_list.html.erb +++ b/app/views/emails/_list.html.erb @@ -1,40 +1,51 @@ +<%= form_with url: batch_emails_url, method: :post, data: {"turbo-frame": "_top", controller: "checkboxes"} do |form| %> +
+ <%= check_box_tag "foo", "all", false, + class: "focus:ring-gray-500 h-4 w-4 text-gray-600 border-gray-300 rounded", + data: { action: "input->checkboxes#syncCheckedState", "checkboxes-target": "checkboxesGroup" } %> + | +Date | +From | +Subject | +Metadata | +
---|
Date | -From | -Subject | -Metadata | -
---|
- Showing - <%= @emails.offset_value + 1 %> - to - <%= @emails.offset_value + (@emails.respond_to?(:records) ? @emails.records : @emails.to_a).size %> - of - <%= @emails.total_count %> - results -
++ Showing + <%= @emails.offset_value + 1 %> + to + <%= @emails.offset_value + (@emails.respond_to?(:records) ? @emails.records : @emails.to_a).size %> + of + <%= @emails.total_count %> + results +
+