added security type models, improved cashflow, bug- and layout fixes along the way
[smr.git] / gui / app / controllers / objects / organization_controller.rb
blobe85d1d7695cc8da6b745cc23551d5fb51eef66cf
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
7 # version.
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/>.
18 # handles CRUD on Organization records
19 class Objects::OrganizationController < ObjectsController
20     def index
21         super
22         @organizations, @total_pages = smr_paginate(
23             @page = smr_page,
24             Organization.all.order(:name).to_a
25         )
26     end
28     ##
29     # defines empty Organization to create() a new one
30     def new
31         self.index
32         @organization = Organization.new
33         render :index
34     end
36     ##
37     # edit existing Organization
38     def edit
39         self.index
40         @organization = Organization.where(:id=>params[:id]).first
41         render :index
42     end
44     ##
45     # handles creates and updates
46     def create
47         if params[:organization][:id].to_i > 0 then
48             o = Organization.where(:id=>params[:organization][:id]).first
49         else o = Organization.new(organization_params) end
51         # hard-wired so noone spoofes it in here
52         # FIXME: how to handle properly? given 0 _or_ current user id
53 #        fv.id_user = current_user.id
55         if params[:organization][:id].to_i > 0 then
56             o.update(organization_params)
57         else o.save end
59         redirect_to objects_organization_index_path, :notice=>o.errors.full_messages.uniq.join(', ')
60     end
62  protected
64     ##
65     # internal helper defining parameters acceptable for Organization create/update
66     def organization_params
67         params.require(:organization).permit(
68           :name, :url, :contact_email, :description,
69         )
70     end
71 end