summaryrefslogtreecommitdiff
path: root/app/views/nodes/new.html.erb
blob: 1303e9ed6f302f1285be3265dc7e8a90300f7161 (plain)
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
<h1>Create new node</h1>

<% if @node.errors.any? %>
  <div class="error_messages">
    <ul><% @node.errors.full_messages.each do |msg| %><li><%= msg.to_s.gsub("Slug", "Title") %></li><% end %></ul>
  </div>
<% end %>

<%= form_tag nodes_path do %>
<div id="new_node">

  <div class="node_description">Type</div>
  <div class="node_content">
    <% CccConventions::NODE_KINDS.each do |kind, config| %>
      <p>
        <%= radio_button_tag :kind, kind, kind == @selected_kind,
          data: { path_prefix: resolve_kind_text(config[:path_prefix]) } %>
        <%= resolve_kind_text(config[:label]) %>
        <% if config[:hint] %>
          <span class="field_hint"><%= resolve_kind_text(config[:hint]) %></span>
        <% end %>
      </p>
    <% end %>
  </div>

  <div class="node_description">Title</div>
  <div class="node_content">
    <%= text_field_tag :title, nil, required: true %>
    <span class="field_hint">A URL slug will be generated from this automatically. You can review or adjust it afterward under the "metadata" section's Slug field.</span>
  </div>

  <div id="parent_search_field" style="<%= @selected_kind == "generic" ? "" : "display: none;" %>">
    <div class="node_description">Parent</div>
    <div class="node_content">
      <%= text_field_tag :parent_search_term, @parent&.title %>
      <%= hidden_field_tag :parent_id, @parent&.id, data: { unique_name: @parent&.computed_unique_name } %>
      <div id="parent_search_results" class="search_results"></div>
    </div>
  </div>

  <div class="node_description">Resulting path</div>
  <div class="node_content">
    <span id="resulting_path">—</span>
    <button type="button" id="copy_resulting_path" class="unselected copy_button" data-copy-target="#resulting_path">
      <span class="copy_button_label">copy</span>
    </button>

    <span class="field_hint">This preview updates as you type. The final path can still be changed afterward by editing the title (for the last segment) or moving the node to a different parent (for everything before it).</span>
  </div>

  <% if @attach_asset %>
    <div class="node_description">attachment</div>
    <div class="node_content">
      <ul class="thumbnail_list">
        <li>
          <% if @attach_asset.has_variant?(:thumb) %>
            <%= image_tag @attach_asset.upload.url(:thumb) %>
          <% end %>
          <%= link_to @attach_asset.name, asset_path(@attach_asset),
                :target => "_blank", :rel => "noopener" %>
        </li>
      </ul>
      <span class="field_hint">This asset will automatically be attached to the new page.</span>
      <label><%= check_box_tag :asset_headline, "1" %> as the page's headline</label>
      <%= hidden_field_tag :asset_id, @attach_asset.id %>
    </div>
  <% end %>

  <div class="node_description"></div>
  <div class="node_content"><%= submit_tag "Create" %></div>

</div>
<% end %>