Skip to content

Commit

Permalink
saving/loading alert properties and mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hinanaya committed Jun 4, 2024
1 parent 466a5c5 commit e8c4369
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions controllers/alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public function get_last_player()
* @param duration
* @param start
* @param stop
* @param mode
* @param properties Settings if mode is set to voicetrack.
*
* @route POST /v2/alerts
* @route PUT /v2/alerts/(:id:)
Expand All @@ -161,6 +163,9 @@ public function save()
$data['start'] = trim($this->data('start'));
$data['stop'] = trim($this->data('stop'));

$data['mode'] = trim($this->data('mode'));
$data['properties'] = json_encode($this->data('properties'));

$data['user_id'] = $this->user->param('id');

$validation = $this->models->alerts('validate', ['data' => $data, 'id' => $id]);
Expand Down
16 changes: 16 additions & 0 deletions js/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ OB.Alert.saveAlert = function()
fields.id = $('#alert_id').val();
fields.item_id = document.querySelector('#alert_item_id').value[0];

fields.mode = document.querySelector('#alert_mode').value;
fields.properties = {
"voicetrack_volume": document.querySelector('#alert_voicetrack_volume').value,
"voicetrack_offset": document.querySelector('#alert_voicetrack_offset').value,
"voicetrack_fadeout_before": document.querySelector('#alert_voicetrack_fadeout_before').value,
"voicetrack_fadein_after": document.querySelector('#alert_voicetrack_fadein_after').value
};

OB.API.post('alerts','save',fields,function(data)
{

Expand Down Expand Up @@ -246,6 +254,14 @@ OB.Alert.editAlert = function(id)

$('#alert_start_datetime').val(new Date(parseInt(emerg.start)*1000));
$('#alert_stop_datetime').val(new Date(parseInt(emerg.stop)*1000));

document.querySelector('#alert_mode').value = emerg.mode;
if (emerg.properties) {
document.querySelector('#alert_voicetrack_volume').value = emerg.properties.voicetrack_volume;
document.querySelector('#alert_voicetrack_offset').value = emerg.properties.voicetrack_offset;
document.querySelector('#alert_voicetrack_fadeout_before').value = emerg.properties.voicetrack_fadeout_before;
document.querySelector('#alert_voicetrack_fadein_after').value = emerg.properties.voicetrack_fadein_after;
}
}

else OB.UI.alert(data.msg);
Expand Down
11 changes: 10 additions & 1 deletion models/alerts_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function get_init($args = [])
$this->db->what('alerts.start', 'start');
$this->db->what('alerts.stop', 'stop');
$this->db->what('alerts.player_id', 'player_id');
$this->db->what('alerts.mode', 'mode');
$this->db->what('alerts.properties', 'properties');

$this->db->leftjoin('media', 'alerts.item_id', 'media.id');
}
Expand Down Expand Up @@ -80,6 +82,8 @@ public function get_one($args = [])
}
unset($alert['item_duration']);

$alert['properties'] = json_decode($alert['properties'], true);

return $alert;
}

Expand Down Expand Up @@ -132,7 +136,7 @@ public function validate($args = [])
}

// required fields?
if (empty($name) || empty($player_id) || empty($item_id) || empty($frequency) || empty($start) || empty($stop)) {
if (empty($name) || empty($player_id) || empty($item_id) || empty($frequency) || empty($start) || empty($stop) || empty($mode)) {
return array(false,'Required Field Missing');
}

Expand Down Expand Up @@ -194,6 +198,11 @@ public function validate($args = [])
return array(false,'The stop date/time must occur after the start date/time.');
}

//T The mode must be either an interrupt or a voicetrack.
if ($mode !== 'interrupt' && $mode !== 'voicetrack') {
return array(false, 'The mode must be either an interrupt or a voicetrack.');
}

return array(true,'');
}

Expand Down

0 comments on commit e8c4369

Please sign in to comment.