pulitzer 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/pulitzer.js +13 -4
  3. data/app/controllers/pulitzer/content_elements_controller.rb +3 -17
  4. data/app/controllers/pulitzer/post_tags_controller.rb +8 -8
  5. data/app/controllers/pulitzer/posts_controller.rb +4 -2
  6. data/app/controllers/pulitzer/versions_controller.rb +13 -4
  7. data/app/helpers/pulitzer/posts_helper.rb +1 -5
  8. data/app/interactions/pulitzer/clone_version.rb +22 -3
  9. data/app/interactions/pulitzer/create_post_tag.rb +6 -8
  10. data/app/interactions/pulitzer/update_version_status.rb +5 -1
  11. data/app/models/pulitzer/content_element.rb +4 -3
  12. data/app/models/pulitzer/post.rb +17 -1
  13. data/app/models/pulitzer/version.rb +11 -1
  14. data/app/validators/pulitzer/content_element_validator.rb +24 -0
  15. data/app/views/pulitzer/content_elements/_form.html.erb +1 -1
  16. data/app/views/pulitzer/content_elements/_index.html.erb +20 -0
  17. data/app/views/pulitzer/content_elements/{index_processing.html.erb → _index_processing.html.erb} +0 -0
  18. data/app/views/pulitzer/content_elements/_new.html.erb +6 -6
  19. data/app/views/pulitzer/content_elements/_show.html.erb +1 -1
  20. data/app/views/pulitzer/content_elements/_show_wrapper.html.erb +2 -2
  21. data/app/views/pulitzer/post_tags/_new.html.erb +3 -3
  22. data/app/views/pulitzer/post_tags/_show.html.erb +3 -3
  23. data/app/views/pulitzer/post_tags/_show_wrapper.html.erb +1 -1
  24. data/app/views/pulitzer/posts/_show.html.erb +1 -1
  25. data/app/views/pulitzer/posts/edit.html.erb +10 -0
  26. data/app/views/pulitzer/versions/_edit.html.erb +41 -0
  27. data/app/views/pulitzer/versions/_form.html.erb +2 -9
  28. data/config/routes.rb +6 -2
  29. data/db/migrate/20160122204201_add_errors_to_version.rb +5 -0
  30. data/lib/pulitzer/version.rb +1 -1
  31. data/spec/dummy/db/development.sqlite3 +0 -0
  32. data/spec/dummy/db/schema.rb +3 -7
  33. data/spec/dummy/db/test.sqlite3 +0 -0
  34. data/spec/dummy/log/test.log +7574 -0
  35. data/spec/dummy/public/uploads/tmp/1453739521-68535-5576/cms_sam_and_snow.jpg +0 -0
  36. data/spec/dummy/public/uploads/tmp/1453739521-68535-5576/sam_and_snow.jpg +0 -0
  37. data/spec/dummy/public/uploads/tmp/1453739521-68535-5576/thumb_sam_and_snow.jpg +0 -0
  38. data/spec/dummy/public/uploads/tmp/1453739650-68698-8068/cms_sam_and_snow.jpg +0 -0
  39. data/spec/dummy/public/uploads/tmp/1453739650-68698-8068/sam_and_snow.jpg +0 -0
  40. data/spec/dummy/public/uploads/tmp/1453739650-68698-8068/thumb_sam_and_snow.jpg +0 -0
  41. data/spec/dummy/public/uploads/tmp/1453740957-70195-5923/cms_sam_and_snow.jpg +0 -0
  42. data/spec/dummy/public/uploads/tmp/1453740957-70195-5923/sam_and_snow.jpg +0 -0
  43. data/spec/dummy/public/uploads/tmp/1453740957-70195-5923/thumb_sam_and_snow.jpg +0 -0
  44. data/spec/dummy/public/uploads/tmp/1453741054-70338-5984/cms_sam_and_snow.jpg +0 -0
  45. data/spec/dummy/public/uploads/tmp/1453741054-70338-5984/sam_and_snow.jpg +0 -0
  46. data/spec/dummy/public/uploads/tmp/1453741054-70338-5984/thumb_sam_and_snow.jpg +0 -0
  47. data/spec/dummy/public/uploads/tmp/1453741100-70403-3570/cms_sam_and_snow.jpg +0 -0
  48. data/spec/dummy/public/uploads/tmp/1453741100-70403-3570/sam_and_snow.jpg +0 -0
  49. data/spec/dummy/public/uploads/tmp/1453741100-70403-3570/thumb_sam_and_snow.jpg +0 -0
  50. data/spec/dummy/public/uploads/tmp/1453741119-70445-1368/cms_sam_and_snow.jpg +0 -0
  51. data/spec/dummy/public/uploads/tmp/1453741119-70445-1368/sam_and_snow.jpg +0 -0
  52. data/spec/dummy/public/uploads/tmp/1453741119-70445-1368/thumb_sam_and_snow.jpg +0 -0
  53. data/spec/dummy/public/uploads/tmp/1453741152-70510-7020/cms_sam_and_snow.jpg +0 -0
  54. data/spec/dummy/public/uploads/tmp/1453741152-70510-7020/sam_and_snow.jpg +0 -0
  55. data/spec/dummy/public/uploads/tmp/1453741152-70510-7020/thumb_sam_and_snow.jpg +0 -0
  56. data/spec/dummy/public/uploads/tmp/1453741165-70539-8838/cms_sam_and_snow.jpg +0 -0
  57. data/spec/dummy/public/uploads/tmp/1453741165-70539-8838/sam_and_snow.jpg +0 -0
  58. data/spec/dummy/public/uploads/tmp/1453741165-70539-8838/thumb_sam_and_snow.jpg +0 -0
  59. data/spec/dummy/public/uploads/tmp/1453741192-70601-8114/cms_sam_and_snow.jpg +0 -0
  60. data/spec/dummy/public/uploads/tmp/1453741192-70601-8114/sam_and_snow.jpg +0 -0
  61. data/spec/dummy/public/uploads/tmp/1453741192-70601-8114/thumb_sam_and_snow.jpg +0 -0
  62. data/spec/dummy/public/uploads/tmp/1453741252-70701-6629/cms_sam_and_snow.jpg +0 -0
  63. data/spec/dummy/public/uploads/tmp/1453741252-70701-6629/sam_and_snow.jpg +0 -0
  64. data/spec/dummy/public/uploads/tmp/1453741252-70701-6629/thumb_sam_and_snow.jpg +0 -0
  65. data/spec/interactions/clone_version_spec.rb +2 -0
  66. data/spec/models/content_element_spec.rb +0 -2
  67. data/spec/models/version_spec.rb +1 -1
  68. metadata +130 -9
  69. data/app/views/pulitzer/content_elements/index.html.erb +0 -39
  70. data/app/views/pulitzer/posts/show.html.erb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 914de466646e5388348244b27b726863885e4f5d
4
- data.tar.gz: 4044a0f17a04fbe7c4f4ab18b727338230a01d6e
3
+ metadata.gz: 9fb47ff0580548ffe9a35433a77ee4ac57e8d070
4
+ data.tar.gz: 0f6099bbf1a457a725f8cd5dcf9c3e89c498349e
5
5
  SHA512:
6
- metadata.gz: 451c86d52fb63970c8bc98317ae84d406c751915da9d8b5c850e0c6147f2e667f0465d329cd89aa0500d802f1a7412966f1fb54785fdbfc4f45e1fd25a817fe8
7
- data.tar.gz: ae95ee1c85a3c2cec45cf92627101285efbed756cc793ecb8f590760f0c4eb9d79a633a429c228b693bdab4b1e36f50d36632e2af7a5e10a1e5c9888869dbf97
6
+ metadata.gz: e004f415446e6fbe37075e8a7da3934755b1398ca1249e76fc1d8af8a8285238f7fbb581184311e4e09366a2c46e8ffd1659d3fcbbef37792719d3866d5e7e73
7
+ data.tar.gz: 687eded1e2a0f063412e75911b31e320fc7df1541aa783f32fe6ab46c97fba3d1b035801068440b50c91513379b970c74f0ef3406f677e90afef7457642c5ceb
@@ -28,10 +28,11 @@ var Select2Trigger = Class.extend({
28
28
 
29
29
  var RichTextEditor = Class.extend({
30
30
  init: function($textarea){
31
- self.$form = $textarea.parents("form");
32
- self.$toolbar = self.$form.find('[data-pulitzer-toolbar]');
33
- self.editor = new wysihtml5.Editor($textarea[0], {
34
- toolbar: self.$toolbar[0],
31
+ var rich_text_editor = this
32
+ this.$form = $textarea.parents("form")
33
+ this.$toolbar = this.$form.find('[data-pulitzer-toolbar]')
34
+ this.editor = new wysihtml5.Editor($textarea[0], {
35
+ toolbar: rich_text_editor.$toolbar[0],
35
36
  stylesheets: wysihtml5Stylesheets,
36
37
  parserRules: wysihtml5ParserRules
37
38
  });
@@ -54,6 +55,14 @@ var ContentElementEditor = Class.extend({
54
55
  }
55
56
  })
56
57
 
58
+ $(document).ajaxComplete(function(){
59
+ $.each(window.any_time_manager.recordedObjects["RichTextEditor"], function(){
60
+ if(this.$form.parents('body').length == 0){ //the form has been removed from the dom
61
+ this.editor.fire('destroy:composer')
62
+ }
63
+ })
64
+ })
65
+
57
66
  $(document).ready(function(){
58
67
  // window.any_time_manager.registerListWithClasses(
59
68
  // { 'pulitzer-element' : 'ContentElementEditor'}
@@ -1,29 +1,15 @@
1
1
  class Pulitzer::ContentElementsController < Pulitzer::ApplicationController
2
2
  before_filter :set_content_element, only: [:show, :edit, :update]
3
3
 
4
- def index
5
- @post = Pulitzer::Post.find(params[:post_id])
6
- if @post.preview_version
7
- @content_elements = @post.preview_version.template_content_elements
8
- @free_form_content_elements = @post.preview_version.free_form_content_elements
9
- route = "pulitzer_preview_#{@post.post_type.name.parameterize('_')}_path"
10
- @preview_path = main_app.public_send(route, @post.slug) if main_app.respond_to?(route)
11
- elsif @post.processing_version
12
- render template: '/pulitzer/content_elements/index_processing' and return
13
- else
14
- render text: "There is a problem with this post", status: 404
15
- end
16
- end
17
-
18
4
  def new
19
- @version = Pulitzer::Version.find params[:version_id]
20
- @content_element = @version.content_elements.build
5
+ @version = Pulitzer::Version.find params[:version_id]
6
+ @content_element = @version.content_elements.build
21
7
  render partial: 'new', locals: { content_element: @content_element, version: @version }
22
8
  end
23
9
 
24
10
  def create
25
11
  @version = Pulitzer::Version.find content_element_params[:version_id]
26
- @content_element = @version.content_elements.create content_element_params
12
+ @content_element = @version.content_elements.create content_element_params.merge(ensure_unique: true)
27
13
  render partial: 'show_wrapper', locals: { content_element: @content_element }
28
14
  end
29
15
 
@@ -1,19 +1,19 @@
1
1
  class Pulitzer::PostTagsController < Pulitzer::ApplicationController
2
- before_filter :get_post, only: [:new, :create, :destroy]
2
+ before_filter :get_post_tag, only: [:destroy]
3
3
 
4
4
  def new
5
5
  @tag_model = params[:tag_model]
6
- @post_tag = @post.preview_version.post_tags.new
7
- render partial: 'new', locals: { post: @post, tag_model: @tag_model, post_tag: @post_tag }
6
+ @version = Pulitzer::Version.find params[:version_id]
7
+ @post_tag = @version.post_tags.new label_type: @tag_model
8
+ render partial: 'new', locals: { tag_model: @tag_model, post_tag: @post_tag }
8
9
  end
9
10
 
10
11
  def create
11
- @post_tag = Pulitzer::CreatePostTag.new(@post, params).call
12
- render partial: 'show', locals: { post: @post, tag_model: @post_tag.label_type }
12
+ @post_tag = Pulitzer::CreatePostTag.new(params).call
13
+ render partial: 'show', locals: { version: @post_tag.version, tag_model: @post_tag.label_type }
13
14
  end
14
15
 
15
16
  def destroy
16
- @post_tag = @post.preview_version.post_tags.find params[:id]
17
17
  @post_tag.destroy
18
18
  render nothing: true
19
19
  end
@@ -24,8 +24,8 @@ class Pulitzer::PostTagsController < Pulitzer::ApplicationController
24
24
  params[:post_tag].permit!
25
25
  end
26
26
 
27
- def get_post
28
- @post = Pulitzer::Post.find(params[:post_id])
27
+ def get_post_tag
28
+ @post_tag = Pulitzer::PostTag.find(params[:id])
29
29
  end
30
30
 
31
31
  end
@@ -1,5 +1,5 @@
1
1
  class Pulitzer::PostsController < Pulitzer::ApplicationController
2
- before_filter :get_post, only: [:show, :edit, :update]
2
+ before_filter :get_post, only: [:show, :edit, :update, :processing_preview]
3
3
 
4
4
  def index
5
5
  @post_type = Pulitzer::PostType.find params[:post_type_id]
@@ -22,7 +22,9 @@ class Pulitzer::PostsController < Pulitzer::ApplicationController
22
22
  end
23
23
 
24
24
  def edit
25
- render partial: 'form', locals: { post: @post }
25
+ if request.xhr?
26
+ render partial: 'form', locals: { post: @post }
27
+ end
26
28
  end
27
29
 
28
30
  def update
@@ -1,17 +1,26 @@
1
1
  class Pulitzer::VersionsController < Pulitzer::ApplicationController
2
2
  before_action :set_version
3
3
 
4
+ def edit
5
+ if @version.preview?
6
+ route = "pulitzer_preview_#{@post.post_type.name.parameterize('_')}_path"
7
+ @preview_path = main_app.public_send(route, @post.slug) if main_app.respond_to?(route)
8
+ end
9
+ render_ajax locals: {version: @version}
10
+ end
11
+
4
12
  def update
5
- Pulitzer::UpdateVersionStatus.new(@version,@status).call
13
+ processing_version = Pulitzer::UpdateVersionStatus.new(@version,@status).call
6
14
 
7
- redirect_to post_content_elements_path(@post), notice: "Post #{@status}"
15
+ render json: {html: render_to_string(partial: '/pulitzer/versions/edit', locals: {version: processing_version}),
16
+ flash_message: "The new version of #{@post.title} has been activated."}
8
17
  end
9
18
 
10
19
  private
11
20
  def set_version
12
21
  @version = Pulitzer::Version.find params[:id]
13
- @post = @version.post
14
- @status = params[:status].to_sym
22
+ @status = params[:status]
23
+ @post = @version.post
15
24
  end
16
25
 
17
26
  end
@@ -40,11 +40,7 @@ module Pulitzer
40
40
  end
41
41
 
42
42
  def select2_html_options(tag_model)
43
- if tag_model == "Pulitzer::Tag"
44
- { class: 'seletct2-pulitzer-tags', data: { select2_trigger: true } }
45
- else
46
- { }
47
- end
43
+ { class: 'seletct2-pulitzer-tags', data: { select2_trigger: true } }
48
44
  end
49
45
  end
50
46
  end
@@ -1,24 +1,43 @@
1
1
  class Pulitzer::CloneVersion
2
+ include Pulitzer::Engine.routes.url_helpers
2
3
 
3
4
  def initialize(version)
4
5
  @version = version
5
6
  @post = @version.post
7
+ Rails.logger.info("Pulitzer::CloneVersion !!! ")
8
+ Rails.logger.info($0)
6
9
  end
7
10
 
8
11
  def call
9
- new_version = @post.create_processing_version
12
+ new_version = @post.processing_version
13
+ cloning_errors = []
14
+ new_version.processed_element_count = 0
10
15
  @version.content_elements.each do |ce|
11
16
  begin
12
17
  cloned_content_element = ce.clone_me
13
18
  new_version.content_elements << cloned_content_element
14
19
  rescue ActiveRecord::RecordInvalid => invalid
15
- new_version.errors.add(:base, "ContentElement #{ce.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}")
20
+ cloning_errors.push "ContentElement #{ce.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}"
16
21
  end
22
+ new_version.processed_element_count += 1
23
+ new_version.broadcast_change if defined? ForeignOffice
17
24
  end
18
25
  @version.post_tags.each do |pt|
19
26
  new_version.post_tags << pt.clone_me
27
+ new_version.processed_element_count += 1
28
+ new_version.broadcast_change if defined? ForeignOffice
20
29
  end
21
- new_version.update(status: :preview)
30
+ if cloning_errors.any?
31
+ new_version.update(status: :processing_failed, cloning_errors: cloning_errors)
32
+ else
33
+ new_version.update(status: :preview)
34
+ new_version.processed_element_count += 1
35
+ new_version.broadcast_change if defined? ForeignOffice
36
+ end
37
+ @post.new_preview_version = edit_version_path(new_version)
38
+ new_version.processed_element_count += 1
39
+ new_version.broadcast_change if defined? ForeignOffice
40
+ @post.broadcast_change if defined? ForeignOffice
22
41
  new_version
23
42
  end
24
43
 
@@ -1,21 +1,19 @@
1
1
  class Pulitzer::CreatePostTag
2
- attr_accessor :post, :request_params
3
2
 
4
- def initialize(post, params)
5
- self.post = post
6
- self.request_params = params
3
+ def initialize(params)
4
+ @request_params = params
7
5
  end
8
6
 
9
7
  def call
10
- label_id = request_params[:post_tag][:label_id]
8
+ label_id = post_tag_params[:label_id]
11
9
  unless (Integer(label_id) rescue false)
12
10
  tag = Pulitzer::Tag.where(name: label_id).first_or_create
13
- request_params[:post_tag][:label_id] = tag.id
11
+ @request_params[:post_tag][:label_id] = tag.id
14
12
  end
15
- post.preview_version.post_tags.create post_tag_params
13
+ Pulitzer::PostTag.create post_tag_params
16
14
  end
17
15
 
18
16
  def post_tag_params
19
- request_params[:post_tag].permit!
17
+ @request_params[:post_tag].permit!
20
18
  end
21
19
  end
@@ -3,6 +3,7 @@ class Pulitzer::UpdateVersionStatus
3
3
  @transitional_version = version
4
4
  @status = status
5
5
  @status_change_method = 'make_version_' + @status.to_s
6
+ @post = version.post
6
7
  end
7
8
 
8
9
  def call
@@ -14,14 +15,17 @@ class Pulitzer::UpdateVersionStatus
14
15
  @old_active_version = @new_active_version.post.active_version
15
16
  @new_active_version.update(status: :active)
16
17
  @old_active_version.update(status: :archived) if @old_active_version
18
+ @processing_version = @post.create_processing_version
17
19
  Pulitzer::CloneVersionJob.perform_later(@new_active_version)
18
- @new_active_version
20
+ @processing_version
19
21
  end
20
22
 
21
23
  def make_version_abandoned
22
24
  @active_version = @transitional_version.post.active_version
23
25
  @transitional_version.update(status: :abandoned)
26
+ @processing_version = @post.create_processing_version
24
27
  Pulitzer::CloneVersionJob.perform_later(@active_version)
28
+ @processing_version
25
29
  end
26
30
 
27
31
  end
@@ -10,10 +10,10 @@ module Pulitzer
10
10
  delegate :type, :text_type?, :image_type?, :video_type?, to: :content_element_type
11
11
  delegate :post, to: :version
12
12
 
13
- attr_accessor :version_unavailable
13
+ attr_accessor :version_unavailable, :ensure_unique
14
14
 
15
15
  # Validations
16
- validates :label, presence: true, uniqueness: { scope: :version_id }, unless: :free_form?
16
+ validates_with ContentElementValidator
17
17
 
18
18
  # Callbacks
19
19
  before_save :handle_sort_order
@@ -51,6 +51,7 @@ module Pulitzer
51
51
  clone_attrs.delete 'version_id'
52
52
 
53
53
  type_clone_method = 'clone_' + type.to_s
54
+
54
55
  if respond_to? type_clone_method
55
56
  my_clone = send type_clone_method, clone_attrs
56
57
  else
@@ -67,7 +68,7 @@ module Pulitzer
67
68
  # If there is an error getting the image, don't bail out,
68
69
  # create the content element clone without the image so the user can reupload later
69
70
  if !my_clone.valid?
70
- if my_clone.errors.get(:image).any?
71
+ if my_clone.errors.get(:image)
71
72
  my_clone = Pulitzer::ContentElement.new(clone_attrs)
72
73
  end
73
74
  end
@@ -1,13 +1,16 @@
1
1
  module Pulitzer
2
2
  class Post < ActiveRecord::Base
3
+ include ForeignOffice::Broadcaster if defined? ForeignOffice
3
4
  extend ::FriendlyId
4
5
  has_many :versions
5
6
  belongs_to :post_type
6
- delegate :post_type_content_element_types, to: :post_type
7
+ delegate :post_type_content_element_types, :allow_free_form?, to: :post_type
7
8
  delegate :content_elements, :post_tags, to: :active_version, allow_nil: true
8
9
  friendly_id :title, use: [:slugged, :finders]
9
10
  after_create :create_preview_version
10
11
 
12
+ attr_accessor :new_preview_version
13
+
11
14
  validates :title, presence: true
12
15
 
13
16
  TAG_MODELS = ["Pulitzer::Tag"] + Pulitzer.tagging_models
@@ -32,6 +35,14 @@ module Pulitzer
32
35
  versions.processing.last
33
36
  end
34
37
 
38
+ def processing_failed_version
39
+ versions.processing_failed.last
40
+ end
41
+
42
+ def next_version
43
+ preview_version || processing_version || processing_failed_version
44
+ end
45
+
35
46
  def create_preview_version
36
47
  versions.create(status: :preview)
37
48
  end
@@ -39,5 +50,10 @@ module Pulitzer
39
50
  def create_processing_version
40
51
  versions.create(status: :processing)
41
52
  end
53
+
54
+ def serialize
55
+ self.attributes.merge \
56
+ new_preview_version: self.new_preview_version
57
+ end
42
58
  end
43
59
  end
@@ -1,10 +1,15 @@
1
1
  module Pulitzer
2
2
  class Version < ActiveRecord::Base
3
- enum status: [ :preview, :active, :archived, :abandoned, :processing ]
3
+ include ForeignOffice::Broadcaster if defined? ForeignOffice
4
+ enum status: [ :preview, :active, :archived, :abandoned, :processing, :processing_failed ]
4
5
  has_many :content_elements, dependent: :destroy
5
6
  has_many :post_tags, dependent: :destroy
6
7
  belongs_to :post
7
8
 
9
+ attr_accessor :processed_element_count
10
+
11
+ delegate :allow_free_form?, :title, to: :post
12
+
8
13
  validates :post_id, :status, presence: true
9
14
 
10
15
  def content_element(label)
@@ -18,5 +23,10 @@ module Pulitzer
18
23
  def free_form_content_elements
19
24
  content_elements.free_form
20
25
  end
26
+
27
+ def serialize
28
+ self.attributes.merge \
29
+ processed_element_count: self.processed_element_count
30
+ end
21
31
  end
22
32
  end
@@ -0,0 +1,24 @@
1
+ module Pulitzer
2
+ class ContentElementValidator < ActiveModel::Validator
3
+ attr_accessor :record
4
+
5
+ def validate(record)
6
+ self.record = record
7
+ validate_label_presence
8
+ validate_lable_uniqueness if record.ensure_unique
9
+ end
10
+
11
+ private
12
+
13
+ def validate_label_presence
14
+ record.errors.add(:label, "is required.") unless record.label.present?
15
+ end
16
+
17
+ def validate_label_uniqueness
18
+ if record.version && record.version.content_elements.to_a.reject{|ce| ce == record}.any?{|ce| ce.label == record.label}
19
+ record.errors.add(:label, "is already taken.")
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -4,7 +4,7 @@
4
4
  <%= form_for content_element, html: ajax_form_hash(dom_target(content_element)), multipart: true,
5
5
  data: { server_endpoint: content_element_path(content_element) } do |f| %>
6
6
  <%= f.text_field :title, placeholder: 'Title' %>
7
- <%= render partial: "#{content_element.type}_fields", locals: { f: f, content_element: content_element } %>
7
+ <%= render partial: "/pulitzer/content_elements/#{content_element.type}_fields", locals: { f: f, content_element: content_element } %>
8
8
  <%= submit_tag "Update" %>
9
9
  <%= link_to('Cancel', content_element_path(content_element), :class => 'button',
10
10
  data: { ajax_link: true, ajax_target: dom_target(content_element) } ) %>
@@ -0,0 +1,20 @@
1
+ <h2>Template content elements</h2>
2
+
3
+ <% version.template_content_elements.each do |content_element| %>
4
+ <%= render partial: '/pulitzer/content_elements/show_wrapper', locals: { content_element: content_element } %>
5
+ <% end %>
6
+
7
+ <% if version.allow_free_form? %>
8
+ <div id="<%= dom_id version, :free_form_elements %>">
9
+ <h2>Free form content elements</h2>
10
+ <div class="pulitzer-row margin-bottom list-item">
11
+ <%= ajax_link "add a new content element for #{version.title}", new_content_element_path(version_id: version), {}, "#new_free_form_content_element_#{dom_id(version)}" %>
12
+ <div id="<%= dom_id(version, :new_free_form_content_element) %>"></div>
13
+ </div>
14
+ <div class="pulitzer-row margin-bottom list-item" id="<%= dom_id(version, :free_form_content_element_container) %>" id="content_element_list" data-sorter href="<%= update_all_content_elements_path %>">
15
+ <% version.free_form_content_elements.each do |content_element| %>
16
+ <%= render partial: '/pulitzer/content_elements/show_wrapper', locals: { content_element: content_element } %>
17
+ <% end %>
18
+ </div>
19
+ </div>
20
+ <% end %>
@@ -1,17 +1,17 @@
1
- <%= form_for content_element, html: ajax_form_hash("#version_content_element_container_#{dom_id(version)}", insert_method: 'append', sub_class: "AddALineForm", container: "#new_version_content_element_#{dom_id(version)}") do |f| %>
1
+ <%= form_for content_element, html: ajax_form_hash(dom_target(version, :free_form_content_element_container), insert_method: 'append', sub_class: "AddALineForm", container: dom_target(version, :new_free_form_content_element)) do |f| %>
2
2
  <%= f.collection_select :content_element_type_id, Pulitzer::ContentElementType.all, :id, :name, {},
3
- { data: { "revealer" => true, "sub-type" => "FormFieldRevealer", "revealer-children-id" => dom_id(version, :revealer) }} %>
3
+ revealer(dom_id(version, :content_element_type_revealer), highlander: true) %>
4
4
 
5
- <div data-revealer-target="<%= dom_id(version, :revealer) %>"></div>
5
+ <div <%= revealer_target_attrs dom_id(version, :content_element_type_revealer) %>></div>
6
6
 
7
- <div data-revealer_id="<%= dom_id(version, :revealer) %>" data-revealer-triggers="['<%= Pulitzer::ContentElementType.find_by(name: 'Image').id %>']">
7
+ <div <%= revealer_option_attrs(dom_id(version, :content_element_type_revealer), trigger: Pulitzer::ContentElementType.find_by(name: 'Image').id) %> >
8
8
  <%= f.label :height %>
9
9
  <%= f.text_field :height, placeholder: 'Height' %>
10
10
  <%= f.label :width %>
11
11
  <%= f.text_field :width, placeholder: 'Width' %>
12
12
  </div>
13
13
 
14
- <div data-revealer_id="<%= dom_id(version, :revealer) %>" data-revealer-triggers="['<%= Pulitzer::ContentElementType.find_by(name: 'Text').id %>']">
14
+ <div <%= revealer_option_attrs(dom_id(version, :content_element_type_revealer), trigger: Pulitzer::ContentElementType.find_by(name: 'Text').id) %>>
15
15
  <%= f.label :text_editor, "Text editor" %>
16
16
  <%= f.select :text_editor, Pulitzer.text_editor_toolbars.map { |t| t[:name] } %>
17
17
  </div>
@@ -21,5 +21,5 @@
21
21
 
22
22
  <%= submit_tag "Create" %>
23
23
  <%= link_to('Cancel', '#', :class => 'button',
24
- data: { emptier: true, target: "#new_version_content_element_#{dom_id(version)}" } ) %>
24
+ data: { emptier: true, target: dom_target(version, :new_free_form_content_element) } ) %>
25
25
  <% end %>
@@ -11,6 +11,6 @@
11
11
  <li><h3><%= content_element.label %></h3></li>
12
12
  <% end %>
13
13
  <li><%= render_element(content_element) %></li>
14
- <li><%= ajax_link "Edit", edit_post_content_element_path(content_element.post, content_element), {}, dom_target(content_element) %></li>
14
+ <li><%= ajax_link "Edit", edit_content_element_path(content_element), {}, dom_target(content_element) %></li>
15
15
  </ul>
16
16
  </div>
@@ -1,7 +1,7 @@
1
1
  <div class="pulitzer-row margin-bottom list-item" id="<%= dom_id(content_element) %>">
2
2
  <% if content_element.empty_body? %>
3
- <%= render partial: 'form', locals: { content_element: content_element } %>
3
+ <%= render partial: '/pulitzer/content_elements/form', locals: { content_element: content_element } %>
4
4
  <% else %>
5
- <%= render partial: 'show', locals: { content_element: content_element } %>
5
+ <%= render partial: '/pulitzer/content_elements/show', locals: { content_element: content_element } %>
6
6
  <% end %>
7
7
  </div>
@@ -1,8 +1,8 @@
1
- <%= form_for post_tag, url: post_post_tags_path(post), html: ajax_form_hash("#show_#{underscore_class_name(tag_model)}") do |f| %>
1
+ <%= form_for post_tag, html: ajax_form_hash("#show_#{underscore_class_name(tag_model)}") do |f| %>
2
2
  <%= f.label :name %>
3
3
  <%= f.select :label_id, options_from_collection_for_select(tag_model.constantize.all, :id, :name), {}, select2_html_options(tag_model) %>
4
- <%= f.hidden_field :version_id, value: post.preview_version.id %>
5
- <%= f.hidden_field :label_type, value: tag_model %>
4
+ <%= f.hidden_field :version_id %>
5
+ <%= f.hidden_field :label_type %>
6
6
  <%= f.submit "Create" %>
7
7
  <%= link_to('Cancel', '#', class: 'button',
8
8
  data: { emptier: true, target: "#new_tag_#{underscore_class_name(tag_model)}" } ) %>
@@ -1,11 +1,11 @@
1
1
  <h3><%= humanize_class_name(tag_model).pluralize %></h3>
2
- <% post.preview_version.post_tags.where(label_type: tag_model).each do |post_tag| %>
2
+ <% version.post_tags.where(label_type: tag_model).each do |post_tag| %>
3
3
  <ul class='inline-list' id="<%= dom_id(post_tag) %>">
4
4
  <li><%= post_tag.label.name %></li>
5
- <li><%= ajax_delete 'delete', post_post_tag_path(post, post_tag), {}, dom_target(post_tag) %></li>
5
+ <li><%= ajax_delete 'delete', post_tag_path(post_tag), {}, dom_target(post_tag) %></li>
6
6
  </ul>
7
7
  <% end %>
8
8
 
9
- <%= ajax_link "Add a new #{humanize_class_name(tag_model)}", new_post_post_tag_path(post, tag_model: tag_model), {}, "#new_tag_#{underscore_class_name(tag_model)}" %>
9
+ <%= ajax_link "Add a new #{humanize_class_name(tag_model)}", new_post_tag_path(version_id: version.id, tag_model: tag_model), {}, "#new_tag_#{underscore_class_name(tag_model)}" %>
10
10
 
11
11
  <div id="new_tag_<%= underscore_class_name(tag_model) %>"></div>
@@ -1,3 +1,3 @@
1
1
  <div class="pulitzer-row margin-bottom margin-left" id="show_<%= underscore_class_name(tag_model) %>">
2
- <%= render partial: 'pulitzer/post_tags/show', locals: { tag_model: tag_model, post: post } %>
2
+ <%= render partial: 'pulitzer/post_tags/show', locals: { tag_model: tag_model, version: version } %>
3
3
  </div>
@@ -4,7 +4,7 @@
4
4
  <%= ajax_link post.title, edit_post_path(post), {}, dom_target(post) %>
5
5
  </li>
6
6
  <li>
7
- <%= link_to 'edit', post_content_elements_path(post) %>
7
+ <%= link_to 'edit', edit_post_path(post) %>
8
8
  </li>
9
9
  </ul>
10
10
  </div>
@@ -0,0 +1,10 @@
1
+ <h1>Editing <%= @post.title %></h1>
2
+
3
+ <div class="pulitzer-row margin-bottom list-item">
4
+ <%= link_back_to_posts(@post.post_type, "Back to #{@post.post_type.name.singularize} Posts", 'Back to post types') %>
5
+ </div>
6
+
7
+ <div id="<%= dom_id(@post, :preview_version)%>">
8
+ </div>
9
+ <%= ajax_link_now '', edit_version_path(@post.next_version), {}, dom_target(@post, :preview_version) %>
10
+
@@ -0,0 +1,41 @@
1
+ <% if version.processing_failed? %>
2
+ <div class="pulitzer-row">
3
+ There was a problem creating the new preview version of this post for editing.
4
+ <ul>
5
+ <% version.cloning_errors.each do |error| %>
6
+ <li><%= error %></li>
7
+ <% end %>
8
+ </ul>
9
+ </div>
10
+ <% elsif version.processing? %>
11
+ <h2> Processing Preview for <%= version.title %> </h2>
12
+ <div class="pulitzer-row">
13
+ <progress value="0" max="<%= version.post.active_version.content_elements.count + version.post.active_version.post_tags.count + 2 %>" <%= listener_attrs version, :processed_element_count if defined? ForeignOffice %>></progress>
14
+ </div>
15
+ <a <%= listener_attrs version.post, :new_preview_version, trigger: true if defined? ForeignOffice %>
16
+ <%= ajax_link_attrs(dom_target(version.post, :preview_version)) %> > </a>
17
+ If the preview does not appear within a few minutes, click here to see if it's available.
18
+ <%= ajax_link "refresh preview", edit_version_path(version), {}, dom_target(version.post, :preview_version) %>
19
+ <% elsif version.preview? %>
20
+ <div class="pulitzer-row margin-bottom list-item">
21
+ <h2>Tags</h2>
22
+ <% Pulitzer::Post::TAG_MODELS.each do |tag_model| %>
23
+ <%= render partial: 'pulitzer/post_tags/show_wrapper', locals: { version: version, tag_model: tag_model } %>
24
+ <% end %>
25
+ </div>
26
+
27
+ <div class="pulitzer-row margin-bottom list-item">
28
+ <%= render partial: '/pulitzer/content_elements/index', locals: {version: version} %>
29
+ </div>
30
+
31
+ <div class="pulitzer-row">
32
+ <%= render partial: 'pulitzer/versions/form', locals: { version: version } %>
33
+ </div>
34
+ <div class="preview-link">
35
+ <% if @preview_path %>
36
+ <%= link_to "Preview", @preview_path, target: '_blank' %>
37
+ <% else %>
38
+ <small>Preview not available</small>
39
+ <% end %>
40
+ </div>
41
+ <% end %>
@@ -1,19 +1,12 @@
1
1
  <div class="pulitzer-row">
2
- <%= form_for version, html: { class: 'pulitzer-form-left' } do |f| %>
2
+ <%= form_for version, html: ajax_form_hash(dom_target(version.post, :preview_version)).merge( class: 'pulitzer-form-left' ) do |f| %>
3
3
  <%= f.submit "Activate" %>
4
4
  <%= hidden_field_tag :status, :active %>
5
5
  <% end %>
6
6
 
7
- <%= form_for version, html: { class: 'pulitzer-form-left' } do |f| %>
7
+ <%= form_for version, html: ajax_form_hash(dom_target(version.post, :preview_version)).merge( class: 'pulitzer-form-left' ) do |f| %>
8
8
  <%= f.submit "Abandon" %>
9
9
  <%= hidden_field_tag :status, :abandoned %>
10
10
  <% end %>
11
11
 
12
- <div class="preview-link">
13
- <% if @preview_path %>
14
- <%= link_to "Preview", @preview_path, target: '_blank' %>
15
- <% else %>
16
- <small>Preview not available</small>
17
- <% end %>
18
- </div>
19
12
  </div>
data/config/routes.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  Pulitzer::Engine.routes.draw do
2
2
  resources :posts do
3
- resources :content_elements
4
- resources :post_tags
3
+ member do
4
+ get :processing_preview
5
+ end
5
6
  end
7
+ resources :content_elements
8
+ resources :post_tags
9
+
6
10
  resources :content_elements do
7
11
  collection do
8
12
  patch :update_all
@@ -0,0 +1,5 @@
1
+ class AddErrorsToVersion < ActiveRecord::Migration
2
+ def change
3
+ add_column :pulitzer_versions, :cloning_errors, :jsonb
4
+ end
5
+ end