Commit a4abbe84fc2c118417035ce1f7f415768fdc1801

Authored by Hugo Melo
1 parent 8268e552

Adapt badge edition form for composed actions

lib/gamification_plugin.rb
... ... @@ -50,7 +50,7 @@ class GamificationPlugin < Noosfero::Plugin
50 50 end
51 51  
52 52 def js_files
53   - ['jquery.noty.packaged.min.js', 'jquery.easypiechart.min.js', 'main.js']
  53 + ['jquery.noty.packaged.min.js', 'jquery.easypiechart.min.js', 'main.js', 'admin.js']
54 54 end
55 55  
56 56  
... ...
public/admin.js
... ... @@ -4,5 +4,20 @@ var gamificationPluginAdmin = {
4 4 var template = $('.gamification-plugin-rank-rules .template-level > div').clone();
5 5 template.find('.level-value').text($('.gamification-plugin-rank-rules .rank-rules .items .level').length + 1);
6 6 $('.gamification-plugin-rank-rules .rank-rules .items').append(template);
  7 + },
  8 +
  9 + selectCustomFieldsOnNameChange: function() {
  10 + jQuery('.controller-actions').find('input').attr('disabled', 'disabled');
  11 + jQuery('.controller-actions').hide();
  12 + console.log('.name_'+jQuery('#gamification-plugin-form-badge-name').val());
  13 + var name = jQuery('#gamification-plugin-form-badge-name').find('option:selected').text();
  14 + jQuery('.name_'+name).show();
  15 + jQuery('.name_'+name).find('input').removeAttr('disabled');
7 16 }
  17 +
8 18 }
  19 +
  20 +jQuery(function() {
  21 + $('#gamification-plugin-form-badge-name').on('change', gamificationPluginAdmin.selectCustomFieldsOnNameChange);
  22 + gamificationPluginAdmin.selectCustomFieldsOnNameChange();
  23 +});
... ...
views/gamification_plugin_badges/_form.html.erb
... ... @@ -11,9 +11,11 @@
11 11 </div>
12 12 <% end %>
13 13  
14   - <div class="field">
  14 + <% rules = Merit::BadgeRules::AVAILABLE_RULES %>
  15 + <% rules.merge! Merit::BadgeRules::CONFERENCE_RULES %>
  16 + <div class="field" id="gamification-plugin-form-badge-name">
15 17 <%= f.label :name %><br />
16   - <%= f.select :name, Merit::BadgeRules::AVAILABLE_RULES.map{ |key, rule| key } %>
  18 + <%= f.select :name, rules.map{ |key, rule| key } %>
17 19 </div>
18 20 <div class="field">
19 21 <%= f.label :title %><br />
... ... @@ -27,11 +29,22 @@
27 29 <%= f.label :level %><br />
28 30 <%= f.text_field :level %>
29 31 </div>
  32 + <h4><%= _('Actions') %></h4>
30 33 <%= f.fields_for :custom_fields do |c| %>
31   - <div class="field">
32   - <%= c.label :threshold %><br />
33   - <%= c.text_field :threshold %>
34   - </div>
  34 + <% rules.each do |name, settings| %>
  35 + <div class='controller-actions <%= "name_#{name}" %>'>
  36 + <% settings.each do |setting| %>
  37 + <%= c.label _(setting[:action]) %>
  38 + <%= c.fields_for setting[:action] do |d| %>
  39 + <% action = (@gamification_plugin_badge.custom_fields || {}).fetch(setting[:action], {}) %>
  40 + <div class="field">
  41 + <%= d.label :threshold %><br />
  42 + <%= d.text_field :threshold, {value: action.fetch('threshold', "")} %>
  43 + </div>
  44 + <% end %>
  45 + <% end %>
  46 + </div>
  47 + <% end %>
35 48 <% end %>
36 49 <div class="actions">
37 50 <%= f.submit %>
... ...