Popup to add groups and sources to global notification configuration
Former-commit-id: 481812290ea1d1446aa7378ab6a935139483c8a0
This commit is contained in:
parent
0b72571c7c
commit
8811257762
|
@ -18,6 +18,8 @@
|
|||
// Load global vars
|
||||
global $config;
|
||||
|
||||
require_once ($config['homedir'] . '/include/functions_notifications.php');
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
|
||||
|
@ -27,6 +29,22 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user
|
|||
}
|
||||
|
||||
// Actions
|
||||
// AJAX
|
||||
if (get_parameter('get_selection_two_ways_form', 0)) {
|
||||
$source_id = get_parameter('source_id', '');
|
||||
$users = get_parameter('users', '');
|
||||
$id = get_notification_source_id($source_id);
|
||||
$info_selec = $users === "users"
|
||||
? notifications_get_user_source_not_configured($id)
|
||||
: notifications_get_group_source_not_configured($id);
|
||||
|
||||
echo notifications_print_two_ways_select(
|
||||
$info_selec,
|
||||
$users,
|
||||
$source_id
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (get_parameter('update_config', 0)) {
|
||||
$res_global = array_reduce(notifications_get_all_sources(), function($carry, $source){
|
||||
$id = notifications_desc_to_id($source['description']);
|
||||
|
@ -94,4 +112,56 @@ function notifications_disable_source(event) {
|
|||
document.getElementById('multi-' + select + '-' + id).disabled = is_checked;
|
||||
});
|
||||
}
|
||||
|
||||
// Open a dialog with selector of source elements.
|
||||
function add_source_dialog(users, source_id) {
|
||||
// Display the dialog
|
||||
var dialog_id = 'global_config_notifications_dialog_add-' + users + '-' + source_id;
|
||||
var not_dialog = document.createElement('div');
|
||||
not_dialog.setAttribute('class', 'global_config_notifications_dialog_add');
|
||||
not_dialog.setAttribute('id', dialog_id);
|
||||
document.body.appendChild(not_dialog);
|
||||
$("#" + dialog_id).dialog({
|
||||
resizable: false,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
dialogClass: "global_config_notifications_dialog_add_wrapper",
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
},
|
||||
closeOnEscape: true,
|
||||
modal: true
|
||||
});
|
||||
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "godmode/setup/setup_notifications",
|
||||
"get_selection_two_ways_form" : 1,
|
||||
"users" : users,
|
||||
"source_id" : source_id
|
||||
},
|
||||
function (data, status) {
|
||||
not_dialog.innerHTML = data
|
||||
},
|
||||
"html"
|
||||
);
|
||||
}
|
||||
|
||||
// Move from selected and not selected source elements.
|
||||
function notifications_modify_two_ways_element (id, source_id, operation) {
|
||||
var index_sufix = 'multi-' + id + '-' + source_id;
|
||||
var start_id = operation === 'add' ? 'all-' : 'selected-';
|
||||
var end_id = operation !== 'add' ? 'all-' : 'selected-';
|
||||
var select = document.getElementById(
|
||||
start_id + index_sufix
|
||||
);
|
||||
var select_end = document.getElementById(
|
||||
end_id + index_sufix
|
||||
);
|
||||
for (var i = 0; i < select.options.length; i++) {
|
||||
if(select.options[i].selected ==true){
|
||||
select_end.appendChild(select.options[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -195,16 +195,37 @@ function notifications_get_user_sources_for_select($source_id) {
|
|||
* @return array with the group id in keys and group name in value
|
||||
*/
|
||||
function notifications_get_group_sources_for_select($source_id) {
|
||||
$groups = notifications_get_group_sources (
|
||||
array('id_source' => $source_id),
|
||||
array('id_group')
|
||||
);
|
||||
return index_array($groups, 'id_group', 'name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group sources
|
||||
*
|
||||
* @param array $filter Filter of sql query.
|
||||
*/
|
||||
function notifications_get_group_sources ($filter = array(), $fields = array()) {
|
||||
// Get only the tnotifications_source_group fields in addition to group name.
|
||||
if (empty($fields)) $fields[] = "tnsg.*";
|
||||
$fields = array_map(function($field) {
|
||||
if (!preg_match("/^tnsg./", $field)) $field = "tnsg.{$field}";
|
||||
return $field;
|
||||
}, $fields);
|
||||
|
||||
// Get groups.
|
||||
$groups = db_get_all_rows_filter(
|
||||
'tnotification_source_group tnsg
|
||||
LEFT JOIN tgrupo tg ON tnsg.id_group = tg.id_grupo',
|
||||
array('id_source' => $source_id),
|
||||
array ('tnsg.id_group', 'IFNULL(tg.nombre, "All") AS name')
|
||||
$filter,
|
||||
array_merge ($fields, array('IFNULL(tg.nombre, "All") AS name'))
|
||||
);
|
||||
|
||||
// If fails or no one is selected, return empty array
|
||||
if ($groups === false) return array();
|
||||
|
||||
return index_array($groups, 'id_group', 'name');
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,6 +275,36 @@ function notifications_add_group_to_source ($source_id, $groups) {
|
|||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the groups that not own to a source and, for that reason, they can be
|
||||
* added to the source.
|
||||
*
|
||||
* @param int $source_id Source id.
|
||||
* @return array Indexed by id group all selectable groups.
|
||||
*/
|
||||
function notifications_get_group_source_not_configured ($source_id) {
|
||||
$groups_selected = notifications_get_group_sources_for_select($source_id);
|
||||
$all_groups = users_get_groups_for_select(false, "AR", false, true, $groups_selected);
|
||||
return array_diff($all_groups, $groups_selected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the users that not own to a source and, for that reason, they can be
|
||||
* added to the source.
|
||||
*
|
||||
* @param int $source_id
|
||||
* @return array Indexed by id user, all selectable users.
|
||||
*/
|
||||
function notifications_get_user_source_not_configured ($source_id) {
|
||||
$users_selected = array_keys(notifications_get_user_sources_for_select($source_id));
|
||||
$users = get_users(
|
||||
'id_user',
|
||||
array('!id_user' => $users_selected),
|
||||
array('id_user')
|
||||
);
|
||||
return index_array($users, 'id_user', 'id_user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the notification ball to see unread messages
|
||||
*
|
||||
|
@ -365,9 +416,29 @@ function notifications_print_source_select_box($info_selec, $id, $source_id, $di
|
|||
$html_select .= html_print_select(empty($info_selec) ? true : $info_selec, "multi-{$id}-{$source_id}[]", 0, false, '', '', true, true, true,'', $disabled);
|
||||
$html_select .= " </div>";
|
||||
$html_select .= " <div class='global-notifications-icons'>";
|
||||
$html_select .= html_print_image('images/input_add.png', true, array('title' => $add_title));
|
||||
$html_select .= html_print_image('images/input_add.png', true, array('title' => $add_title, 'onclick' => "add_source_dialog('$id', '$source_id')"));
|
||||
$html_select .= html_print_image('images/input_delete.png', true, array('title' => $delete_title));
|
||||
$html_select .= " </div>";
|
||||
$html_select .= "</div>";
|
||||
return $html_select;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the select with right and left arrows to select new sources
|
||||
* (groups or users).
|
||||
*
|
||||
* @param array $info_selec Array with source info.
|
||||
* @param string $users users|groups.
|
||||
* @param source $source_id Source id.
|
||||
* @return string HTML with the select code.
|
||||
*/
|
||||
function notifications_print_two_ways_select($info_selec, $users, $source_id) {
|
||||
$html_select .= html_print_select(empty($info_selec) ? true : $info_selec, "all-multi-{$users}-{$source_id}[]", 0, false, '', '', true, true, true,'');
|
||||
$html_select .= "<div class='global_config_notifications_two_ways_form_arrows'>";
|
||||
$html_select .= html_print_image('images/darrowright.png', true, array('title' => $add_title, 'onclick' => "notifications_modify_two_ways_element('$users', '$source_id', 'add')"));
|
||||
$html_select .= html_print_image('images/darrowleft.png', true, array('title' => $add_title, 'onclick' => "notifications_modify_two_ways_element('$users', '$source_id', 'remove')"));
|
||||
$html_select .= "</div>";
|
||||
$html_select .= html_print_select(true, "selected-multi-{$users}-{$source_id}[]", 0, false, '', '', true, true, true, '');
|
||||
|
||||
return $html_select;
|
||||
}
|
||||
|
|
|
@ -4953,7 +4953,8 @@ div#dialog_messages table th:last-child {
|
|||
margin: 0;
|
||||
}
|
||||
|
||||
.global-config-notification-single-selector {
|
||||
.global-config-notification-single-selector,
|
||||
.global_config_notifications_dialog_add select {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
padding: 0 10px;
|
||||
|
@ -4970,6 +4971,23 @@ div#dialog_messages table th:last-child {
|
|||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.global_config_notifications_dialog_add {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin: 8px;
|
||||
}
|
||||
|
||||
.global_config_notifications_two_ways_form_arrows {
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
justify-content: center;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.global_config_notifications_two_ways_form_arrows img {
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
/* --- JQUERY-UI --- */
|
||||
.ui-button-text-only .ui-button-text {
|
||||
font-family: "nunito", sans-serif;
|
||||
|
|
Loading…
Reference in New Issue