diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 57e8f05..ed6ea4a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,3 +21,10 @@ //= require chosen.jquery //= require underscore //= require_tree . + +// Setup star rating automagic +$(document).on("turbolinks:load", function() { + + $("input[data-rating='true']").starRating(); + +}); \ No newline at end of file diff --git a/app/assets/javascripts/logs.js b/app/assets/javascripts/logs.js index 94cbaf7..e6a1cdb 100644 --- a/app/assets/javascripts/logs.js +++ b/app/assets/javascripts/logs.js @@ -2,9 +2,6 @@ $(document).on("turbolinks:load", function() { $(".log-form input.datepicker").datepicker({autoclose: true, todayBtn: "linked", format: "yyyy-mm-dd"}); - $(".log-form input.rating").starRating(); - - $(".log-table input.rating").starRating({readOnly: true}); }); })(jQuery); \ No newline at end of file diff --git a/app/assets/javascripts/recipes.js b/app/assets/javascripts/recipes.js index 0e6a548..e9eacfb 100644 --- a/app/assets/javascripts/recipes.js +++ b/app/assets/javascripts/recipes.js @@ -3,8 +3,6 @@ $(document).on("turbolinks:load", function() { $(".recipe-view ul.ingredients").checkable(); $(".recipe-view ol.steps").checkable(); - - $(".recipe-table input.rating").starRating({readOnly: true, interval: 0.25, size: '20px'}); }); })(jQuery); diff --git a/app/assets/javascripts/star_rating.js b/app/assets/javascripts/star_rating.js index 54ca1e2..7a4eb9e 100644 --- a/app/assets/javascripts/star_rating.js +++ b/app/assets/javascripts/star_rating.js @@ -13,8 +13,10 @@ initialize: function(opts) { return this.each(function() { var $input = $(this); + var attrOpts = {}; + var inputData = $input.data(); - if ($input.data(pluginName.toLowerCase()) === true) { + if (inputData[pluginName.toLowerCase()] === true) { if (console && console.log) { console.log("star rating has already been initialized; skipping..."); } @@ -23,7 +25,23 @@ $input.attr("data-" + pluginName.toLowerCase(), "true"); - var options = _.extend({}, defaultOptions, opts); + if (inputData.interval) { + attrOpts.interval = inputData.interval; + } + + if (inputData.starcount) { + attrOpts.starCount = inputData.starcount; + } + + if (inputData.size) { + attrOpts.size = inputData.size; + } + + if ($input.is(":disabled")) { + attrOpts.readOnly = true; + } + + var options = _.extend({}, defaultOptions, attrOpts, opts); var $widget = $("").addClass("star-rating").css({'font-size': options.size}); var $emptySet = $("").addClass("empty-set").appendTo($widget); diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index 7162da9..4d35dc4 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -21,7 +21,7 @@ class LogsController < ApplicationController def update ensure_owner(@log) do if @log.update(log_params) - redirect_to @log, notice: 'Log Entry was successfully updated.' + redirect_to logs_path, notice: 'Log Entry was successfully updated.' else render :edit end @@ -45,7 +45,7 @@ class LogsController < ApplicationController @log.source_recipe = @recipe if @log.save - redirect_to @log, notice: 'Log Entry was successfully created.' + redirect_to logs_path, notice: 'Log Entry was successfully created.' else render :new end diff --git a/app/views/logs/_form.html.erb b/app/views/logs/_form.html.erb index c1bf31e..fd51552 100644 --- a/app/views/logs/_form.html.erb +++ b/app/views/logs/_form.html.erb @@ -15,7 +15,7 @@
<%= f.label :rating, class: 'control-label' %> - <%= f.text_field :rating, class: 'form-control rating' %> + <%= f.text_field :rating, class: 'form-control', data: {rating: 'true'} %>
diff --git a/app/views/logs/edit.html.erb b/app/views/logs/edit.html.erb new file mode 100644 index 0000000..4a704e2 --- /dev/null +++ b/app/views/logs/edit.html.erb @@ -0,0 +1,12 @@ +
+
+ + + <%= render 'form' %> + + <%= link_to 'Back', logs_path, class: 'btn btn-default' %> + +
+
diff --git a/app/views/logs/index.html.erb b/app/views/logs/index.html.erb index 111fd27..d0ef92a 100644 --- a/app/views/logs/index.html.erb +++ b/app/views/logs/index.html.erb @@ -25,8 +25,8 @@ <%= link_to log.recipe.short_name, log %> <%= log.date %> - - <%= %> + <%= text_field_tag('rating', log.rating, disabled: true, data: {rating: true}) %> + <%= log.notes %> <% end %> diff --git a/app/views/logs/show.html.erb b/app/views/logs/show.html.erb index e69de29..0bf2b8a 100644 --- a/app/views/logs/show.html.erb +++ b/app/views/logs/show.html.erb @@ -0,0 +1,96 @@ + +<% + @log = decorate(@log, LogDecorator) + @recipe = @log.recipe +%> + +
+ +
+
+ + +

Date: <%= @log.date %>

+

Rating: <%= text_field_tag('rating', @log.rating, disabled: true, data: {rating: true}) %>

+

Notes: <%= @log.notes %>

+ +

+ <%= @recipe.description %> +

+
+
+ +
+ <% if @recipe.total_time.present? || @recipe.active_time.present? %> +
+

<%= recipe_time(@recipe) %>

+
+ <% end %> + + <% if @recipe.yields.present? %> +
+

Yields

<%= @recipe.yields %>

+
+ <% end %> + + <% if @recipe.source.present? %> +
+

Source

<%= @recipe.source_markup %>

+
+ <% end %> + +
+ +
+
+
+
+ +
+

Ingredients

+
+ + +
+
+
    + <% @recipe.recipe_ingredients.each do |i| %> +
  • <%= i.display_name %>
  • + <% end %> +
+
+
+ +
+ +
+
+
+

Directions

+
+
+
    + <% @recipe.recipe_steps.each do |s| %> +
  1. <%= "#{s.step}" %>
  2. + <% end %> +
+
+
+
+
+ +
+ +
+
+ + <%= link_to 'Edit', edit_log_path(@log), class: 'btn btn-default' %> + <%= link_to 'Back', logs_path, class: 'btn btn-default' %> + +
+
+ diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index 833b331..5f4c6e8 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -30,7 +30,7 @@ <%= link_to recipe.short_name, recipe %> <% if recipe.average_rating > 0 %> - + <%= text_field_tag('rating', recipe.average_rating, disabled: true, data: {rating: true, size: '20px', interval: '0.25'}) %> <% else %> -- <% end %>