foreman/app/controllers/puppetclasses_controller.rb @ d97375e0
c6eee281 | Ohad Levy | class PuppetclassesController < ApplicationController
|
|
af6e2624 | Ohad Levy | def index
|
|
3aa6ea3f | Ohad Levy | respond_to do |format|
|
|
format.html do
|
|||
@search = Puppetclass.search params[:search]
|
|||
@puppetclasses = @search.paginate :page => params[:page], :include => [:environments, :hostgroups, :operatingsystems]
|
|||
end
|
|||
format.json { render :json => Puppetclass.classes2hash(Puppetclass.all(:select => "name, id")) }
|
|||
end
|
|||
6e50fa1d | Ohad Levy | end
|
|
af6e2624 | Ohad Levy | ||
def new
|
|||
@puppetclass = Puppetclass.new
|
|||
end
|
|||
def create
|
|||
@puppetclass = Puppetclass.new(params[:puppetclass])
|
|||
if @puppetclass.save
|
|||
flash[:foreman_notice] = "Successfully created puppetclass."
|
|||
redirect_to puppetclasses_url
|
|||
else
|
|||
render :action => 'new'
|
|||
end
|
|||
end
|
|||
def edit
|
|||
@puppetclass = Puppetclass.find(params[:id])
|
|||
end
|
|||
def update
|
|||
@puppetclass = Puppetclass.find(params[:id])
|
|||
if @puppetclass.update_attributes(params[:puppetclass])
|
|||
flash[:foreman_notice] = "Successfully updated puppetclass."
|
|||
redirect_to puppetclasses_url
|
|||
else
|
|||
render :action => 'edit'
|
|||
end
|
|||
end
|
|||
def destroy
|
|||
@puppetclass = Puppetclass.find(params[:id])
|
|||
if @puppetclass.destroy
|
|||
flash[:foreman_notice] = "Successfully destroyed puppetclass."
|
|||
else
|
|||
be96f201 | Ohad Levy | flash[:foreman_error] = @puppetclass.errors.full_messages.join("<br/>")
|
|
af6e2624 | Ohad Levy | end
|
|
redirect_to puppetclasses_url
|
|||
end
|
|||
bd46fa41 | Ohad Levy | # AJAX methods
|
|
# adds a puppetclass to an existing host or hostgroup
|
|||
#
|
|||
# We assign the new puppetclasses (e.g. in the context of a Host or a Host Group)
|
|||
# via ajax and not java script as rendering javascript for each and every class
|
|||
# seems to be much longer than the average roundtrip time to the server
|
|||
85d3461d | Ohad Levy | # TODO: convert this to pure javascript then AJAX will not be required.
|
|
bd46fa41 | Ohad Levy | def assign
|
|
return unless request.xhr?
|
|||
klass = Puppetclass.find(params[:id])
|
|||
type = params[:type]
|
|||
render :update do |page|
|
|||
page.insert_html :after, :selected_classes, :partial => 'selectedClasses', :locals => {:klass => klass, :type => type}
|
|||
page["puppetclass_#{klass.id}"].hide
|
|||
end
|
|||
end
|
|||
6e50fa1d | Ohad Levy | end
|