end
def new
- @panel_picture = PanelPicture.new params[:panel_picture]
+ @picture = Picture.show params[:picture_id], @author
+ raise ActiveRecord::Forbidden unless @picture.enable?
+ @panel = Panel.edit(@author.working_panel, @author)
+
+ @panel_picture = PanelPicture.new :panel_id => @panel.id, :picture_id => @picture.id
@panel_picture.supply_default
- @panel = @panel_picture.panel
respond_to do |format|
format.html
end
def create
- @panel_picture = PanelPicture.new params[:panel_picture]
- @panel_picture.supply_default
- @panel_picture.overwrite
- @panel = Panel.edit(@panel_picture.panel.id, @author)
+ @panel = Panel.edit(@author.working_panel, @author)
+
+ @panel_picture = PanelPicture.new
+ @panel_picture.attributes = params[:panel_picture]
+ @panel_picture.overwrite @panel.id
+
+ @picture = Picture.show @panel_picture.picture_id, @author
+ raise ActiveRecord::Forbidden unless @picture.enable?
respond_to do |format|
if @panel_picture.valid?
format.html { redirect_to @panel }
format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
else
- flash[:notice] = I18n.t('flash.notice.not_created', :model => Panel.model_name.human)
- format.html { render action: "panels/new" }
+ flash[:notice] = I18n.t('flash.notice.not_created', :model => PanelPicture.model_name.human)
+ format.html { render action: "new" }
format.json { render json: @panel.errors, status: :unprocessable_entity }
end
else
def update
@panel_picture = PanelPicture.show(params[:id], @author)
@panel_picture.attributes = params[:panel_picture]
- @panel_picture.overwrite
@panel = Panel.edit(@panel_picture.panel.id, @author)
+ @panel_picture.overwrite @panel.id
+
+ @picture = Picture.show @panel_picture.picture_id, @author
+ raise ActiveRecord::Forbidden unless @picture.enable?
respond_to do |format|
if @panel_picture.store @author