- New style of information message

This commit is contained in:
PhantomVl 2019-09-25 13:27:43 +03:00 committed by Diederik de Groot
parent 49aa1f0ecc
commit 8121a69607
No known key found for this signature in database
GPG key ID: AFA728250A1BECD6
2 changed files with 62 additions and 39 deletions

View file

@ -662,7 +662,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
public function ajaxHandler() {
$request = $_REQUEST;
$msg = '';
$msg = array();
$cmd_id = $request['command'];
switch ($cmd_id) {
case 'savesettings':
@ -677,7 +677,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$res = $this->srvinterface->sccp_core_commands(array('cmd' => 'sccp_reload'));
// $res = $this->srvinterface->sccp_core_commands(array('cmd' => 'restart_phone'));
$msg = '<p>Config Saved: ' . $res['Response'] . ".</p> <p>Info :" . $res['data']."</p>";
$msg []= 'Config Saved: ' . $res['Response'];
$msg []= 'Info :' . $res['data'];
// needreload();
// !TODO!: It is necessary in the future to check, and replace all server responses on correct messages. Use _(msg)
return array('status' => true, 'message' => $msg, 'reload' => true);
@ -757,17 +758,21 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
case 'reset_token':
case 'reset_dev':
$msg = '';
$msgr = array();
$msgr[] = 'Reset command send';
if (!empty($request['name'])) {
foreach ($request['name'] as $idv) {
$msg = strpos($idv, 'SEP-');
if (!(strpos($idv, 'SEP') === false)) {
if ($cmd_id == 'reset_token') {
$res = $this->srvinterface->sccp_core_commands(array('cmd' => 'reset_token', 'name' => $idv));
$msgr[] = $msg .' '. $res['Response'] . ' ' . $res['data'];
} else {
$res = $this->srvinterface->sccp_core_commands(array('cmd' => 'reset_phone', 'name' => $idv));
$msgr[] = $msg .' '. $res['Response'] . ' ' . $res['data'];
}
// $msg = print_r($this->sccp_core_commands(array('cmd' => 'reset_phone', 'name' => $idv)), 1);
$msg = $res['Response'] . ' ' . $res['data'];
// $msg = $res['Response'] . ' ' . $res['data'];
}
if ($idv == 'all') {
$dev_list = $this->srvinterface->sccp_get_active_device();
@ -775,11 +780,13 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
if ($cmd_id == 'reset_token') {
if (($data['token'] == 'Rej') || ($data['status'] == 'Token ')) {
$res = $this->srvinterface->sccp_core_commands(array('cmd' => 'reset_token', 'name' => $key));
$msg .= 'Send Token reset to :' . $key . ' ';
// $msg .= 'Send Token reset to :' . $key . ' <br>';
$msgr[] = 'Send Token reset to :' . $key ;
}
} else {
$res = $this->srvinterface->sccp_core_commands(array('cmd' => 'reset_phone', 'name' => $key));
$msg .= $res['Response'] . ' ' . $res['data'] . ' ';
// $msg .= $res['Response'] . ' ' . $res['data'] . ' <br>';
$msgr[] = $res['Response'] . ' ' . $res['data'];
}
// $msg .= $res['Response'] . ' ' . $res['data'] . ' ';
}
@ -787,7 +794,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
}
// !TODO!: It is necessary in the future to check, and replace all server responses on correct messages. Use _(msg)
return array('status' => true, 'message' => 'Reset command send ' . $msg, 'reload' => true);
return array('status' => true, 'message' => $msgr, 'reload' => true);
// return array('status' => true, 'message' => 'Reset command send <br>' . $msg, 'reload' => true);
// }
break;
case 'update_button_label':

View file

@ -83,16 +83,12 @@ $(document).ready(function () {
success: function (data) {
if (data.status === true) {
if (data.message) {
bs_alert(data.message);
bs_alert(data.message,data.status);
} else {
bs_alert('Data Save');
bs_alert('Data Save',data.status);
}
} else {
if (Array.isArray(data.message)) {
data.message.forEach(function (entry) {
fpbxToast(entry, 'error', 'error');
});
}
bs_alert(data.message,data.status);
}
}
});
@ -123,7 +119,7 @@ $(document).ready(function () {
success: function (data) {
if (data.status === true) {
if (data.message) {
var old_style = bs_alert(data.message, data.reload);
var old_style = bs_alert(data.message, data.status, data.reload);
}
if (data.table_reload === true) {
$('table').bootstrapTable('refresh');
@ -146,11 +142,7 @@ $(document).ready(function () {
}
} else {
if (Array.isArray(data.message)) {
data.message.forEach(function (entry) {
fpbxToast(entry, 'error', 'error');
});
}
bs_alert(data.message,data.status);
}
}
});
@ -202,7 +194,7 @@ $(document).ready(function () {
// console.log(data);
if (data.status === true) {
if (data.message) {
var old_style = bs_alert(data.message, data.reload);
var old_style = bs_alert(data.message, data.status, data.reload);
}
if (data.table_reload === true) {
$('table').bootstrapTable('refresh');
@ -211,11 +203,7 @@ $(document).ready(function () {
location.reload();
}
} else {
if (Array.isArray(data.message)) {
data.message.forEach(function (entry) {
fpbxToast(entry, 'error', 'error');
});
}
bs_alert(data.message,data.status);
}
}
@ -645,7 +633,7 @@ $(document).ready(function () {
// console.log(data);
if (data.status === true) {
if (data.message) {
var old_style = bs_alert(data.message, data.reload);
var old_style = bs_alert(data.message, data.status,data.reload);
}
if (data.table_reload === true) {
$('table').bootstrapTable('refresh');
@ -656,14 +644,15 @@ $(document).ready(function () {
} else {
if (Array.isArray(data.message)) {
data.message.forEach(function (entry) {
fpbxToast(entry, 'error', 'error');
bs_alert(entry,data.status);
//fpbxToast(entry, 'error', 'error');
});
} else {
if (data.message) {
bs_alert(data.message);
bs_alert(data.message,data.status);
} else {
if (data) {
bs_alert(data);
bs_alert(data,data.status);
}
}
}
@ -751,7 +740,7 @@ $("table").on("post-body.bs.table", function () {
});
toggle_reload_button("show");
} else {
bs_alert(data.message);
bs_alert(data.message, data.status);
}
});
}
@ -1001,25 +990,51 @@ var theForm = document.editIax;
return unescape(result);
}
*/
function bs_test() {
// alert('asasasasas');
function bs_page_reload() {
window.location.reload(false);
}
function bs_alert(data, reload)
function bs_alert(data, status, reload)
{
if (document.getElementById('hwalert') === null) {
alert(data);
if (Array.isArray(data)) {
data.forEach(function (entry) {
alert(entry);
});
}else {
alert(data);
}
return true; // Old style
} else {
var modal = $("#hwalert");
modal.find('.modal-title').text('Success operation ');
modal.find('.modal-body').text(data);
var modal = $("#hwalert");
if (typeof status != "undefined") {
if (status === true) {
modal.find('.modal-title').text('Operation result');
} else {
modal.find('.modal-title').text('Erroe operation ');
}
} else {
modal.find('.modal-title').text('Operation result');
}
// var modal2 = modal.find('.modal-title');
// console.log(modal2);
// modal.find('.modal-body').text(data);
var modal2 = modal.find('.modal-body');
var msg_html = '';
if (Array.isArray(data)) {
data.forEach(function(entry) {
msg_html = msg_html + '<p>'+ entry + '</p>';
});
}else {
msg_html = data;
}
modal2[0].innerHTML = msg_html;
if (typeof reload != "undefined") {
if (reload === true) {
$("#hwalert").on('hidden.bs.modal', bs_test);
$("#hwalert").on('hidden.bs.modal', bs_page_reload);
}
}
$("#hwalert").modal('show');
modal.modal('show');
return false;
}