def create
      @element = Humpyard::config.element_types[params[:type]].new params[:element]
            
      unless can? :create, @element.element
        render :json => {
          :status => :failed
        }, :status => 403
        return
      end      
            
      if @element.save
        @prev = Humpyard::Element.find_by_id(params[:prev_id])
        @next = Humpyard::Element.find_by_id(params[:next_id])
        
        do_move(@element, @prev, @next)
      
        insert_options = {
          :element => "hy-id-#{@element.element.id}",
          :url => humpyard_element_path(@element.element),
          :parent => @element.container ? "hy-id-#{@element.container.id}" : "hy-content-#{@element.page_yield_name}"
        }
        
        insert_options[:before] = "hy-id-#{@next.id}" if @next
        insert_options[:after] = "hy-id-#{@prev.id}" if not @next and @prev
      
        render :json => {
          :status => :ok,
          :dialog => :close,
          :insert => [insert_options]
        }
      else
        render :json => {
          :status => :failed, 
          :errors => @element.errors
        }
      end
    end
def create
      @element = Humpyard::config.element_types[params[:type]].new params[:element]
            
      unless can? :create, @element.element
        render :json => {
          :status => :failed
        }, :status => 403
        return
      end      
            
      if @element.save
        @prev = Humpyard::Element.find_by_id(params[:prev_id])
        @next = Humpyard::Element.find_by_id(params[:next_id])
        
        do_move(@element, @prev, @next)
      
        insert_options = {
          :element => "hy-id-#{@element.element.id}",
          :url => humpyard_element_path(@element.element),
          :parent => @element.container ? "hy-id-#{@element.container.id}" : "hy-content-#{@element.page_yield_name}"
        }
        
        insert_options[:before] = "hy-id-#{@next.id}" if @next
        insert_options[:after] = "hy-id-#{@prev.id}" if not @next and @prev
      
        render :json => {
          :status => :ok,
          :dialog => :close,
          :insert => [insert_options]
        }
      else
        render :json => {
          :status => :failed, 
          :errors => @element.errors
        }
      end
    end
Create a new element