{"size": 2323, "ext": "js", "max_stars_repo_path": "www/html/js/components/modalEditActuator.js", "max_stars_repo_name": "RGort10/DomoticaTi", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "www/html/js/components/modalEditActuator.js", "max_issues_repo_name": "RGort10/DomoticaTi", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "www/html/js/components/modalEditActuator.js", "max_forks_repo_name": "RGort10/DomoticaTi", "max_forks_repo_forks_event_min_datetime": "2020-02-10T11:55:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-10T11:55:59.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 36.296875, "max_line_length": 78, "alphanum_fraction": 0.662505381}


function saveEditActuator() {
	const actuatorBody = {
		actuatorid: 	$('#modalEditActuator-actuatorid').html(),
		actuatorname: 	$('#modalEditActuator-actuatorname').val(),
		type: 					$('#modalEditActuator-type').val(),
		arduinoid: 			$('#modalEditActuator-arduinoid').val(),
		arduinocomponentid: $('#modalEditActuator-arduinocomponentid').val()
	}

  $.ajax({
    method: 'PUT',
    url: '/cgi-bin/api/actuator.cgi?' + actuatorBody.actuatorid,
    data: JSON.stringify(actuatorBody)
  })
    .done(() => {
      emptyEditActuatorForm()
      $('#modalEditActuator').modal('toggle')
      getModalActuator(actuatorBody.actuatorid)
      makeActuatorTable()
    })
    .fail((err) => {
      if(err.status === 400) {
        $.each(err.responseJSON, (key, value) => {
          if(value === false) {
            $(`#modalEditActuator-${key}`).addClass('is-invalid')
            $(`#modalEditActuator-${key}`).removeClass('is-valid')
          } else {
            $(`#modalEditActuator-${key}`).addClass('is-valid')
            $(`#modalEditActuator-${key}`).removeClass('is-invalid')
          }
        })
      }
    })
}

function editActuator(id) {
  getActuator(id)
    .then(data => {
      const actuator = data.data[0]
			$('#modalEditActuator').modal('toggle')
			$(`#modalEditActuator-actuatorid`).html(actuator.actuatorid)
			$(`#modalEditActuator-actuatorname`).val(actuator.actuatorname)
			$(`#modalEditActuator-type`).val(actuator.type)
			$(`#modalEditActuator-arduinoid`).val(actuator.arduinoid)
			$(`#modalEditActuator-arduinocomponentid`).val(actuator.arduinocomponentid)
		})
}

function emptyEditActuatorForm() {
	$(`#modalEditActuator-actuatorname`).removeClass('is-valid')
	$(`#modalEditActuator-type`).removeClass('is-valid')
	$(`#modalEditActuator-arduinoid`).removeClass('is-valid')
	$(`#modalEditActuator-arduinocomponentid`).removeClass('is-valid')
	$(`#modalEditActuator-actuatorname`).removeClass('is-invalid')
	$(`#modalEditActuator-type`).removeClass('is-invalid')
	$(`#modalEditActuator-arduinoid`).removeClass('is-invalid')
	$(`#modalEditActuator-arduinocomponentid`).removeClass('is-invalid')
	$(`#modalEditActuator-actuatorname`).val(null)
	$(`#modalEditActuator-type`).val(null)
	$(`#modalEditActuator-arduinoid`).val(null)
	$(`#modalEditActuator-arduinocomponentid`).val(null)
}