Browse files

Added jQuery styling to forms, added confirmation step to emailing

  • Loading branch information...
1 parent 82a73f2 commit 6b45800ca7f5cba8fac15b1782cca5540d5a697c Michael B. Klein committed May 22, 2010
View
18 app/controllers/barcode_controller.rb → app/controllers/barcodes_controller.rb
@@ -1,14 +1,22 @@
-class BarcodeController < ApplicationController
+class BarcodesController < ApplicationController
+ before_filter :cancel?, :only => [ :send_mail ]
+
+ def cancel?
+ if params[:commit] == 'Cancel'
+ redirect_to '/barcode'
+ end
+ end
def display_form
- render :html => 'display_form'
end
def send_mail
+ @confirmed = params[:commit] == 'Confirm'
@institution = Institution.find(params[:institution_id])
- @barcodes = params[:barcodes].split(/[\s\n,]+/)
- BarcodeMailer.deliver_barcodes(@institution, @barcodes)
- render :html => 'send_mail'
+ @barcodes = params[:barcodes].split(/[\s\n,;:]+/)
+ if @confirmed
+ BarcodeMailer.deliver_barcodes(@institution, @barcodes)
+ end
end
def image
View
12 app/controllers/institutions_controller.rb
@@ -1,4 +1,12 @@
class InstitutionsController < ApplicationController
+ before_filter :cancel?, :only => [ :create, :update ]
+
+ def cancel?
+ if params[:commit] == 'Cancel'
+ redirect_to institutions_path
+ end
+ end
+
# GET /institutions
# GET /institutions.xml
def index
@@ -45,7 +53,7 @@ def create
respond_to do |format|
if @institution.save
flash[:notice] = 'Institution was successfully created.'
- format.html { redirect_to(@institution) }
+ format.html { redirect_to institutions_path }
format.xml { render :xml => @institution, :status => :created, :location => @institution }
else
format.html { render :action => "new" }
@@ -62,7 +70,7 @@ def update
respond_to do |format|
if @institution.update_attributes(params[:institution])
flash[:notice] = 'Institution was successfully updated.'
- format.html { redirect_to(@institution) }
+ format.html { redirect_to institutions_path }
format.xml { head :ok }
else
format.html { render :action => "edit" }
View
2 app/models/institution.rb
@@ -14,7 +14,7 @@ def barcode_format
end
def symbology_name
- SymbologyNames[symbology]
+ SymbologyNames[symbology-1]
end
def symbology_name=(value)
View
11 app/views/barcode/send_mail.erb
@@ -1,11 +0,0 @@
-<p>To: <%= @institution.email %></p>
-<% @barcodes.in_groups_of(2).each { |group| -%>
- <p>
- <% group.each { |code| -%>
- <% unless code.nil? -%>
- <img src="/barcode/<%= @institution.id %>/<%= code %>">
- <% end -%>
- <% } -%>
- </p>
-<% } -%>
-
View
2 app/views/barcode/display_form.erb → app/views/barcodes/display_form.erb
@@ -1,3 +1,5 @@
+<h1>Scan barcodes</h1>
+
<% form_tag('/barcode', :method => :post) do -%>
<p>Institution: <%= select_tag 'institution_id', Institution.find(:all).collect { |inst| %{<option value="#{inst.id}">#{inst.name}</option>}}.join('') %></p>
<p>
View
21 app/views/barcodes/send_mail.erb
@@ -0,0 +1,21 @@
+<h1>Send barcodes</h1>
+<% unless @confirmed -%>
+ <span style="color:red">Please confirm that you wish to send the following <%= @barcodes.length %> barcodes to <b><%= @institution.name %></b> to be checked in.</span>
+ <% form_tag('/barcode', :method => :post) do -%>
+ <%= hidden_field_tag 'institution_id', @institution.id %>
+ <%= hidden_field_tag 'barcodes', @barcodes.join(';') -%>
+ <%= submit_tag 'Confirm' -%>
+ <%= submit_tag 'Cancel' -%>
+ <% end -%>
+<% end -%>
+<p>To: <%= @institution.email %></p>
+<% @barcodes.in_groups_of(2).each { |group| -%>
+ <p>
+ <% group.each { |code| -%>
+ <% unless code.nil? -%>
+ <img src="/barcode/<%= @institution.id %>/<%= code %>">
+ <% end -%>
+ <% } -%>
+ </p>
+<% } -%>
+
View
16 app/views/institutions/_form.html.erb
@@ -0,0 +1,16 @@
+<% form_for(@institution, :html => { :class => 'ui-widget' }) do |f| %>
+ <%= f.error_messages %>
+ <%= f.label :name, 'Name' %>
+ <%= f.text_field :name, :size => 60 %><br/>
+ <%= f.label :email, 'Email' %>
+ <%= f.text_field :email, :size => 60 %><br/>
+ <%= f.label :symbology, 'Symbology' %>
+ <%= select_tag 'institution[symbology]', options_for_select(Institution::SymbologyNames.inject([]) { |r,i| r << [i,r.length+1] }, @institution.symbology) %>
+ <%= f.label :checksum, 'Checksum?' %>
+ <%= f.check_box :checksum %>
+
+ <p>
+ <%= f.submit 'Submit' %>
+ <%= f.submit 'Cancel' %>
+ </p>
+<% end %>
View
20 app/views/institutions/edit.html.erb
@@ -1,21 +1,3 @@
<h1>Editing institution</h1>
-<% form_for(@institution) do |f| %>
- <%= f.error_messages %>
- <%= f.label :name, 'Name' %>
- <%= f.text_field :name, :size => 60 %><br/>
- <%= f.label :email, 'Email' %>
- <%= f.text_field :email, :size => 45 %><br/>
- <%= f.label :symbology, 'Symbology' %>
- <%= select_tag 'symbology', options_for_select(Institution::SymbologyNames.inject([]) { |r,i| r << [i,r.length+1] }, @institution.symbology) %>
- <br/>
- <%= f.label :checksum, 'Checksum?' %>
- <%= f.check_box :checksum %>
-
- <p>
- <%= f.submit 'Update' %>
- </p>
-<% end %>
-
-<%= link_to 'Show', @institution %> |
-<%= link_to 'Back', institutions_path %>
+<%= render :partial => 'form' %>
View
26 app/views/institutions/index.html.erb
@@ -1,36 +1,40 @@
<script type="text/javascript">
$(document).ready(function() {
- $('#institution_table').dataTable();
+ $('#institution_table').dataTable();
});
</script>
<h1>Listing institutions</h1>
-<table id="institution_table">
+<table id="institution_table" class="ui-widget-container ui-state-default ui-corner-all">
<thead>
<tr>
+ <th>&nbsp;</th>
+ <th>&nbsp;</th>
<th>Name</th>
<th>Email</th>
<th>Format</th>
<th>Checksum</th>
- <th>&nbsp;</th>
- <th>&nbsp;</th>
</tr>
</thead>
- <tbody>
+ <tbody class="ui-widget-content">
<% @institutions.each do |institution| %>
<tr>
+ <td class="ui-state-default ui-corner-all"><%= link_to '<span class="ui-icon ui-icon-pencil"></span>', edit_institution_path(institution) %></td>
+ <td class="ui-state-default ui-corner-all"><%= link_to '<span class="ui-icon ui-icon-trash"></span>', institution, :confirm => 'Are you sure?', :method => :delete %></td>
<td><%= institution.name %></td>
<td><%= institution.email %></td>
<td><%= institution.symbology_name %></td>
<td><%= institution.checksum ? 'Yes' : 'No' %></td>
- <td><%= link_to image_tag('/images/icons/page_edit.png', :alt => 'Edit'), edit_institution_path(institution) %></td>
- <td><%= link_to image_tag('/images/icons/page_delete.png', :alt => 'Delete'), institution, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
+<tr>
+ <td class="ui-state-default ui-corner-all"><%= link_to '<span class="ui-icon ui-icon-plus"></span>', new_institution_path %></td>
+ <td>&nbsp;</td>
+ <td>&nbsp;</td>
+ <td>&nbsp;</td>
+ <td>&nbsp;</td>
+ <td>&nbsp;</td>
+</tr>
</tbody>
</table>
-
-<br />
-
-<%= link_to image_tag('/images/icons/page_add.png', :alt => "Add New"), new_institution_path %>
View
16 app/views/institutions/new.html.erb
@@ -1,17 +1,3 @@
<h1>New institution</h1>
-<% form_for(@institution) do |f| %>
- <%= f.label :name, 'Name' %>
- <%= f.text_field :name, :size => 30 %>
- <%= f.label :email, 'Email' %>
- <%= f.text_field :email, :size => 20 %>
- <%= f.label :symbology, 'Symbology' %>
- <%= select_tag 'symbology', options_for_select(Institution::SymbologyNames.inject([]) { |r,i| r << [i,r.length+1] }, @institution.symbology_name) %>
- <%= f.label :checksum, 'Checksum?' %>
- <%= f.check_box :checksum %>
- <p>
- <%= f.submit 'Create' %>
- </p>
-<% end %>
-
-<%= link_to 'Back', institutions_path %>
+<%= render :partial => 'form' %>
View
23 app/views/layouts/barcodes.html.erb
@@ -0,0 +1,23 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>Barcodes: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag('ui-lightness/jquery-ui-1.8.1.custom.css') %>
+ <%= stylesheet_link_tag('dt_page.css') %>
+ <%= stylesheet_link_tag('data_table.css') %>
+ <%= stylesheet_link_tag('data_table_jui.css') %>
+ <%= javascript_include_tag('jquery-1.4.2.min.js') %>
+ <%= javascript_include_tag('jquery-ui-1.8.1.custom.min.js') %>
+ <%= javascript_include_tag('jquery.dataTables.min.js') %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+<div id="container">
+<%= yield %>
+</div>
+</body>
+</html>
View
5 app/views/layouts/institutions.html.erb
@@ -6,6 +6,7 @@
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Institutions: <%= controller.action_name %></title>
<%= stylesheet_link_tag('ui-lightness/jquery-ui-1.8.1.custom.css') %>
+ <%= stylesheet_link_tag('dt_page.css') %>
<%= stylesheet_link_tag('data_table.css') %>
<%= stylesheet_link_tag('data_table_jui.css') %>
<%= javascript_include_tag('jquery-1.4.2.min.js') %>
@@ -15,8 +16,8 @@
<body>
<p style="color: green"><%= flash[:notice] %></p>
-
+<div id="container">
<%= yield %>
-
+</div>
</body>
</html>
View
6 config/routes.rb
@@ -3,9 +3,9 @@
# The priority is based upon order of creation: first created -> highest priority.
- map.connect 'barcode', :controller => 'barcode', :action => 'display_form', :conditions => { :method => :get }
- map.connect 'barcode', :controller => 'barcode', :action => 'send_mail' , :conditions => { :method => :post }
- map.connect 'barcode/:institution_id/:string', :controller => 'barcode', :action => 'image'
+ map.connect 'barcode', :controller => 'barcodes', :action => 'display_form', :conditions => { :method => :get }
+ map.connect 'barcode', :controller => 'barcodes', :action => 'send_mail' , :conditions => { :method => :post }
+ map.connect 'barcode/:institution_id/:string', :controller => 'barcodes', :action => 'image'
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
View
93 public/stylesheets/dt_page.css
@@ -0,0 +1,93 @@
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * General page setup
+ */
+body {
+ font: 80%/1.45em "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
+ margin: 0;
+ padding: 0;
+ color: #333;
+ background-color: #fff;
+}
+
+
+body #container {
+ width: 800px;
+ margin: 30px auto;
+ padding: 0;
+}
+
+
+body #footer {
+ margin: 50px auto 0 auto;
+ padding: 0;
+}
+
+body #demo {
+ margin: 30px auto 0 auto;
+}
+
+body .demo_jui {
+ margin: 30px auto 0 auto;
+}
+
+body .big {
+ font-size: 1.3em;
+ font-weight: bold;
+ line-height: 1.6em;
+ color: #4E6CA3;
+}
+
+body .spacer {
+ height: 20px;
+ clear: both;
+}
+
+body .clear {
+ clear: both;
+}
+
+body pre {
+ padding: 15px;
+ background-color: #F5F5F5;
+ border: 1px solid #CCCCCC;
+}
+
+body h1 {
+ margin-top: 2em;
+ font-size: 1.3em;
+ font-weight: normal;
+ line-height: 1.6em;
+ color: #4E6CA3;
+ border-bottom: 1px solid #B0BED9;
+ clear: both;
+}
+
+body h2 {
+ font-size: 1.2em;
+ font-weight: normal;
+ line-height: 1.6em;
+ color: #4E6CA3;
+ clear: both;
+}
+
+body a {
+ color: #0063DC;
+ text-decoration: none;
+}
+
+body a:hover {
+ text-decoration: underline;
+}
+
+body ul {
+ color: #4E6CA3;
+}
+
+.css_right {
+ float: right;
+}
+
+.css_left {
+ float: left;
+}

0 comments on commit 6b45800

Please sign in to comment.