More resource adding

This commit is contained in:
2014-02-09 03:42:17 -07:00
parent 74e60d4ec9
commit 23dcb0715c
11 changed files with 277 additions and 14 deletions

View File

@@ -0,0 +1,69 @@
<%= form_for @resource, :html => { :multipart => true } do |f| %>
<% if @resource.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@resource.errors.count, "error") %> prohibited this resource from being saved:</h2>
<ul>
<% @resource.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :category_id %><br />
<%= select(:resource, :category_id, options_from_collection_for_select(ResourceCategory.all.sort_by(&:name), :id, :name, @resource.category_id ) ) %>
</p>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :serial, "Serial" %>
<br />
<%= f.text_field :serial %>
</p>
<p>
<%= f.label :specs, "Specs" %>
<br/>
<%= f.text_field :specs %>
</p>
<p>
<%= f.label :status, "Status/Location" %>
<br/>
<%= f.text_field :status %>
</p>
<% if can? :assign_user, @resource %>
<p>
<%= f.label :user_id, "Owner" %>
<br />
<%= select(:resource, :user_id, options_from_collection_for_select(@users, :id, :name, @resource.user_id), include_blank: true) %>
</p>
<% end %>
<p>
<%= f.label :donatable %><br />
<%= f.check_box :donatable %>
</p>
<p>
<%= f.label :estimated_value, "Estimated Value" %><br />
<%= f.text_field :estimated_value %>
</p>
<p>
<%= f.label :picture %><br />
<%= f.file_field :picture %>
<%= link_to image_tag(@resource.picture.url(:tiny)), @resource.picture.url, :popup => ['form_image_preview', 'height=300,width=400'] if @resource.picture? %>
</p>
<p>
<%= f.label :notes %><br />
<%= f.text_area :notes %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
<%= link_to 'Back', resources_path %>

View File

@@ -1,9 +1,11 @@
<div class="col-sm-2">
<div class="thumbnail">
<% if resource.user %>
<span class="ownership">Owned by:<br/><%= resource.user.name %></span>
<% end %>
<%= link_to(resource) do %>
<%= image_tag(resource.picture.url(:thumb)) if resource.picture? %>
<strong><%=h resource.name %></strong>
<h4><%=h resource.name %></h4>
<% end %>
<%= "Owned by "+resource.user.name if resource.user %>
</div>
</div>

View File

@@ -0,0 +1,2 @@
<h1>Edit Resource</h1>
<%= render 'form' %>

View File

@@ -1,23 +1,28 @@
<h1>Resources</h1>
<h1>Lab Resources
<%= link_to 'Add Resource', new_resource_path, :class => "btn btn-success" if can? :create, Resource %>
</h1>
<%= link_to 'Add Equipment', new_resource_path, :class => "btn" if can? :create, Resource %>
<link href="/bootstrap/css/bootstrap-theme.min.css" type="text/css" />
<link href="/bootstrap/css/bootstrap.min.css" type="text/css" />
<script src="/bootstrap/js/bootstrap.min.js" type="text/javascript" ></script>
<style>
.collapsible .thumbnail { height: 150px; }
#accordion .thumbnail { height: 150px; position: relative; }
#accordion .thumbnail .ownership { position: absolute; top: 1px; text-shadow: 0.1em 0.1em 0.2em white; font-weight: bold; left: 10px; }
#accordion .thumbnail h4 { position: absolute; bottom: 1px; margin-bottom: 1px; }
</style>
<% unless @resources.blank? %>
<div class="panel-group" id="accordion">
<div class="panel-group col-sm-8" id="accordion">
<% @resources.sort_by{|r| [r.category_name,r.name] }.group_by(&:category).each do |category,resources| %>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-heading" data-toggle="collapse" data-parent="#accordion" href="#collapse_cat_<%= category.id %>">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
<%= category.name %>
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div id="collapse_cat_<%= category.id %>" class="panel-collapse collapse">
<div class="panel-body">
<%= render resources %>
</div>

View File

@@ -0,0 +1,2 @@
<h1>New Resource</h1>
<%= render 'form' %>

View File

@@ -0,0 +1,45 @@
<%= link_to image_tag(@resource.picture.url(:medium)), @resource.picture.url, :popup => ['show_image_preview', 'height=300,width=400'] if @resource.picture? %>
<h2><%=h @resource.name %>
<%= link_to 'Back', resources_path, class: "btn btn-default" %>
<%= link_to 'Edit', edit_resource_path(@resource), class: "btn btn-primary" %>
<%= link_to 'Delete', resource_path(@resource), {:confirm => 'Are you sure you want to delete this forever?', :method => :delete, :class => "btn btn-danger"} if can? :destroy, @resource %>
</h2>
<p>
<b>Category:</b>
<%=h @resource.category.name if !@resource.category.blank? %>
</p>
<p>
<b>Serial:</b>
<%=h @resource.serial %>
</p>
<p>
<b>Specs:</b>
<%=h @resource.specs %>
</p>
<p>
<b>Status/Location:</b>
<%=h @resource.status %>
</p>
<p>
<b>Donatable:</b>
<%=h @resource.donatable %>
</p>
<p>
<b>Estimated Value:</b>
<%=h @resource.estimated_value %>
</p>
<p>
<b>Notes:</b>
<%=h @resource.notes %>
</p>