Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1848 from sarken/issue_4090
4090 Wrangling Guidelines system
- Loading branch information
Showing
22 changed files
with
399 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
class WranglingGuidelinesController < ApplicationController | ||
|
||
before_filter :admin_only, :except => [:index, :show] | ||
|
||
# GET /wrangling_guidelines | ||
def index | ||
@wrangling_guidelines = WranglingGuideline.order('position ASC') | ||
end | ||
|
||
# GET /wrangling_guidelines/1 | ||
def show | ||
@wrangling_guideline = WranglingGuideline.find(params[:id]) | ||
end | ||
|
||
# GET /wrangling_guidelines/new | ||
def new | ||
@wrangling_guideline = WranglingGuideline.new | ||
end | ||
|
||
# GET /wrangling_guidelines/1/edit | ||
def edit | ||
@wrangling_guideline = WranglingGuideline.find(params[:id]) | ||
end | ||
|
||
# GET /wrangling_guidelines/manage | ||
def manage | ||
@wrangling_guidelines = WranglingGuideline.order('position ASC') | ||
end | ||
|
||
# POST /wrangling_guidelines | ||
def create | ||
@wrangling_guideline = WranglingGuideline.new(params[:wrangling_guideline]) | ||
|
||
if @wrangling_guideline.save | ||
flash[:notice] = ts('Wrangling Guideline was successfully created.') | ||
redirect_to(@wrangling_guideline) | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
# PUT /wrangling_guidelines/1 | ||
def update | ||
@wrangling_guideline = WranglingGuideline.find(params[:id]) | ||
|
||
if @wrangling_guideline.update_attributes(params[:wrangling_guideline]) | ||
flash[:notice] = ts('Wrangling Guideline was successfully updated.') | ||
redirect_to(@wrangling_guideline) | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
# reorder FAQs | ||
def update_positions | ||
if params[:wrangling_guidelines] | ||
@wrangling_guidelines = WranglingGuideline.reorder(params[:wrangling_guidelines]) | ||
flash[:notice] = ts('Wrangling Guidelines order was successfully updated.') | ||
elsif params[:wrangling_guideline] | ||
params[:wrangling_guideline].each_with_index do |id, position| | ||
WranglingGuideline.update(id, :position => position + 1) | ||
(@wrangling_guidelines ||= []) << WranglingGuideline.find(id) | ||
end | ||
end | ||
redirect_to(wrangling_guidelines_path) | ||
end | ||
|
||
# DELETE /wrangling_guidelines/1 | ||
def destroy | ||
@wrangling_guideline = WranglingGuideline.find(params[:id]) | ||
@wrangling_guideline.destroy | ||
|
||
redirect_to(wrangling_guidelines_url) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class WranglingGuideline < ActiveRecord::Base | ||
acts_as_list | ||
|
||
attr_protected :content_sanitizer_version | ||
|
||
validates_presence_of :content, :title | ||
validates_length_of :content, :maximum => ArchiveConfig.CONTENT_MAX, | ||
:too_long => ts('cannot be more than %{max} characters long.', :max => ArchiveConfig.CONTENT_MAX) | ||
|
||
def self.reorder(positions) | ||
SortableList.new(self.find(:all, :order => 'position ASC')).reorder_list(positions) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<div class="admin"> | ||
<!--Descriptive page name, messages and instructions--> | ||
<h2 class="heading"><%= ts('Wrangling Guidelines') %></h2> | ||
<!--/descriptions--> | ||
|
||
<!--subnav--> | ||
<%= render 'admin/admin_nav' %> | ||
<ul class="navigation actions" role="navigation"> | ||
<li><%= link_to ts('New Wrangling Guideline'), new_wrangling_guideline_path %></li> | ||
<li><%= link_to ts('Reorder Wrangling Guidelines'), manage_wrangling_guidelines_path %></li> | ||
</ul> | ||
<!--/subnav--> | ||
|
||
<!--main content--> | ||
<h4 class="landmark heading"><%= ts("Manage Wrangling Guidelines") %></h3> | ||
<dl class="faq index group"> | ||
<% @wrangling_guidelines.each do |wrangling_guideline| %> | ||
<dt><%= link_to wrangling_guideline.title, wrangling_guideline %></dt> | ||
<dd> | ||
<p class="datetime"><%= ts('Created at') %> <%= wrangling_guideline.created_at %> <%= ts('and updated at') %> <%= wrangling_guideline.updated_at %></p> | ||
<ul class="navigation actions"> | ||
<li><%= link_to ts('Show'), wrangling_guideline %></li> | ||
<li><%= link_to ts('Edit'), edit_wrangling_guideline_path(wrangling_guideline) %></li> | ||
<li><%= link_to ts('Delete'), wrangling_guideline, :confirm => ts('Are you sure you want to delete this Wrangling Guideline?'), :method => :delete %></td> | ||
</dd> | ||
<% end %> | ||
</dl> | ||
<!--/content--> | ||
</div> |
43 changes: 43 additions & 0 deletions
43
app/views/wrangling_guidelines/_wrangling_guideline_form.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<%= form_for(@wrangling_guideline, html: { class: 'post' }) do |f| %> | ||
<%= error_messages_for @wrangling_guideline %> | ||
|
||
<p class="required notice"><%= ts('* Required information') %></p> | ||
<dl> | ||
|
||
<dt class="required"><%= f.label :title, ts('Title') + '*' %></dt> | ||
<dd> | ||
<%= f.text_field :title %> | ||
<%= live_validation_for_field('wrangling_guideline_title', :failureMessage => ts('Please enter a title.')) %> | ||
</dd> | ||
|
||
<dt class="required"><%= f.label :content, ts('Guideline text') + '*' %></dt> | ||
<dd class="required"> | ||
<ul class="hidden rtf-html-switch actions" role="menu"> | ||
<li><a class="rtf-link" href="#"><%= ts('Rich Text') %></a></li> | ||
<li><a class="html-link" href="#"><%= ts('HTML') %></a></li> | ||
</ul> | ||
<p class="rtf-html-instructions note"> | ||
<span class="html-notes"><%= allowed_html_instructions %></span> | ||
<span class="hidden rtf-notes"><%= ts('Type or paste formatted text.') %><%= link_to_help "rte-help" %></span> | ||
</p> | ||
<% use_tinymce %> | ||
<div class="rtf-html-field"> | ||
<%= f.text_area :content, :class => "mce-editor observe_textlength" %> | ||
<%= live_validation_for_field('wrangling_guideline_content', | ||
:maximum_length => ArchiveConfig.CONTENT_MAX, :minimum_length => ArchiveConfig.CONTENT_MIN, | ||
:tooLongMessage => ts('We salute your ambition! But sadly the content must be less than %{max} letters long.', :max => ArchiveConfig.CONTENT_MAX.to_s), | ||
:tooShortMessage => ts('Brevity is the soul of wit, but your content does have to be at least %{min} letters long.', :min => ArchiveConfig.CONTENT_MIN.to_s), | ||
:failureMessage => ts('You need to post some content here.')) | ||
%> | ||
<%= generate_countdown_html("content", ArchiveConfig.CONTENT_MAX) %> | ||
</div> | ||
</dd> | ||
|
||
<dt class="landmark"><%= ts('Post') %></dt> | ||
<dd class="submit actions"> | ||
<%= submit_tag ts('Post'), :name => 'post_button' %> | ||
</dd> | ||
|
||
</dl> | ||
<% end %> |
33 changes: 33 additions & 0 deletions
33
app/views/wrangling_guidelines/_wrangling_guideline_order.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<div id="manage-wrangling-guidelines"> | ||
<%= form_tag url_for(:action => 'update_positions') do %> | ||
<ul id="sortable_wrangling_guideline_list"> | ||
<% for wrangling_guideline in @wrangling_guidelines %> | ||
<li id="wrangling_guideline_<%= wrangling_guideline.id %>" class="wrangling_guideline-position-list"> | ||
<%= text_field_tag "wrangling_guidelines[]", nil, :size => 3, :maxlength => 3, :id => "wrangling_guidelines_#{wrangling_guideline.id}", :class => "number" %> | ||
<span id='position-for-<%= wrangling_guideline.id %>'><%= wrangling_guideline.position %></span>. | ||
<h3 class="heading"><%=h wrangling_guideline.title %></h3> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<p class="submit actions"><%= submit_tag ts('Update Positions') %></p> | ||
<% end %> | ||
</div> | ||
|
||
<%= content_for :footer_js do %> | ||
<%= javascript_tag do %> | ||
$j("#sortable_wrangling_guideline_list").sortable({ | ||
delay: 300, | ||
update: function(event, ui) { | ||
$j(".wrangling_guideline-position-list").each(function(index, li){ | ||
var faqId = $j(li).attr("id").replace("wrangling_guideline_",""); | ||
$j("#position-for-"+faqId).html(index+1); | ||
}); | ||
$j.ajax({ | ||
type: 'post', | ||
data: $j("#sortable_wrangling_guideline_list").sortable("serialize"), | ||
dataType: 'script', | ||
url: "<%= url_for(:action => :update_positions) %>"}) | ||
} | ||
}) | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!--Descriptive page name, messages and instructions--> | ||
<h2 class="heading"><%= ts('Edit Wrangling Guideline') %></h2> | ||
<!--/descriptions--> | ||
|
||
<!--subnav--> | ||
<%= render 'admin/admin_nav' %> | ||
<!--/subnav--> | ||
|
||
<!--main content--> | ||
<%= render 'wrangling_guideline_form' %> | ||
<!--/content--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!--Descriptive page name, messages and instructions--> | ||
<% if logged_in_as_admin? %> | ||
<%= render 'admin_index' %> | ||
<% else %> | ||
<h2 class="heading"><%= ts('Wrangling Guidelines') %></h2> | ||
<!--/descriptions--> | ||
|
||
<!--main content--> | ||
<div class="admin userstuff"> | ||
<% unless @wrangling_guidelines.blank? %> | ||
<h3><%= ts('Wrangling Guideline Sections') %></h3> | ||
<ol role="navigation"> | ||
<% for wrangling_guideline in @wrangling_guidelines %> | ||
<li><%= link_to wrangling_guideline.title, wrangling_guideline %></li> | ||
<% end %> | ||
</ol> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!--Descriptive page name, messages and instructions--> | ||
<h2 class="heading"><%= ts('Manage Wrangling Guidelines') %></h2> | ||
<!--/descriptions--> | ||
|
||
<!--subnav--> | ||
<%= render 'admin/admin_nav' %> | ||
<!--/subnav--> | ||
|
||
<!--main content--> | ||
<%= render 'wrangling_guideline_order' %> | ||
<!--/content--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!--Descriptive page name, messages and instructions--> | ||
<h2 class="heading"><%= ts('Create New Wrangling Guideline Section') %></h2> | ||
<!--/descriptions--> | ||
|
||
<!--subnav--> | ||
<%= render 'admin/admin_nav' %> | ||
<!--/subnav--> | ||
|
||
<!--main content--> | ||
<%= render 'wrangling_guideline_form' %> | ||
<!--/content--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!--Descriptive page name, messages and instructions--> | ||
<h2 class="heading"><%= link_to ts('Wrangling Guidelines'), wrangling_guidelines_path %> > <%= @wrangling_guideline.title %></h2> | ||
<!--/descriptions--> | ||
|
||
<!--subnav--> | ||
|
||
<!--/subnav--> | ||
|
||
<!--main content--> | ||
<div class="admin" role="article"> | ||
<% if logged_in_as_admin? %> | ||
<div class="header"> | ||
<h3 class="heading"> | ||
Updated: <%=h @wrangling_guideline.updated_at %> | <%= link_to ts('Edit'), edit_wrangling_guideline_path(@wrangling_guideline) %> | ||
</h3> | ||
</div> | ||
<% end %> | ||
<div class="userstuff"> | ||
<%=raw sanitize_field(@wrangling_guideline, :content) %> | ||
</div> | ||
</div> | ||
<!--/content--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateWranglingGuidelines < ActiveRecord::Migration | ||
def up | ||
create_table :wrangling_guidelines do |t| | ||
t.integer :admin_id | ||
t.string :title | ||
t.text :content | ||
t.datetime :created_at | ||
t.datetime :updated_at | ||
t.integer :position | ||
t.integer :content_sanitizer_version, :limit => 2, :default => 0, :null => false | ||
end | ||
end | ||
|
||
def down | ||
drop_table :wrangling_guidelines | ||
end | ||
end |
Oops, something went wrong.