diff --git a/app/assets/javascripts/field-autosave.js b/app/assets/javascripts/field-autosave.js index 1a031ef0..a30a2784 100644 --- a/app/assets/javascripts/field-autosave.js +++ b/app/assets/javascripts/field-autosave.js @@ -2,7 +2,7 @@ $(document).ready(function() { $('.panel-field.autosave-field').click(function () { console.log('autosaving'); var content_form = $(this).closest('form'); - content_form.submit(); + // content_form.submit(); }); // To ensure all fields get unblurred (and therefore autosaved) upon navigation, diff --git a/app/controllers/attribute_fields_controller.rb b/app/controllers/attribute_fields_controller.rb index a8e67b59..70023267 100644 --- a/app/controllers/attribute_fields_controller.rb +++ b/app/controllers/attribute_fields_controller.rb @@ -1,4 +1,3 @@ -# Controller for the Attribute model class AttributeFieldsController < ContentController def create initialize_object.save! @@ -18,6 +17,50 @@ class AttributeFieldsController < ContentController related_category.destroy if related_category.attribute_fields.empty? end + def update + content_type = AttributeField + # todo rework from here + + content_type = content_type_from_controller(self.class) + @content = content_type.with_deleted.find(params[:id]) + + unless @content.updatable_by?(current_user) + flash[:notice] = "You don't have permission to edit that!" + return redirect_back fallback_location: @content + end + + Mixpanel::Tracker.new(Rails.application.config.mixpanel_token).track(current_user.id, 'updated content', { + 'content_type': content_type.name + }) if Rails.env.production? + + if params.key?('image_uploads') + upload_files(params['image_uploads'], content_type.name, @content.id) + end + + if @content.is_a?(Universe) && params.key?('contributors') && @content.user == current_user + params[:contributors][:email].reject(&:blank?).each do |email| + ContributorService.invite_contributor_to_universe(universe: @content, email: email.downcase) + end + end + + update_page_tags if @content.respond_to?(:page_tags) + + if @content.user == current_user + # todo this needs some extra validation probably to ensure each attribute is one associated with this page + update_success = @content.reload.update(content_params) + else + # Exclude fields only the real owner can edit + #todo move field list somewhere when it grows + update_success = @content.update(content_params.except(:universe_id)) + end + + if update_success + successful_response(@content, t(:update_success, model_name: @content.try(:name).presence || humanized_model_name)) + else + failed_response('edit', :unprocessable_entity, "Unable to save page. Error code: " + @content.errors.to_json) + end + end + private def initialize_object @@ -78,7 +121,8 @@ class AttributeFieldsController < ContentController :label, :description, :entity_type, :attribute_category_id, - :hidden + :hidden, + :field_options ] end end diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 6468ce9b..227a0718 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -256,7 +256,7 @@ class ContentController < ApplicationController end cache_params = {} - cache_params[:name] = @content.name_field_value unless [AttributeCategory, AttributeField, Attribute].include?(@content.class) + cache_params[:name] = @content.name_field_value unless [AttributeCategory, Attribute].include?(@content.class) cache_params[:universe] = @content.universe_field_value if self.respond_to?(:universe_id) @content.update(cache_params) if cache_params.any? && update_success diff --git a/app/views/content/attributes.html.erb b/app/views/content/attributes.html.erb index b41f9e47..6bad9ea3 100644 --- a/app/views/content/attributes.html.erb +++ b/app/views/content/attributes.html.erb @@ -1,5 +1,5 @@ <%= content_for :full_width_page_header do %> - <%= render partial: 'content/components/parallax_header', locals: { content_type: @content_type, content_class: @content_type_class } %> + <%# render partial: 'content/components/parallax_header', locals: { content_type: @content_type, content_class: @content_type_class } %> <% end %> \ No newline at end of file diff --git a/app/views/content/attributes/fields/options/_link.html.erb b/app/views/content/attributes/fields/options/_link.html.erb new file mode 100644 index 00000000..fcea707b --- /dev/null +++ b/app/views/content/attributes/fields/options/_link.html.erb @@ -0,0 +1,21 @@ +
+ Customize which pages this field can link to with the dropdown below. +
+