Issue #212 Setting Defaults for Pushover

- ConfigController.php - Preparation defaults to settings
- Modifying Templates config.tpl.html
 - Added language texts EN + CZ
pull/304/head
Pavel Dvořák 2016-05-21 23:45:38 +02:00
parent dae50f6e84
commit 57fb82f469
4 changed files with 146 additions and 2 deletions

View File

@ -221,6 +221,19 @@ $sm_lang = array(
'pushover_clone_app' => 'Klikněte pro vytvoření Pushover aplikace',
'pushover_api_token' => 'Pushover App API Token',
'pushover_api_token_description' => 'Pře použitím Pushoveru se musíte <a href="%1$s" target="_blank">registrovat</a> a získat API Token.',
'pushover_default_priority_online' => 'Výchozí priorita pro Online',
'pushover_default_priority_offline' => 'Výchozí priorita pro Offline',
'pushover_default_sound' => 'Výchozí zvuk',
'pushover_default_sound_device' => 'Výchozí zvuk zařízení',
'pushover_default_retry' => 'Výchozí opakování',
'pushover_default_retry_description' => 'Toto nastavení se uplatní v oznámení pouze pokud je zvolena priorita Nouzová priorita (2)',
'pushover_default_expire' => 'Výchozí expirace',
'pushover_default_expire_description' => 'Toto nastavení se uplatní v oznámení pouze pokud je zvolena priorita Nouzová priorita (2)',
'pushover_priority_-2' => 'Nejnižší priorita (-2)',
'pushover_priority_-1' => 'Nízká priorita (-1)',
'pushover_priority_0' => 'Normální priorita (0)',
'pushover_priority_1' => 'Vysoká priorita (1)',
'pushover_priority_2' => 'Nouzová priorita (2)',
'alert_type' => 'Zvolte kdy si přejete být upozorněni.',
'alert_type_description' => '<b>Změna stavu:</b> '.
'Obdržíte upozornění při změně stavu, tedy:online -> offline nebo offline -> online.<br/>'.

View File

@ -220,6 +220,19 @@ $sm_lang = array(
'pushover_clone_app' => 'Click here to create your Pushover app',
'pushover_api_token' => 'Pushover App API Token',
'pushover_api_token_description' => 'Before you can use Pushover, you need to <a href="%1$s" target="_blank">register an App</a> at their website and enter the App API Token here.',
'pushover_default_priority_online' => 'Default Priority for Online',
'pushover_default_priority_offline' => 'Default Priority for Offline',
'pushover_default_sound' => 'Default Sound',
'pushover_default_sound_device' => 'Device default sound',
'pushover_default_retry' => 'Default Retry',
'pushover_default_retry_description' => 'This setting will apply to notification only if the selected priority Emergency Priority (2).',
'pushover_default_expire' => 'Default Expire',
'pushover_default_expire_description' => 'This setting will apply to notification only if the selected priority Emergency Priority (2).',
'pushover_priority_-2' => 'Lowest Priority (-2)',
'pushover_priority_-1' => 'Low Priority (-1)',
'pushover_priority_0' => 'Normal Priority (0)',
'pushover_priority_1' => 'High Priority (1)',
'pushover_priority_2' => 'Emergency Priority (2)',
'alert_type' => 'Select when you\'d like to be notified.',
'alert_type_description' => '<b>Status change:</b> '.
'You will receive a notifcation when a server has a change in status. So from online -> offline or offline -> online.<br/>'.

View File

@ -62,6 +62,8 @@ class ConfigController extends AbstractController {
'sms_gateway_password',
'sms_from',
'pushover_api_token',
'pushover_default_retry',
'pushover_default_expire',
);
private $default_tab = 'general';
@ -131,6 +133,66 @@ class ConfigController extends AbstractController {
$tpl_data[$this->default_tab . '_active'] = 'active';
// pushover default settings
$pushoverDefaultPriority = [
'-2' => [
'value' => '-2',
'label' => psm_get_lang('config', 'pushover_priority_-2'),
'selected' => '',
],
'-1' => [
'value' => '-1',
'label' => psm_get_lang('config', 'pushover_priority_-1'),
'selected' => '',
],
'0' => [
'value' => '0',
'label' => psm_get_lang('config', 'pushover_priority_0'),
'selected' => '',
],
'1' => [
'value' => '1',
'label' => psm_get_lang('config', 'pushover_priority_1'),
'selected' => '',
],
'2' => [
'value' => '2',
'label' => psm_get_lang('config', 'pushover_priority_2'),
'selected' => '',
],
];
$tpl_data['pushover_default_priority_online'] = $pushoverDefaultPriority;
if (
isset($config['pushover_default_priority_online']) &&
isset($tpl_data['pushover_default_priority_online'][$config['pushover_default_priority_online']])
) {
$tpl_data['pushover_default_priority_online'][$config['pushover_default_priority_online']]['selected'] = ' selected="selected"';
}
$tpl_data['pushover_default_priority_offline'] = $pushoverDefaultPriority;
if (
isset($config['pushover_default_priority_offline']) &&
isset($tpl_data['pushover_default_priority_offline'][$config['pushover_default_priority_offline']])
) {
$tpl_data['pushover_default_priority_offline'][$config['pushover_default_priority_offline']]['selected'] = ' selected="selected"';
}
$pushover = psm_build_pushover();
$pushoverSound = $pushover->getSounds();
if ($pushoverSound !== false) {
foreach ($pushoverSound as $key => $name) {
$tpl_data['pushover_default_sound'][$key] = [
'value' => $key,
'label' => $name,
'selected' => (isset($config['pushover_default_sound']) && $config['pushover_default_sound'] == $key) ? ' selected="selected"' : '',
];
}
} else {
$tpl_data['pushover_default_sound'] = [];
}
$testmodals = array('email', 'sms', 'pushover');
foreach($testmodals as $modal_id) {
$modal = new \psm\Util\Module\Modal($this->twig, 'test' . ucfirst($modal_id), \psm\Util\Module\Modal::MODAL_TYPE_OKCANCEL);
@ -161,6 +223,11 @@ class ConfigController extends AbstractController {
'auto_refresh_servers' => intval(psm_POST('auto_refresh_servers', 0)),
'log_retention_period' => intval(psm_POST('log_retention_period', 365)),
'password_encrypt_key' => psm_POST('password_encrypt_key', sha1(microtime())),
'pushover_default_priority_online' => psm_POST('pushover_default_priority_online', '0'),
'pushover_default_priority_offline' => psm_POST('pushover_default_priority_offline', '2'),
'pushover_default_sound' => psm_POST('pushover_default_sound', 'pushover'),
'pushover_default_retry' => psm_POST('pushover_default_retry', 300),
'pushover_default_expire' => psm_POST('pushover_default_expire', 3600),
);
foreach($this->checkboxes as $input_key) {
$clean[$input_key] = (isset($_POST[$input_key])) ? '1': '0';
@ -328,7 +395,15 @@ class ConfigController extends AbstractController {
'label_pushover_description' => psm_get_lang('config', 'pushover_description'),
'label_pushover_status' => psm_get_lang('config', 'pushover_status'),
'label_pushover_clone_app' => psm_get_lang('config', 'pushover_clone_app'),
'pushover_clone_url' => PSM_PUSHOVER_CLONE_URL,
'label_pushover_default_priority_online' => psm_get_lang('config', 'pushover_default_priority_online'),
'label_pushover_default_priority_offline' => psm_get_lang('config', 'pushover_default_priority_offline'),
'label_pushover_default_sound' => psm_get_lang('config', 'pushover_default_sound'),
'label_pushover_default_sound_device' => psm_get_lang('config', 'pushover_default_sound_device'),
'label_pushover_default_retry' => psm_get_lang('config', 'pushover_default_retry'),
'label_pushover_default_retry_description' => psm_get_lang('config', 'pushover_default_retry_description'),
'label_pushover_default_expire' => psm_get_lang('config', 'pushover_default_expire'),
'label_pushover_default_expire_description' => psm_get_lang('config', 'pushover_default_expire_description'),
'label_pushover_clone_url' => PSM_PUSHOVER_CLONE_URL,
'label_pushover_api_token' => psm_get_lang('config', 'pushover_api_token'),
'label_pushover_api_token_description' => sprintf(
psm_get_lang('config', 'pushover_api_token_description'),

View File

@ -221,9 +221,52 @@
<label class="control-label" for="pushover_api_token">{{ label_pushover_api_token }}</label>
<div class="controls">
<p><button class="btn btn-primary" onclick="window.open('{{ pushover_clone_url }}');return false;">{{ label_pushover_clone_app }}</button></p>
<input type="text" id="pushover_api_token" name="pushover_api_token" value="{{ pushover_api_token }}" maxlength="255" />
<input class="input-xxlarge" type="text" id="pushover_api_token" name="pushover_api_token" value="{{ pushover_api_token }}" maxlength="255" />
<p class="help-block">{{ label_pushover_api_token_description|raw }}</p>
</div>
</div>
<div class="control-group {{ control_class_pushover }}">
<label class="control-label" for="pushover_default_priority_online">{{ label_pushover_default_priority_offline }}</label>
<div class="controls">
<select id="pushover_default_priority_online" name="pushover_default_priority_online">
{% for value in pushover_default_priority_online %}
<option value="{{ value.value }}"{{ value.selected }}>{{ value.label }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="control-group {{ control_class_pushover }}">
<label class="control-label" for="pushover_default_priority_offline">{{ label_pushover_default_priority_offline }}</label>
<div class="controls">
<select id="pushover_default_priority_offline" name="pushover_default_priority_offline">
{% for value in pushover_default_priority_offline %}
<option value="{{ value.value }}"{{ value.selected }}>{{ value.label }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="control-group {{ control_class_pushover }}">
<label class="control-label" for="pushover_default_sound">{{ label_pushover_default_sound }}</label>
<div class="controls">
<select class="span3" id="pushover_default_sound" name="pushover_default_sound">
<option value="">({{ label_pushover_default_sound_device }})</option>
{% for value in pushover_default_sound %}
<option value="{{ value.value }}"{{ value.selected }}>{{ value.label }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="control-group {{ control_class_pushover }}">
<label class="control-label" for="pushover_default_retry">{{ label_pushover_default_retry }}</label>
<div class="controls">
<input class="input-mini" type="text" id="pushover_default_retry" name="pushover_default_retry" value="{{ pushover_default_retry }}" placeholder="300" maxlength="10" data-toggle="tooltip" title="{{ label_pushover_default_retry_description }}" /> {{ label_seconds }}
</div>
</div>
<div class="control-group {{ control_class_pushover }}">
<label class="control-label" for="pushover_default_expire">{{ label_pushover_default_expire }}</label>
<div class="controls">
<input class="input-mini" type="text" id="pushover_default_expire" name="pushover_default_expire" value="{{ pushover_default_expire }}" placeholder="3600" maxlength="10" data-toggle="tooltip" title="{{ label_pushover_default_expire_description }}" /> {{ label_seconds }}
</div>
</div>
<div class="control-group">
<div class="controls">