@@ -11,29 +11,6 @@ def old_dialogs_get_form_vars
1111 @edit [ :new ] [ :content ] = @edit [ :new ] [ :content ] + "..." if !params [ :name ] && !params [ :description ] && !params [ :dialog_type ] && !params [ :content_data ]
1212 end
1313
14- # Set form variables for edit
15- def old_dialogs_set_form_vars
16- @edit = { }
17- @edit [ :dialog ] = @dialog
18-
19- @edit [ :new ] = { }
20- @edit [ :current ] = { }
21- @edit [ :key ] = "dialog_edit__#{ @dialog . id || "new" } "
22-
23- @edit [ :new ] [ :name ] = @dialog . name
24- @edit [ :new ] [ :description ] = @dialog . description
25- @edit [ :new ] [ :dialog_type ] = if @dialog . dialog_type
26- @dialog . dialog_type
27- else
28- # if new customization dialogs, check if add button was pressed form folder level, to auto select image type
29- x_node == "root" ? @dialog . dialog_type : x_node . split ( '_' ) [ 1 ]
30- end
31-
32- @edit [ :new ] [ :content ] = @dialog . content . to_yaml
33- @edit [ :current ] = copy_hash ( @edit [ :new ] )
34- session [ :edit ] = @edit
35- end
36-
3714 def old_dialogs_set_record_vars ( dialog )
3815 dialog . name = @edit [ :new ] [ :name ]
3916 dialog . description = @edit [ :new ] [ :description ]
@@ -161,15 +138,30 @@ def old_dialogs_list
161138 def old_dialogs_new
162139 assert_privileges ( "old_dialogs_new" )
163140 @dialog = MiqDialog . new
164- old_dialogs_set_form_vars
141+ @dialog . dialog_type = x_node == "root" ? @dialog . dialog_type : x_node . split ( '_' ) [ 1 ]
142+ @hide_bottom_bar = true
165143 @in_a_form = true
166144 replace_right_cell ( :nodetype => "odg-" )
167145 end
168146
169147 def old_dialogs_copy
170148 assert_privileges ( "old_dialogs_copy" )
171- @_params [ :typ ] = "copy"
172- old_dialogs_edit
149+ @hide_bottom_bar = true
150+ dialog = MiqDialog . find ( params [ :id ] )
151+ @dialog = MiqDialog . new
152+ @dialog . name = "Copy of " + dialog . name
153+ @dialog . description = dialog . description
154+ @dialog . dialog_type = dialog . dialog_type
155+ @dialog . content = YAML . dump ( dialog . content )
156+ session [ :changed ] = true
157+ if @dialog . default == true
158+ add_flash ( _ ( "Default Dialog \" %{name}\" can not be edited" ) % { :name => @dialog . name } , :error )
159+ get_node_info
160+ replace_right_cell ( :nodetype => x_node )
161+ return
162+ end
163+ @in_a_form = true
164+ replace_right_cell ( :nodetype => "odg-#{ params [ :id ] } " )
173165 end
174166
175167 def old_dialogs_edit
@@ -180,39 +172,112 @@ def old_dialogs_edit
180172 obj = find_checked_items
181173 @_params [ :id ] = obj [ 0 ]
182174 end
183-
184- if params [ :typ ] == "copy"
185- dialog = MiqDialog . find ( params [ :id ] )
186- @dialog = MiqDialog . new
187- @dialog . name = "Copy of " + dialog . name
188- @dialog . description = dialog . description
189- @dialog . dialog_type = dialog . dialog_type
190- @dialog . content = dialog . content
191- session [ :changed ] = true
192- else
193- @dialog = @record = identify_record ( params [ :id ] , MiqDialog ) if params [ :id ]
194- session [ :changed ] = false
195- end
175+ @hide_bottom_bar = true
176+ @dialog = @record = identify_record ( params [ :id ] , MiqDialog ) if params [ :id ]
177+ session [ :changed ] = false
196178 if @dialog . default == true
197179 add_flash ( _ ( "Default Dialog \" %{name}\" can not be edited" ) % { :name => @dialog . name } , :error )
198180 get_node_info
199181 replace_right_cell ( :nodetype => x_node )
200182 return
201183 end
202- old_dialogs_set_form_vars
203184 @in_a_form = true
204185 replace_right_cell ( :nodetype => "odg-#{ params [ :id ] } " )
205186 end
206187
188+ def old_dialogs_edit_get
189+ assert_privileges ( "old_dialogs_edit" )
190+ unless params [ :id ]
191+ obj = find_checked_items
192+ @_params [ :id ] = obj [ 0 ]
193+ end
194+ @hide_bottom_bar = true
195+
196+ dialog = MiqDialog . find ( params [ :id ] )
197+ if dialog . default == true
198+ add_flash ( _ ( "Default Dialog \" %{name}\" can not be edited" ) % { :name => dialog . name } , :error )
199+ end
200+ render :json => {
201+ :name => dialog . name ,
202+ :description => dialog . description ,
203+ :content => YAML . dump ( dialog . content ) ,
204+ :dialog_type => dialog . dialog_type
205+ }
206+ end
207+
207208 def old_dialogs_update
208209 assert_privileges ( params [ :id ] . present? ? 'old_dialogs_edit' : 'old_dialogs_new' )
209210 id = params [ :id ] ? params [ :id ] : "new"
210211 return unless load_edit ( "dialog_edit__#{ id } " , "replace_cell__explorer" )
211212 old_dialogs_update_create
212213 end
213214
215+ def provision_dialogs_update
216+ assert_privileges ( params [ :id ] . present? ? 'old_dialogs_edit' : 'old_dialogs_new' )
217+ @hide_bottom_bar = true
218+ id = params [ :id ] ? params [ :id ] : "new"
219+ provision_dialogs_update_create
220+ end
221+
214222 private
215223
224+ def provision_dialogs_update_create
225+ case params [ :button ]
226+ when "add" , "save"
227+ dialog = params [ :id ] . blank? ? MiqDialog . new : MiqDialog . find ( params [ :id ] ) # Get new or existing record
228+ if params [ :name ] . blank?
229+ add_flash ( _ ( "Name is required" ) , :error )
230+ end
231+ if params [ :dialog_type ] . blank?
232+ add_flash ( _ ( "Dialog Type must be selected" ) , :error )
233+ end
234+ unless @flash_array
235+ begin
236+ YAML . parse ( params [ :content_data ] )
237+ rescue YAML ::SyntaxError => ex
238+ add_flash ( _ ( "Syntax error in YAML file: %{error_message}" ) % { :error_message => ex . message } , :error )
239+ end
240+ end
241+ if @flash_array
242+ javascript_flash
243+ return
244+ end
245+ dialog . name = params [ :name ]
246+ dialog . description = params [ :description ]
247+ dialog . dialog_type = params [ :dialog_type ]
248+ dialog . content = YAML . safe_load ( params [ :content_data ] )
249+ begin
250+ dialog . save!
251+ rescue StandardError
252+ dialog . errors . each do |error |
253+ add_flash ( "#{ error . attribute . to_s . capitalize } #{ error . message } " , :error )
254+ end
255+ @changed = true
256+ javascript_flash
257+ else
258+ edit_hash = { }
259+ edit_hash [ :new ] = { :name => params [ :name ] , :description => params [ :description ] , :dialog_type => params [ :dialog_type ] , :content => params [ :content_data ] }
260+
261+ if params [ :old_data ]
262+ edit_hash [ :current ] = { :name => params [ :old_data ] [ :name ] , :description => params [ :old_data ] [ :description ] , :dialog_type => params [ :old_data ] [ :dialog_type ] , :content => params [ :old_data ] [ :content ] }
263+ else
264+ edit_hash [ :current ] = { :name => nil , :description => nil , :dialog_type => nil , :content => nil }
265+ end
266+ AuditEvent . success ( build_saved_audit ( dialog , edit_hash ) )
267+ @edit = session [ :edit ] = nil # clean out the saved info
268+ # if editing from list view then change active_node to be same as updated image_type folder node
269+ if x_node . split ( '-' ) [ 0 ] == "xx"
270+ self . x_node = "xx-MiqDialog_#{ dialog . dialog_type } "
271+ elsif params [ :button ] == "add"
272+ d = MiqDialog . find_by ( :name => dialog . name , :dialog_type => dialog . dialog_type )
273+ self . x_node = "odg-#{ d . id } "
274+ end
275+ get_node_info
276+ replace_right_cell ( :nodetype => x_node , :replace_trees => [ :old_dialogs ] )
277+ end
278+ end
279+ end
280+
216281 def old_dialogs_update_create
217282 old_dialogs_get_form_vars
218283 case params [ :button ]
0 commit comments