manage bookmarks, bugfixes
[smr.git] / gui / app / controllers / objects / figurevar_controller.rb
blob9555b8cf3acc9ed9b33a4dd28af139bbd8657649
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 FigureVar records
19 class Objects::FigurevarController < ObjectsController
20     def index
21         super
22         @figurevars, @total_pages = smr_paginate(
23             @page = smr_page,
24             FigureVar.where(:id_user=>[0,current_user.id]).order(:name).to_a
25         )
26     end
28     ##
29     # defines empty FigureVar to create() a new one
30     def new
31         @figurevar = FigureVar.new
32     end
34     ##
35     # edit existing FigureVar
36     def edit
37         @figurevar = FigureVar.where(:id=>params[:id]).for_user(current_user.id).first
38         render :new
39     end
41     ##
42     # handles creates and updates
43     def create
44         if params[:figure_var][:id].to_i > 0 then
45             fv = FigureVar.where(:id=>params[:figure_var][:id]).for_user(current_user.id).first
46         else fv = FigureVar.new(figurevar_params) end
48         # hard-wired so noone spoofes it in here
49         # FIXME: how to handle properly? given 0 _or_ current user id
50 #        fv.id_user = current_user.id
52         if params[:figure_var][:id].to_i > 0 then
53             fv.update(figurevar_params)
54         else fv.save end
56         redirect_to objects_figurevar_index_path, :notice=>fv.errors.full_messages.uniq.join(', ')
57     end
59  protected
61     ##
62     # internal helper defining parameters acceptable for FigureVar create/update
63     def figurevar_params
64         params.require(:figure_var).permit(
65           :name, :unit, :expression, :comment,
66           :Bookmark_attributes=> [ :id, :name, :url, :rank ]
67         )
68     end
69 end