Commit 60e11e2ca28bde89ad6de1126fd742e926c8b997

Authored by Diego Camarinha
Committed by Diego Camarinha
1 parent aca22dd2

[Mezuro] Fixed color picker.

plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
... ... @@ -113,7 +113,6 @@ class MezuroPluginMyprofileController < ProfileController
113 113 @configuration_content = profile.articles.find(params[:id])
114 114 @metric_name = params[:metric_name]
115 115 @range = Kalibro::Range.new
116   - @range_color = "#000000"
117 116 end
118 117  
119 118 def edit_range
... ... @@ -122,7 +121,6 @@ class MezuroPluginMyprofileController < ProfileController
122 121 @beginning_id = params[:beginning_id]
123 122 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name)
124 123 @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" }
125   - @range_color = "#" + @range.color.to_s.gsub(/^ff/, "")
126 124 end
127 125  
128 126 def create_range
... ...
plugins/mezuro/lib/kalibro/range.rb
... ... @@ -34,4 +34,12 @@ class Kalibro::Range < Kalibro::Model
34 34 @grade = value.to_f
35 35 end
36 36  
  37 + def mezuro_color
  38 + @color.nil? ? "#e4ca2d" : @color.gsub(/^ff/, "#")
  39 + end
  40 +
  41 + def color=(new_color)
  42 + @color = new_color.gsub(/^#/, "ff")
  43 + end
  44 +
37 45 end
... ...
plugins/mezuro/public/javascripts/validations.js
... ... @@ -39,14 +39,6 @@ function IsNotInfinite(value){
39 39 return true;
40 40 }
41 41  
42   -function IsNotHexadecimal(value){
43   - if(value.match(/^[0-9a-fA-F]{1,8}$/))
44   - {
45   - return false;
46   - }
47   - return true;
48   -}
49   -
50 42 function validate_new_range_configuration(event){
51 43 var label = jQuery("#range_label").val();
52 44 var beginning = jQuery("#range_beginning").val();
... ... @@ -56,24 +48,20 @@ function validate_new_range_configuration(event){
56 48  
57 49 if (is_null(label) || is_null(beginning) || is_null(end) || is_null(color) || is_null(grade))
58 50 {
59   - alert("Please fill all fields marked with (*)");
  51 + alert("Please fill all fields marked with (*).");
60 52 return false;
61 53 }
62 54 if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)) || IsNotNumeric(grade))
63 55 {
64   - alert("Beginning, End and Grade must be numeric values");
  56 + alert("Beginning, End and Grade must be numeric values.");
65 57 return false;
66 58 }
67 59 if (parseInt(beginning) > parseInt(end))
68 60 {
69 61 if(IsNotInfinite(beginning) && IsNotInfinite(end)){
70   - alert("End must be greater than Beginning");
  62 + alert("End must be greater than Beginning.");
71 63 return false;
72 64 }
73 65 }
74   - if (IsNotHexadecimal(color)){
75   - alert("Color must be an hexadecimal value");
76   - return false;
77   - }
78 66 return true;
79 67 }
... ...
plugins/mezuro/test/unit/kalibro/range_test.rb
... ... @@ -17,4 +17,16 @@ class RangeTest < ActiveSupport::TestCase
17 17 assert_equal @hash, @range.to_hash
18 18 end
19 19  
  20 + should 'create a default color for new range' do
  21 + assert_equal "#e4ca2d", Kalibro::Range.new.mezuro_color
  22 + end
  23 +
  24 + should "convert color from 'ff' to '#'" do
  25 + assert_equal "#ff0000", @range.mezuro_color
  26 + end
  27 +
  28 + should "convert color from '#' to 'ff' when creating a new range" do
  29 + assert_equal "ffff0000", Kalibro::Range.new({:color => '#ff0000'}).color
  30 + end
  31 +
20 32 end
... ...
plugins/mezuro/views/mezuro_plugin_myprofile/_range_form.html.erb
... ... @@ -38,7 +38,7 @@
38 38 <%= f.label :color, "(*) Color:" %>
39 39 </td>
40 40 <td>
41   - <%= f.text_field(:color, :id => "range_color", :value => @range_color) %>
  41 + <%= f.text_field(:color, :id => "range_color", :value => @range.mezuro_color) %>
42 42 </td>
43 43 </tr>
44 44 <tr>
... ... @@ -53,10 +53,9 @@
53 53 <%= f.submit "Save Range" %>
54 54  
55 55 <script>jQuery(document).ready(function($) {
56   - $('#range_color').colorPicker({
57   - onColorChange : function(id, newValue) {
58   - newValue = newValue.replace(/#/gi, "ff");
59   - jQuery('#range_color').val(newValue);
60   - }
  56 + $('#range_color').colorPicker({
  57 + onColorChange : function(id, newValue) {
  58 + jQuery('#range_color').val(newValue);
  59 + }
61 60 });
62 61 });</script>
... ...