rules_configuration.unknown_rule=Unknown rule
rules_configuration.x_rules_have_been_activated={0} rules have been activated.
rules_configuration.x_rules_have_been_deactivated={0} rules have been deactivated.
-rules_configuration.rule_description=Description
-rules_configuration.rule_note=Note
-rules_configuration.rule_activation_note=Activation note
-rules_configuration.confirm_delete_note=Do you really want to delete this note?
+rules_configuration.extend_description=Extend description
+rules_configuration.update_description=Update description
rules_configuration.add_note=Add note
-rules_configuration.add_activation_note=Add activation note
-rules_configuration.adding_note_description=This note will be linked to the current rule (whatever the profile) and will be visible to every user. It can be used to extend the predefined rule description.<br/>HTML tags can be used in this field.
-rules_configuration.adding_activation_note_description=This activation note will be linked to the active rule of the current profile and will be visible to every user. It can be used to explain why this rule was activated on this profile and/or why such parameter was specified.<br/>HTML tags can be used in this field.
-rules_configuration.create_note=Create note
-rules_configuration.create_activation_note=Create activation note
+rules_configuration.confirm_delete_note=Do you really want to delete this note?
rules_configuration.rule_identification=Identification
rules_configuration.rule_parameters=Parameters
# RULES DOCUMENTATION PAGE
#
#------------------------------------------------------------------------------
-rules.description=Description
-rules.rule_activated_on_profile_x=Rule activated on profile "{0}"
-rules.parameters=Parameters:
+rules.more_about_rule_on_profile_x=More about this rule on profile "{0}"
+rules.identification=Identification
+rules.parameters=Parameters
#------------------------------------------------------------------------------
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post,
- :only => ['activate_rule', 'update_param', 'bulk_edit', 'create', 'update', 'delete', 'revert_rule', 'update_note', 'delete_note'],
+ :only => ['activate_rule', 'update_param', 'bulk_edit', 'create', 'update', 'delete', 'revert_rule', 'update_rule_note', 'update_active_rule_note', 'delete_active_rule_note'],
:redirect_to => { :action => 'index' }
before_filter :admin_required, :except => [ 'index', 'export' ]
end
- def update_note
- if params[:is_active_rule]
- rule = ActiveRule.find(params[:rule_id])
- else
- rule = Rule.find(params[:rule_id])
- end
+ def update_rule_note
+ rule = Rule.find(params[:rule_id])
note = rule.note
unless note
- if params[:is_active_rule]
- note = ActiveRuleNote.new({:rule => rule})
- else
- note = RuleNote.new({:rule => rule})
- end
+ note = RuleNote.new({:rule => rule})
# set the note on the rule to avoid reloading the rule
rule.note = note
end
note.text = params[:text]
note.user_login = current_user.login
note.save!
- render :partial => 'rule_note', :locals => {:rule => rule, :is_admin => true, :is_active_rule => params[:is_active_rule] }
+ render :partial => 'rule_note', :locals => {:rule => rule, :is_admin => true }
end
-
- def delete_note
- if params[:is_active_rule]
- rule = ActiveRule.find(params[:rule_id])
- else
- rule = Rule.find(params[:rule_id])
+
+ def update_active_rule_note
+ active_rule = ActiveRule.find(params[:active_rule_id])
+ note = active_rule.note
+ unless note
+ note = ActiveRuleNote.new({:active_rule => active_rule})
+ # set the note on the rule to avoid reloading the rule
+ active_rule.note = note
end
- rule.note.destroy if rule.note
- render :text => ''
+ note.text = params[:text]
+ note.user_login = current_user.login
+ note.save!
+ render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :is_admin => true }
+ end
+
+
+ def delete_active_rule_note
+ active_rule = ActiveRule.find(params[:active_rule_id])
+ active_rule.note.destroy if active_rule.note
+ active_rule.note = nil
+ render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :is_admin => true }
end
class ActiveRuleNote < ActiveRecord::Base
belongs_to :active_rule
alias_attribute :text, :data
- alias_attribute :rule, :active_rule
validates_presence_of :active_rule, :message => "can't be empty"
validates_presence_of :user_login, :message => "can't be empty"
user_login ? User.find(:first, :conditions => ['login=?', user_login]) : nil
end
end
+
+ def html_text
+ Api::Utils.markdown_to_html(text)
+ end
+
+ def plain_text
+ Api::Utils.convert_string_to_unix_newlines(text)
+ end
end
validates_presence_of :rule, :message => "can't be empty"
validates_presence_of :user_login, :message => "can't be empty"
- validates_length_of :data, :minimum => 1
def user
@user ||=
user_login ? User.find(:first, :conditions => ['login=?', user_login]) : nil
end
end
+
+ def html_text
+ Api::Utils.markdown_to_html(text)
+ end
+
+ def plain_text
+ Api::Utils.convert_string_to_unix_newlines(text)
+ end
end
<h1><%= @rule.name %></h1>
-<div class="subtitle">
-Plugin: <%= @rule.plugin_name -%>
-Key: <%= @rule.plugin_rule_key %>
-</div>
<div class="doc">
- <h2><%= message('rules.description') -%></h2>
- <p><%= @rule.description %></p>
+ <% if @rule.description.strip.start_with?('<p>') %>
+ <%= @rule.description %>
+ <% else %>
+ <p><%= @rule.description %></p>
+ <% end %>
- <% if @rule.note %>
- <p><%= sanitize(@rule.note.text) -%></p>
+ <% if @rule.note && !@rule.note.text.strip.blank? %>
+ <p><%= @rule.note.html_text -%></p>
<% end %>
- <% if @profile %>
- <h2><%= message('rules.rule_activated_on_profile_x', :params => @profile.name) -%></h2>
+ <% if @profile && @active_rule %>
+ <br/>
+ <b>
+ <a href="#" onclick="$('details').toggle();return false;"><%= message('rules.more_about_rule_on_profile_x', :params => @profile.name) %></a>
+ </b>
- <% if @active_rule %>
- <p><%= sanitize(@active_rule.note.text) if @active_rule.note %></p>
+ <div id="details" style="display: none">
+ <p><%= @active_rule.note.html_text if @active_rule.note %></p>
<% unless @rule.parameters.empty? %>
+ <br/>
<h3><%= message('rules.parameters') -%></h3>
- <table>
+ <table style="margin-left:7px">
<% @rule.parameters.each do |parameter|
active_parameter = @active_rule.active_param_by_param_id(parameter.id)
%>
<%= parameter.name %>:
</td>
<td width="90%" nowrap class="left">
- <%= active_parameter.value unless active_parameter.value.blank? -%>
+ <%= active_parameter.value if active_parameter.value && !active_parameter.value.blank? -%>
</td>
</tr>
<tr>
<% end %>
</table>
<% end %>
- <% end %>
+
+ <br/>
+ <h3><%= message('rules.identification') -%></h3>
+ <table style="margin-left:7px">
+ <tbody>
+ <tr><td style="padding-right:10px"><%= message('plugin') -%>:</td><td><%= @rule.plugin_name.capitalize %></td></tr>
+ <tr><td style="padding-right:10px"><%= message('key') -%>:</td><td><%= @rule.plugin_rule_key %></td></tr>
+ </tbody>
+ </table>
+ </div>
+
<% end %>
-
</div>
--- /dev/null
+<% #locals = active_rule, is_admin
+ note = active_rule.note
+ active_note_detail_div_id = "and_" + active_rule.id.to_s
+ add_active_note_button_id = "aanb_" + active_rule.id.to_s
+ edit_active_note_link_id = "eanl_" + active_rule.id.to_s
+ delete_active_note_link_id = "danl_" + active_rule.id.to_s
+ active_note_form_div_id = "anf_" + active_rule.id.to_s
+ active_note_textarea_id = "ant_" + active_rule.id.to_s
+ submit_active_note_update_button_id = "sanub_" + active_rule.id.to_s
+%>
+
+<div id="<%= active_note_detail_div_id -%>" style="padding: 4px;<%= 'border: 1px solid #DDDDDD;' if note -%>">
+ <% if note %>
+ <h4>
+ <%= image_tag("reviews/comment.png") -%>
+ <b><%= note.user.name -%></b>
+ (<%= distance_of_time_in_words_to_now(note.updated_at) -%>)
+
+ <%= image_tag 'sep12.png' -%>
+
+ <a href="#" id="<%= edit_active_note_link_id -%>"
+ onclick="$('<%= active_note_detail_div_id -%>').hide();$('<%= active_note_form_div_id -%>').show();$('<%= active_note_textarea_id -%>').focus();return false;"><%= message('edit') %></a>
+
+ <%= link_to_remote message('delete'),
+ :url => {:action => 'delete_active_rule_note', :active_rule_id => active_rule.id },
+ :update => "active_rule_note_#{active_rule.id}",
+ :confirm => message('rules_configuration.confirm_delete_note') -%>
+ </h4>
+ <p><%= note.html_text -%></p>
+ <% elsif is_admin %>
+ <input type="button" id="<%= add_active_note_button_id -%>" value="<%= message('rules_configuration.add_note') -%>"
+ onclick="$('<%= active_note_form_div_id -%>').show();$('<%= active_note_detail_div_id -%>').hide();$('<%= active_note_textarea_id -%>').focus();">
+ <% end %>
+</div>
+
+<% if is_admin %>
+<div id="<%= active_note_form_div_id -%>" style="display: none" class="admin">
+ <table>
+ <tbody>
+ <tr>
+ <td class="max-width">
+ <%= form_remote_tag :url => {:action => 'update_active_rule_note', :active_rule_id => active_rule.id},
+ :update => "active_rule_note_#{active_rule.id}" %>
+ <textarea name="text" id="<%= active_note_textarea_id -%>" rows="10" cols="100%"
+ onkeyup="if (this.value=='') $('<%= submit_active_note_update_button_id -%>').disabled=true; else $('<%= submit_active_note_update_button_id -%>').disabled=false;"><%= h(note.plain_text) if note -%></textarea>
+ <br/>
+ <input type="submit" value="<%= note ? message('update_verb') : message('rules_configuration.add_note') -%>" name="commit" id="<%= submit_active_note_update_button_id -%>"/>
+ <a href="#" onclick="$('<%= active_note_detail_div_id -%>').show();$('<%= active_note_form_div_id -%>').hide();return false;"><%= message('cancel') %></a>
+ </form>
+ </td>
+ <td class="markdown-help">
+ <%= render :partial => 'markdown/help' -%>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</div>
+<% end %>
\ No newline at end of file
+++ /dev/null
-<% #locals = rule, active_rule, is_admin
- create_buttons_div_id = "cb_" + rule.id.to_s
- create_rule_note_button_div_id = "cnb_" + rule.id.to_s
- create_active_rule_note_button_div_id = "canb_" + rule.id.to_s
- create_rule_note_form_div_id = "crnf_" + rule.id.to_s
- create_active_rule_note_form_div_id = "carnf_" + rule.id.to_s
- submit_rule_note_id = "srn_" + rule.id.to_s
- submit_active_rule_note_id = "sarn_" + rule.id.to_s
- rule_note_text_id = "rnt_" + rule.id.to_s
- active_rule_note_text_id = "arnt_" + rule.id.to_s
-%>
-
-<div style="margin-top: 10px;">
-
-<div id="<%= create_buttons_div_id -%>">
- <input type="button" id="<%= create_rule_note_button_div_id -%>" value="<%= message('rules_configuration.add_note') -%>"
- onclick="$('<%= create_buttons_div_id -%>').hide();$('<%= create_rule_note_form_div_id -%>').show();$('<%= rule_note_text_id -%>').focus();"
- <%= 'style="display:none;"' if rule.note -%>>
- <input type="button" id="<%= create_active_rule_note_button_div_id -%>" value="<%= message('rules_configuration.add_activation_note') -%>"
- onclick="$('<%= create_buttons_div_id -%>').hide();$('<%= create_active_rule_note_form_div_id -%>').show();$('<%= active_rule_note_text_id -%>').focus();"
- <%= 'style="display:none;"' unless active_rule && !active_rule.note -%>>
-</div>
-
-<div id="<%= create_rule_note_form_div_id -%>" style="display: none" class="admin">
- <%= form_remote_tag :url => {:action => 'update_note', :rule_id => rule.id, :is_active_rule => false},
- :update => "rule_note_#{rule.id}",
- :complete => "$('#{create_rule_note_form_div_id}').hide();$('#{create_buttons_div_id}').show();$('#{create_rule_note_button_div_id}').hide();" %>
- <textarea name="text" id="<%= rule_note_text_id -%>" cols="100" rows="10" onkeyup="if (this.value=='') $('<%= submit_rule_note_id -%>').disabled=true; else $('<%= submit_rule_note_id -%>').disabled=false;"></textarea>
- <div class="note" style="padding: 5px 0px"><%= message('rules_configuration.adding_note_description') -%></div>
- <input type="submit" value="<%= message('rules_configuration.create_note') -%>" name="commit" id="<%= submit_rule_note_id -%>" disabled/>
- <a href="#" onclick="$('<%= create_buttons_div_id -%>').show();$('<%= create_rule_note_form_div_id -%>').hide();return false;"><%= message('cancel') %></a>
- </form>
-</div>
-
-<% if active_rule %>
-<div id="<%= create_active_rule_note_form_div_id -%>" style="display: none" class="admin">
- <%= form_remote_tag :url => {:action => 'update_note', :rule_id => active_rule.id, :is_active_rule => true},
- :update => "active_rule_note_#{active_rule.id}",
- :complete => "$('#{create_active_rule_note_form_div_id}').hide();$('#{create_buttons_div_id}').show();$('#{create_active_rule_note_button_div_id}').hide();" %>
- <textarea name="text" id="<%= active_rule_note_text_id -%>" cols="100" rows="10" onkeyup="if (this.value=='') $('<%= submit_active_rule_note_id -%>').disabled=true; else $('<%= submit_active_rule_note_id -%>').disabled=false;"></textarea>
- <div class="note" style="padding: 5px 0px"><%= message('rules_configuration.adding_activation_note_description')-%></div>
- <input type="submit" value="<%= message('rules_configuration.create_activation_note') -%>" name="commit" id="<%= submit_active_rule_note_id -%>" disabled/>
- <a href="#" onclick="$('<%= create_buttons_div_id -%>').show();$('<%= create_active_rule_note_form_div_id -%>').hide();return false;"><%= message('cancel') %></a>
- </form>
-</div>
-<% end %>
-
-</div>
\ No newline at end of file
<tbody>
<tr>
<td width="50%">
- <h3><%= message('rules_configuration.rule_description') -%></h3>
- <p><%= rule.description %></p>
<div id="rule_note_<%= rule.id -%>">
- <%= render :partial => 'rule_note', :locals => {:rule => rule, :is_admin => is_admin, :is_active_rule => false } %>
+ <%= render :partial => 'rule_note', :locals => {:rule => rule, :is_admin => is_admin } %>
</div>
<% if active_rule %>
<div id="active_rule_note_<%= active_rule.id -%>">
- <%= render :partial => 'rule_note', :locals => {:rule => active_rule, :is_admin => is_admin, :is_active_rule => true } %>
+ <%= render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :is_admin => is_admin } %>
</div>
<% end %>
- <% if is_admin %>
- <%= render :partial => 'create_rule_note', :locals => {:rule => rule, :active_rule => active_rule, :is_admin => is_admin } %>
- <% end %>
</td>
<td class="separator"></td>
<td width="50%">
- <h3><%= message('rules_configuration.rule_identification') -%></h3>
- <table style="margin-left:7px">
- <tbody>
- <tr><td style="padding-right:10px"><%= message('plugin') -%>:</td><td><%= rule.plugin_name.capitalize %></td></tr>
- <tr><td style="padding-right:10px"><%= message('key') -%>:</td><td><%= rule.plugin_rule_key %></td></tr>
- <t/body>
- </table>
<% unless rule.parameters.empty? %>
- <br/>
<h3><%= message('rules_configuration.rule_parameters') -%></h3>
<table style="margin-left:7px">
<% rule.parameters.each do |parameter|
<%= button_to message('rules_configuration.revert_to_parent_definition'), :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id} %><br/>
<% end %>
<% end %>
+ <h3><%= message('rules_configuration.rule_identification') -%></h3>
+ <table style="margin-left:7px">
+ <tbody>
+ <tr><td style="padding-right:10px"><%= message('plugin') -%>:</td><td><%= rule.plugin_name.capitalize %></td></tr>
+ <tr><td style="padding-right:10px"><%= message('key') -%>:</td><td><%= rule.plugin_rule_key %></td></tr>
+ </tbody>
+ </table>
</td>
</tr>
</tbody>
-<% #locals = rule, is_admin, is_active_rule
- submit_note_update_button_id = (is_active_rule ? 'a' : '') + "snub_" + rule.id.to_s
+<% #locals = rule, is_admin
+ note = rule.note
+ note_detail_div_id = "nd_" + rule.id.to_s
+ note_extend_link_id = "nel_" + rule.id.to_s
+ note_form_div_id = "nf_" + rule.id.to_s
+ note_textarea_id = "nt_" + rule.id.to_s
+ submit_note_update_button_id = "snub_" + rule.id.to_s
%>
-<%
- if rule.note
- note = rule.note
-%>
- <h3><%= is_active_rule ? message('rules_configuration.rule_activation_note') : message('rules_configuration.rule_note') -%></h3>
- <div class="note"><%= note.user.name -%>, <%= l(note.updated_at) -%></div>
- <div id="note_detail_<%= rule.id -%>">
- <p><%= sanitize(note.text) -%></p>
- <% if is_admin %>
- <div style="margin-bottom: 10px">
- <input type="button" value="<%= message('update_verb') -%>" onclick="$('note_detail_<%= rule.id -%>').hide();$('note_form_<%= rule.id -%>').show();">
- <%= button_to_remote message('delete'),
- {:url => {:action => 'delete_note', :rule_id => rule.id, :is_active_rule => is_active_rule },
- :update => "#{'active_' if is_active_rule}rule_note_#{rule.id}",
- :complete => "$('#{is_active_rule ? "canb_"+rule.rule.id.to_s : "cnb_"+rule.id.to_s}').show()",
- :confirm => message('rules_configuration.confirm_delete_note')},
- {:class => 'red-button'} -%>
- </div>
- <% end %>
- </div>
+<div id="<%= note_detail_div_id -%>">
+ <% if rule.description.strip.start_with?('<p>') %>
+ <%= rule.description %>
+ <% else %>
+ <p><%= rule.description %></p>
+ <% end %>
+
+ <% if note && !note.text.strip.blank? %>
+ <p><%= note.html_text -%></p>
+ <% end %>
+
+ <% if is_admin %>
+ <p style="text-align: right; font-style: italic;">
+ ยป <a href="#" id="<%= note_extend_link_id -%>"
+ onclick="$('<%= note_detail_div_id -%>').hide();$('<%= note_form_div_id -%>').show();$('<%= note_textarea_id -%>').focus();return false;"><%= message('rules_configuration.extend_description') %></a>
+ </p>
+ <% end %>
+</div>
- <div id="note_form_<%= rule.id -%>" style="display: none" class="admin">
- <%= form_remote_tag :url => {:action => 'update_note', :rule_id => rule.id, :is_active_rule => is_active_rule},
- :update => "#{'active_' if is_active_rule}rule_note_#{rule.id}" %>
- <textarea name="text" id="update_<%= 'active_' if is_active_rule -%>_rule_note_<%= rule.id -%>" cols="100" rows="10"
- onkeyup="if (this.value=='') $('<%= submit_note_update_button_id -%>').disabled=true; else $('<%= submit_note_update_button_id -%>').disabled=false;"><%= h(note.text) -%></textarea>
- <br/>
- <input type="submit" value="<%= message('update_verb') -%>" name="commit" id="<%= submit_note_update_button_id -%>"/>
- <a href="#" onclick="$('note_detail_<%= rule.id -%>').show();$('note_form_<%= rule.id -%>').hide();return false;"><%= message('cancel') %></a>
- </form>
- </div>
-<% end %>
\ No newline at end of file
+<% if is_admin %>
+<div id="<%= note_form_div_id -%>" style="display: none" class="admin">
+ <table>
+ <tbody>
+ <tr>
+ <td style="padding-bottom:20px;" colspan="2"><%= rule.description %></td>
+ </tr>
+ <tr>
+ <td class="max-width">
+ <%= form_remote_tag :url => {:action => 'update_rule_note', :rule_id => rule.id},
+ :update => "rule_note_#{rule.id}" %>
+ <textarea name="text" id="<%= note_textarea_id -%>" rows="10" cols="100%"><%= h(note.plain_text) if note -%></textarea>
+ <br/>
+ <input type="submit" value="<%= message('rules_configuration.update_description') -%>" name="commit" id="<%= submit_note_update_button_id -%>"/>
+ <a href="#" onclick="$('<%= note_detail_div_id -%>').show();$('<%= note_form_div_id -%>').hide();return false;"><%= message('cancel') %></a>
+ </form>
+ </td>
+ <td class="markdown-help">
+ <%= render :partial => 'markdown/help' -%>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</div>
+<% end %>
margin-top:10px;
}
+.rule_detail .markdown-help {
+ vertical-align:top;
+ width: 90px;
+ padding-left: 10px;
+ white-space: nowrap;
+}
+
.rule_detail > td > table {
margin: 4px;
}