webui: show result of saving attributes
[opensuse:build-service.git] / src / webui / app / controllers / attribute_controller.rb
1 class AttributeController < ApplicationController
2
3   before_filter :requires
4
5   def index
6   end
7
8   def show
9   end  
10
11
12   def edit
13     all_attributes = Attribute.find(:all, :namespace => "OBS")
14     @attribute_list = []  
15     all_attributes.attributes.each_definition do |d|
16       @attribute_list << "#{d.namespace}:#{d.name}"
17     end
18    
19     @attribute.each do |d|
20       @attribute_list.delete(d.name)  
21     end
22      
23     @selected_attribute = params[:attribute] if params[:attribute]
24     
25   end
26
27   def save
28     values = params[:values].split(',')
29      
30     @attribute.set(params[:attribute], values)
31     result = @attribute.save
32     
33     opt = {:controller => "attribute", :action => "show", :project => @project.name }
34     opt.store( :package, params[:package] ) if params[:package]
35     
36     flash[result[:type]] = result[:msg]
37     redirect_to opt
38   end
39
40   def delete
41     result = @attribute.delete(params[:attribute])
42     flash[result[:type]] = result[:msg]
43
44     opt = {:controller => "attribute", :action => "show", :project => @project.name }
45     opt.store( :package, params[:package] ) if params[:package]
46
47     redirect_to opt
48   end
49
50 private
51
52   def requires
53     begin
54       @project = Project.find( params[:project] )
55       @package = params[:package] if params[:package]
56       opt = {:project => @project.name}
57       opt.store(:package, @package.to_s) if @package
58       @attribute = Attribute.find(opt)
59     rescue ActiveXML::Transport::NotFoundError => e
60       flash[:error] = "Project not found: #{params[:project]}"
61       redirect_to :controller => "project", :action => "list_public"
62       return
63     end
64   end
65
66 end