diff --git a/controllers/ConfigController.php b/controllers/ConfigController.php index a8561eef..04395403 100644 --- a/controllers/ConfigController.php +++ b/controllers/ConfigController.php @@ -300,7 +300,7 @@ class ConfigController extends Controller { } public function actionReset() { - if (Yii::$app->request->isAjax) { + if (Yii::$app->request->post()) { $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([ 'http' => [ 'header' => "Content-Type: application/json", @@ -330,7 +330,17 @@ class ConfigController extends Controller { ]) ] ])); + if (Yii::$app->request->post("deleteDB") === "yes") { + \Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute(); + \Yii::$app->db->createCommand()->truncateTable('list_management')->execute(); + } return Url::to(['/config']); + } else { + Yii::$app->response->format = "json"; + return [ + "title" => "Reset thiết bị", + "form" => $this->renderPartial("reset") + ]; } } diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php index c52e5cfc..7a22ab2c 100644 --- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php +++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php @@ -42,7 +42,7 @@ use yii\widgets\ActiveForm;
  • - + Reset thiết bị
  • diff --git a/views/config/reset.tpl b/views/config/reset.tpl new file mode 100644 index 00000000..e029f16d --- /dev/null +++ b/views/config/reset.tpl @@ -0,0 +1,10 @@ +
    +

    BẠN CÓ MUỐN XÓA DỮ LIỆU LƯU TRỮ TRONG THIẾT BỊ KHÔNG?

    +
    + + +
    \ No newline at end of file diff --git a/web/js/common.js b/web/js/common.js index d7653800..32a169d7 100644 --- a/web/js/common.js +++ b/web/js/common.js @@ -287,12 +287,30 @@ common.success = function (id) { $("#" + id).addClass("has-success").removeClass("has-error"); $("#" + id).find(".help-block").addClass("hidden"); }; -common.reset = function (e) { +common.resetForm = function (e) { + common.modalBlock(true); + $.ajax({ + url: $(e).attr("href"), + type: 'POST', + success: function (data) { + common.modalBlock(false); + common.modalOpen(data.form, false, data.title); + }, + error: function (jqXHR, textStatus, errorThrown) { + common.modalBlock(false); + common.ajaxError(); + } + }); +}; +common.reset = function (e, deleteDB) { if (confirm("Bạn có chắc chắn muốn reset thiết bị về cấu hình mặc định không?")) { common.modalBlock(true); $.ajax({ - url: $(e).attr("href"), + url: $(e).attr("data-href"), type: 'POST', + data: { + deleteDB: deleteDB + }, success: function (data) { window.location = data; },