2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
16 require 'smr_document'
19 # Controller for all sorts of SmrDocument things.
21 # This shows all documents available for the user, no matter where they've been
22 # attached to, when or if.
23 class DocumentsController < ApplicationController
27 @documents = SmrDocuments.new(current_user.id)
28 @portfolios = Portfolio.where(:id_user=>current_user.id).order(order: :asc)
29 @new_document = Document.new
33 # save broser-supplied file content as new Document
35 uploaded_file = params[:new_document][:content]
38 d = store_new_document(current_user.id, uploaded_file, params[:new_document][:comment])
39 n = 'saved file %s' % uploaded_file.original_filename
41 n = 'please select a file first'
43 redirect_to :back, :notice=>n
47 # serve DocumentData file content with correct mimetype to the browser
50 d = SmrDocument.new(params[:id], current_user.id)
52 send_data(d.data, :type=>d.mimetype, :filename=>d.filename, :disposition=>'attachment', :length=>d.size)
55 n = 'requested document #%i does not exist' % params[:id]
58 n = 'please specify a document id to download'
60 redirect_to :back, :notice=>n
64 # delete Document with DocumentData and DocumentAssign associations
67 # - the standard way in Rails to delete a record requires JavaScript, but
68 # SMr is ment to work without it
69 # - therefore deletion is implemented as non-standard action with seperate
72 d = Document.where(:id_user=>current_user.id, :id=>params[:id]).first
74 redirect_to :back, :notice=>'deleted document and its associations'