Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added file upload functionality to Tickets, Clients, and Devices
- Loading branch information
Jonathan Hoyt
authored and
Jonathan Hoyt
committed
Dec 12, 2008
1 parent
7a2b11d
commit ef57ef6
Showing
24 changed files
with
294 additions
and
165 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,88 @@ | ||
class ThingsController < ApplicationController | ||
before_filter :login_required | ||
layout nil | ||
|
||
def index | ||
@things = Thing.find(:all) | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.xml { render :xml => @things } | ||
end | ||
end | ||
|
||
# GET /things/1 | ||
# GET /things/1.xml | ||
def show | ||
@thing = Thing.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.xml { render :xml => @thing } | ||
end | ||
end | ||
|
||
# GET /things/new | ||
# GET /things/new.xml | ||
def new | ||
@thing = Thing.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @thing } | ||
end | ||
end | ||
|
||
# GET /things/1/edit | ||
def edit | ||
@thing = Thing.find(params[:id]) | ||
end | ||
|
||
# POST /things | ||
# POST /things.xml | ||
def create | ||
@thing = Thing.new(params[:thing]) | ||
@thing.attached_id = params[:thing][:attached_id] | ||
@thing.attached_type = params[:thing][:attached_type] | ||
|
||
respond_to do |format| | ||
if @thing.save | ||
flash[:notice] = 'Thing was successfully created.' | ||
format.html { redirect_to :back } | ||
format.xml { render :xml => @thing, :status => :created, :location => @thing } | ||
else | ||
format.html { redirect_to :back } | ||
format.xml { render :xml => @thing.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /things/1 | ||
# PUT /things/1.xml | ||
def update | ||
@thing = Thing.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @thing.update_attributes(params[:thing]) | ||
flash[:notice] = 'Thing was successfully updated.' | ||
format.html { redirect_to(@thing) } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @thing.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /things/1 | ||
# DELETE /things/1.xml | ||
def destroy | ||
@thing = Thing.find(params[:id]) | ||
@thing.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(things_url) } | ||
format.xml { head :ok } | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
module ThingsHelper | ||
end |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
class Thing < ActiveRecord::Base | ||
belongs_to :attached, :polymorphic => true | ||
|
||
has_attached_file :attachment, :whiny_thumbnails => false | ||
|
||
validates_attachment_presence :attachment | ||
validates_attachment_size :attachment, :less_than => 200.megabytes, :message => "File is too large." | ||
|
||
before_create :assign_name | ||
|
||
def assign_name | ||
self.name.blank? ? self.name = self.attachment_file_name : true | ||
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
<div id="files"> | ||
<ul class="toolbar"> | ||
<li><a href="javascript:void(0)" class="upload_file">Upload File</a></li> | ||
</ul> | ||
<div id="upload_file_form" class="hide toolbox"> | ||
<h3>Upload File</h3> | ||
<% form_for @client.things.new, :html => { :multipart => true } do |f| %> | ||
<table class="m"> | ||
<tr><td>Name:</td><td><%= f.text_field :name %></td></tr> | ||
<tr><td>File:</td><td><%= f.file_field :attachment %></td></tr> | ||
<tr><td>Description:</td><td><%= f.text_area :description, :style => "height:50px" %></td></tr> | ||
</table> | ||
<%= f.hidden_field :attached_id, :value => @client.id %> | ||
<%= f.hidden_field :attached_type, :value => "Client" %> | ||
<%= f.submit %> | ||
<% end %> | ||
<br /> | ||
</div> | ||
<h3>Files Attached to this Ticket</h3> | ||
<table class="itu"> | ||
<tr><th>Name</th><th>Description</th><th>Size</th><th>Action</th></tr> | ||
<% @client.things.each do |thing| %> | ||
<tr> | ||
<td><%= link_to thing.name, thing.attachment.url %></td> | ||
<td><%= link_to thing.description, thing.attachment.url %></td> | ||
<td><%= link_to thing.attachment_file_size, thing.attachment.url %></td> | ||
<td> | ||
<div class="delete_file"> | ||
<%= link_to_remote image_tag("/images/icons/delete.png"), :url => thing_url(thing), :method => :delete %> | ||
</div> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
</div> | ||
|
||
<script> | ||
// setup device tab buttons | ||
$("a.upload_file").bind("click", function(){ | ||
$("#upload_file_form").slideDown(1000); | ||
}); | ||
$("div.delete_file a").click(function(){ | ||
$(this).parent().parent().parent().slideUp("slow"); | ||
}); | ||
</script> |
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,45 @@ | ||
<div id="files"> | ||
<ul class="toolbar"> | ||
<li><a href="javascript:void(0)" class="upload_file">Upload File</a></li> | ||
</ul> | ||
<div id="upload_file_form" class="hide toolbox"> | ||
<h3>Upload File</h3> | ||
<% form_for @device.things.new, :html => { :multipart => true } do |f| %> | ||
<table class="m"> | ||
<tr><td>Name:</td><td><%= f.text_field :name %></td></tr> | ||
<tr><td>File:</td><td><%= f.file_field :attachment %></td></tr> | ||
<tr><td>Description:</td><td><%= f.text_area :description, :style => "height:50px" %></td></tr> | ||
</table> | ||
<%= f.hidden_field :attached_id, :value => @device.id %> | ||
<%= f.hidden_field :attached_type, :value => "Device" %> | ||
<%= f.submit %> | ||
<% end %> | ||
<br /> | ||
</div> | ||
<h3>Files Attached to this Ticket</h3> | ||
<table class="itu"> | ||
<tr><th>Name</th><th>Description</th><th>Size</th><th>Action</th></tr> | ||
<% @device.things.each do |thing| %> | ||
<tr> | ||
<td><%= link_to thing.name, thing.attachment.url %></td> | ||
<td><%= link_to thing.description, thing.attachment.url %></td> | ||
<td><%= link_to thing.attachment_file_size, thing.attachment.url %></td> | ||
<td> | ||
<div class="delete_file"> | ||
<%= link_to_remote image_tag("/images/icons/delete.png"), :url => thing_url(thing), :method => :delete %> | ||
</div> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
</div> | ||
|
||
<script> | ||
// setup device tab buttons | ||
$("a.upload_file").bind("click", function(){ | ||
$("#upload_file_form").slideDown(1000); | ||
}); | ||
$("div.delete_file a").click(function(){ | ||
$(this).parent().parent().parent().slideUp("slow"); | ||
}); | ||
</script> |
Oops, something went wrong.