diff options
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/nodes_controller.rb | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 494887d..1e1def2 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -33,17 +33,17 @@ class NodesController < ApplicationController | |||
| 33 | 33 | ||
| 34 | @node = Node.new | 34 | @node = Node.new |
| 35 | @node.parent_id = find_parent | 35 | @node.parent_id = find_parent |
| 36 | @node.slug = params[:title].parameterize.to_s | 36 | @node.slug = slug_for(params[:title]) |
| 37 | 37 | ||
| 38 | config = CccConventions::NODE_KINDS[params[:kind]] | ||
| 39 | |||
| 38 | if @node.save | 40 | if @node.save |
| 39 | @node.draft.update(:title => params[:title]) | 41 | @node.draft.update(:title => params[:title]) |
| 40 | case params[:kind] | 42 | Array(config && config[:tags]).each { |t| @node.draft.tag_list.add(t) } |
| 41 | when "update" | ||
| 42 | @node.draft.tag_list.add("update") | ||
| 43 | when "press_release" | ||
| 44 | @node.draft.tag_list.add("update", "pressemitteilung") | ||
| 45 | end | ||
| 46 | @node.draft.save! | 43 | @node.draft.save! |
| 44 | |||
| 45 | @node.update!(default_template_name: config[:template]) if config && config[:template] | ||
| 46 | |||
| 47 | redirect_to(edit_node_path(@node)) | 47 | redirect_to(edit_node_path(@node)) |
| 48 | else | 48 | else |
| 49 | render :new | 49 | render :new |
| @@ -103,9 +103,17 @@ class NodesController < ApplicationController | |||
| 103 | 103 | ||
| 104 | redirect_to node_path(@node) | 104 | redirect_to node_path(@node) |
| 105 | end | 105 | end |
| 106 | 106 | ||
| 107 | def parameterize_preview | ||
| 108 | render plain: slug_for(params[:title]) | ||
| 109 | end | ||
| 110 | |||
| 107 | private | 111 | private |
| 108 | 112 | ||
| 113 | def slug_for(title) | ||
| 114 | title.to_s.parameterize | ||
| 115 | end | ||
| 116 | |||
| 109 | def node_params | 117 | def node_params |
| 110 | params.fetch(:node, {}).permit(:slug, :parent_id, :staged_slug, :staged_parent_id) | 118 | params.fetch(:node, {}).permit(:slug, :parent_id, :staged_slug, :staged_parent_id) |
| 111 | end | 119 | end |
| @@ -120,18 +128,15 @@ class NodesController < ApplicationController | |||
| 120 | 128 | ||
| 121 | def find_parent | 129 | def find_parent |
| 122 | case params[:kind] | 130 | case params[:kind] |
| 123 | when "top_level" | ||
| 124 | Node.root.id | ||
| 125 | when "update" | ||
| 126 | Update.find_or_create_parent.id | ||
| 127 | when "press_release" | ||
| 128 | Update.find_or_create_parent.id | ||
| 129 | when "generic" | 131 | when "generic" |
| 130 | if params[:parent_id] && Node.find(params[:parent_id]) | 132 | if params[:parent_id] && Node.find(params[:parent_id]) |
| 131 | params[:parent_id] | 133 | params[:parent_id] |
| 132 | else | 134 | else |
| 133 | nil | 135 | nil |
| 134 | end | 136 | end |
| 137 | else | ||
| 138 | config = CccConventions::NODE_KINDS[params[:kind]] | ||
| 139 | config && config[:parent] ? config[:parent].call.id : nil | ||
| 135 | end | 140 | end |
| 136 | end | 141 | end |
| 137 | end | 142 | end |
