Method: Anoubis::Data::Actions#edit

Defined in:
app/controllers/anoubis/data/actions.rb

#editObject

Edit action of Anoubis::DataController. Procedure outputs values for edit form. Authorization bearer is required.

API request:

GET /api/<version>/<controller>/<id>/edit

Request Header:

{
  "Authorization": "Bearer <Session token>"
}

Parameters:

  • locale (String) — the output language locale (optional value)

  • tab (String) — the tab, is used for action (optional value, default: first defined tab)

Resulting output title is took from translation file <lang>.yml at path:

<lang>:
  <controller name divided by level>:
    edit:
      form:
        title: "Edit soldier %{title}"

If this path isn’t defined in translation file, then value is took from path:

<lang>:
  anubis:
    form:
      titles:
        edit: "Edit element: %{title}"

Request example:

curl --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/<controller>/<id>/edit?tab=<tab>

Results:

Resulting data returns in JSON format.

Examples:

Success: HTTP response code 200

{
  "result": 0,
  "message": "Successful",
  "timestamp": 1563271417,
  "tab": "inner",
  "title": "Edit soldier Sailor Mars",
  "values": {
      "id": 3,
      "title": "Sailor Mars",
      "name": "Rey Hino",
      "state_view": "Inner Senshi",
      "state": "inner"
  },
  "options": {
      "state": {
          "inner": "Inner Senshi",
          "outer": "Outer Senshi",
          "star": "Sailor Star"
      }
  }
}

Error (incorrect request id): HTTP response code 200

{
  "result": -2,
  "message": "Incorrect request parameters",
  "timestamp": 1563271417,
  "tab": "inner"
}

Error (session expired): HTTP response code 422

{
  "result": -1,
  "message": "Session expired",
  "timestamp": 1563271417,
  "tab": "inner"
}


615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'app/controllers/anoubis/data/actions.rb', line 615

def edit
  self.output = Anoubis::Output::Edit.new
  self.set_parent_model 'edit'
  self.output.tab = self.etc.tab.tab
  if self.table_actions.include?('edit')
    if params.key?(:value) && params.key?(:field)
      self.load_data_by_title params[:field], params[:value]
      params[:id] = self.etc.data.data.id if self.etc.data.data
    end
    if params.key? :id
      self.load_data_by_id params[:id] if !self.etc.data.data
      if self.etc.data.data
        self.output.values = self.get_data_row self.etc.data.data
        if params.key? :time
          self.output.options = self.get_data_options params[:time]
        else
          self.output.options = self.get_data_options 0
        end
        self.output.fields = self.get_fields_properties if self.etc.time == 0
      else
        self.output.result = -2
      end
    else
      self.output.result = -2
    end
  else
    self.output.result = -1
  end
  if self.output.result == 0
    self.output.title = I18n.t(format('%s.edit.form.title', params[:controller].sub('/', '.')), title: self.output.values[:sys_title],
                          default: I18n.t('anoubis.form.titles.edit', title: self.output.values[:sys_title]))
  end
  self.before_output

  render json: around_output(output.to_h)
end