Class: DrawMethodController

Inherits:
ApplicationController show all
Defined in:
app/controllers/draw_method_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/draw_method_controller.rb', line 10

def create
  user = (=session[:user]) && User.()
  @directory = "/usr/#{user.}/draw_methods"
  case request.method
  when :post
    @draw_method = DrawMethod.new
    @draw_method.attributes = params[:draw_method]
    @draw_method.owner = user
    @draw_method.path = "#{@directory}/#{@draw_method.name}"
    attribute_num = params[:attribute_num].to_i
    attribute_num.times{|i|
      param = params[:attribute][i.to_s]
      value_type = param.delete(:value_type)
      dma = @draw_method.draw_method_attributes.create(param)
      dma.value_type = ValueType.find(:first,:conditions=>["name=?",value_type])
    }
    Node.make_user_directory(@directory, user, 0)
    groups = params[:groups]
    groups.shift if groups[0] == 'only me'
    @draw_method.other_mode = 0
    @draw_method.set_rgroups(groups) if groups.length > 0
    if check_erb(@draw_method) && check_srcipt(@draw_method)
      if @draw_method.save
        flash[:notice] = "create successful"
        redirect_back_or_default :action => "list"
      else
        flash[:notice] = "create unsuccessful"
      end
    end
  when :get
    @draw_method = DrawMethod.new
  end
  @groups = user.own_groups + user.belonging_groups
  @user = user
end

#create_setting_htmlObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/controllers/draw_method_controller.rb', line 119

def create_setting_html
  unless request.xhr?
    render :nothing => true
    return
  end
  name = params[:name]
  nattr = params[:nattr].to_i
  attrs = params[:attribute]
  html = ""
  if nattr > 0
    html += "<table>\n"
    nattr.times{|n|
      html += "  <tr>\n"
      attr = attrs[n.to_s]
      html +=<<-"EOS"
  <td>#{attr["name"]}</td>
  <td>(#{attr["value_type"]})</td>
  <td><input type="text" size="5" value="#{attr["default"]}" name="analysis[#{name}_#{attr["name"]}][#{n}]"/></td>
      EOS
      html += "  </tr>\n"
    }
    html += "</table>\n"
  end
  render :update do |page|
    page << "$('draw_method_setting_html').value='#{escape_javascript(html)}'"
  end
end

#detailsObject



106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/draw_method_controller.rb', line 106

def details
  name = params[:id]
  user = (=session[:user]) && User.()
  dm = DrawMethod.find(:first, :conditions=>["name=?",name], :user=>user)
  if dm
    @draw_method = dm
    @user = user
  else
    redirect_back_or_default :action => "list"
    return
  end
end

#editObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/draw_method_controller.rb', line 46

def edit
  user = (=session[:user]) && User.()
  @draw_method = DrawMethod.find(:first, :conditions=>["name=?",params[:id]], :user=>user)
  unless @draw_method && @draw_method.owner==user
    redirect_back_or_default :action => "list"
    return
  end
  @directory = "/usr/#{user.}/draw_methods"
  case request.method
  when :post
    @draw_method.attributes = params[:draw_method]
    attribute_num = params[:attribute_num].to_i
    dmas = @draw_method.draw_method_attributes
    attribute_num.times{|i|
      param = params[:attribute][i.to_s]
      value_type = param.delete(:value_type)
      if dmas[i]
        dma = dmas[i]
        dma.attributes = param
      else
        dma = dmas.create(param)
      end
      dma.value_type = ValueType.find(:first,:conditions=>["name=?",value_type])
      dma.update
    }
    for i in attribute_num...dmas.length
      dmas[i].destroy
    end
    groups = params[:groups]
    groups.shift if groups[0] == 'only me'
    @draw_method.other_mode = 0
    @draw_method.set_rgroups(groups) if groups.length > 0
    if check_erb(@draw_method) && check_srcipt(@draw_method)
      if @draw_method.update
        flash[:notice] = "edit successful"
        redirect_back_or_default :action => "list"
      else
        flash[:notice] = "edit unsuccessful"
      end
    end
  end
  @groups = user.own_groups + user.belonging_groups
  @user = user
end

#indexObject



6
7
8
# File 'app/controllers/draw_method_controller.rb', line 6

def index
  redirect_to :action => "list"
end

#listObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/draw_method_controller.rb', line 91

def list
   user = (=session[:user]) && User.()
   dms = DrawMethod.find(:all, :user => user)
   @own_dms = Array.new
   @other_dms = Array.new
   dms.each{|dm|
     if dm.owner == user
       @own_dms.push dm
     else
       @other_dms.push dm
     end
   }
   @super_user = user.super_user
end