aboutsummaryrefslogtreecommitdiffstats
path: root/app/views/pdfresources/_form.html.erb
blob: a15bd67f4d073631e027e428f1bf68c2e2cc6ad9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<%= form_with(model: pdfresource, class: "contents") do |form| %>
  <% if pdfresource.errors.any? %>
    <div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
      <h2><%= pluralize(pdfresource.errors.count, "error") %> prohibited this pdfresource from being saved:</h2>

      <ul>
        <% pdfresource.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="my-5">
    <%= required_label_tag(form, :name) %>
    <%= form.text_field :name, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
  </div>

  <div class="my-5">
    <%= required_label_tag(form, :description) %>
    <%= form.textarea :description, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
    <p class="text-sm text-gray-700">Go to two with the description here. THIS WILL BE RICH TEXT.</p>
  </div>

  <div class="my-5">
    <%= required_label_tag(form, :card_description) %>
    <%= form.textarea :card_description, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
    <p class="text-sm text-gray-700">This is a much shorter description that is used inside the "card" boxes on the
      listings page.</p>
  </div>

  <div class="my-5">
    <%= required_label_tag(form, :pdfs) %>
    <% if pdfresource.pdfs.any? %>
      <div class="mb-4 p-4 bg-gray-50 rounded-lg">
        <h3 class="font-medium text-gray-700">Current PDFs:</h3>
        <ul class="list-disc ml-5 text-gray-600">
          <% pdfresource.pdfs.each do |pdf| %>
            <li><%= pdf.filename %></li>
          <% end %>
        </ul>
      </div>
    <% end %>
    <%= form.file_field :pdfs, multiple: true, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
    <p class="text-sm text-gray-700">
      <% if pdfresource.persisted? %>
        Upload new PDFs only if you want to replace the existing ones. Leave empty to keep current files.
      <% else %>
        You can upload up to 10 PDFs per resource.
      <% end %>
    </p>
  </div>

  <div class="my-5">
    <%= required_label_tag(form, :thumbnails) %>
    <% if pdfresource.thumbnails.any? && pdfresource.persisted? %>
      <div class="mb-4 p-4 bg-gray-50 rounded-lg">
        <h3 class="font-medium text-gray-700">Current Thumbnails:</h3>
        <div class="grid grid-cols-2 md:grid-cols-3 gap-4 mt-2">
          <% pdfresource.thumbnails.each do |thumbnail| %>
            <div class="relative">
              <% if thumbnail.persisted? %>
                <%= image_tag url_for(thumbnail), class: "rounded-lg shadow-sm" %>
                <p class="text-xs text-gray-500 mt-1"><%= thumbnail.filename %></p>
              <% end %>
            </div>
          <% end %>
        </div>
      </div>
    <% end %>
    <%= form.file_field :thumbnails, multiple: true, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
    <p class="text-sm text-gray-700">
      <% if pdfresource.persisted? %>
        Upload new thumbnails only if you want to replace the existing ones. Leave empty to keep current files.
      <% else %>
        You can upload up to 10 thumbnails per resource.
      <% end %>
    </p>
  </div>

  <div class="my-5">
    <%= form.label :price, class: "font-bold" %>
    <%= form.number_field :price, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
    <p class="text-sm text-gray-700">This is what we will sell it for!</p>
  </div>

  <div class="my-5">
    <%= required_label_tag(form, :credits) %>
    <%= form.number_field :credits, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
    <p class="text-sm text-gray-700">Number of credits required to purchase this resource.</p>
  </div>

  <div class="my-5">  
    <%= required_label_tag(form, :resource_type) %>
    <%= form.collection_select :resource_type_id, ResourceType.all, :id, :name, {}, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
  </div>

  <div class="my-5">
    <%= form.label :stripe_product_id, "Stripe Product ID", class: "font-bold" %>
    <%= form.text_field :stripe_product_id, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
  </div>

  <div class="my-5">
    <%= form.label :age_range, class: "font-bold" %>
    <%= form.text_field :age_range, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
  </div>

  <div class="my-5">
    <%= form.label :curriculum, class: "font-bold" %>
    <%= form.text_field :curriculum, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
  </div>

  <div class="my-5">
    <%= form.label :feature_slot, class: "font-bold" %>
    <%= form.number_field :feature_slot, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
  </div>

  <div class="flex gap-4 mt-8">
    <%= form.submit pdfresource.persisted? ? "Update" : "Create", 
        class: "bg-blue-500 hover:bg-blue-600 text-white font-semibold py-2 px-6 rounded-lg cursor-pointer" %>
    
    <%= link_to "Cancel", 
        pdfresource.persisted? ? pdfresource_path(pdfresource) : pdfresources_path, 
        class: "bg-gray-500 hover:bg-gray-600 text-white font-semibold py-2 px-6 rounded-lg" %>
  </div>
<% end %>