Commit b6beb3c7 authored by Azy Mushofy Anwary's avatar Azy Mushofy Anwary

Tambah Gambar

parent cd87a10e
...@@ -610,7 +610,6 @@ class ApiController extends \Application\Master\GlobalActionController { ...@@ -610,7 +610,6 @@ class ApiController extends \Application\Master\GlobalActionController {
return $this->getOutput($result->toJson()); return $this->getOutput($result->toJson());
} }
public function savekelolapoliAction(){ public function savekelolapoliAction(){
if($this->isLoggedIn()){ if($this->isLoggedIn()){
$result = new Result(); $result = new Result();
...@@ -620,37 +619,66 @@ class ApiController extends \Application\Master\GlobalActionController { ...@@ -620,37 +619,66 @@ class ApiController extends \Application\Master\GlobalActionController {
$table_poli= 'poli'; $table_poli= 'poli';
if ($request->isPost()) { if ($request->isPost()) {
$storage = \Application\Model\Param\Storage::factory($this->getDb(), $this->getConfig()); $storage = \Application\Model\Param\Storage::factory($this->getDb(), $this->getConfig());
$param = new \Application\Model\Param($storage); $param = new \Application\Model\Param($storage);
try{ try{
$fileupload = $_FILES['fileupload']['tmp_name'];
// print_r($fileupload);die;
$nama_poli = $post->inama_poli; $nama_poli = $post->inama_poli;
$kode_poli = $post->ikode_poli; $kode_poli = $post->ikode_poli;
$deskripsi_poli = $post->ideskripsi_poli; $deskripsi_poli = $post->ideskripsi_poli;
$dataArrayPoli = array ( if (!empty($fileupload)){
$ImageName = $_FILES['fileupload']['name'];
'nama_poli' => $nama_poli, $tipes = $_FILES['fileupload']['type'];
'kode_poli' =>$kode_poli, $size = $_FILES['fileupload']['size'];
'deskripsi_poli'=>$deskripsi_poli,
$uploaddir = './public/tamplate/img/poli/'; // directory file
);
$alamatfile = $uploaddir.$ImageName;
if (move_uploaded_file($_FILES['fileupload']['tmp_name'],$alamatfile)){
// print_r('berhasil');die;
/* jika upload berhasil ke folder sever */
$dataAtt = array(
'nama_poli' => $nama_poli,
'image_poli' => $ImageName,
'deskripsi_poli' => $deskripsi_poli,
'kode_poli' => $kode_poli,
);
$param->saveGlobal($dataAtt, $table_poli);
$result->code = 0;
$result->info = 'ok';
$result->data = $dataArrayPoli->data;
}else{
$result->code = 17;
$result->info = 'FAILED UPLOAD FILE to SERVER';
}
}else{
$result->info = 'File tidak boleh kosong';
}
// print_r($dataArrayPoli);die; // print_r($dataArrayPoli);die;
$param->saveGlobal($dataArrayPoli, $table_poli); // $param->saveGlobal($dataArrayPoli, $table_poli);
$result->code = 0; // $result->code = 0;
$result->info = 'ok'; // $result->info = 'ok';
$result->data = $dataArrayPoli; // $result->data = $dataArrayPoli;
}catch (\Exception $exc) { }catch (\Exception $exc) {
...@@ -663,6 +691,7 @@ class ApiController extends \Application\Master\GlobalActionController { ...@@ -663,6 +691,7 @@ class ApiController extends \Application\Master\GlobalActionController {
return $this->getOutput($result->toJson()); return $this->getOutput($result->toJson());
} }
public function editkelolapoliAction(){ public function editkelolapoliAction(){
if($this->isLoggedIn()){ if($this->isLoggedIn()){
$result = new Result(); $result = new Result();
......
...@@ -94,10 +94,10 @@ ...@@ -94,10 +94,10 @@
</a> </a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink"> <div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
<div class="dropdown-header">Dropdown Header:</div> <div class="dropdown-header">Dropdown Header:</div>
<a class="dropdown-item" href="#">Action</a> <a class="dropdown-item" id="poli"></a>
<a class="dropdown-item" href="#">Another action</a> <select name="poli" id="poli" class="form-control" >
<div class="dropdown-divider"></div> <option disable selected> Pilih </option>
<a class="dropdown-item" href="#">Something else here</a> </select>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<button type="button" class="close" data-dismiss="modal">&times;</button> <button type="button" class="close" data-dismiss="modal">&times;</button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form id="myForm"> <form id="myForm" method="POST" action="<?php $this->basePath('/api/savekelolapoli') ?>" enctype="multipart/form-data">
<div class="form-group"> <div class="form-group">
<label>Nama Poli</label> <label>Nama Poli</label>
...@@ -70,12 +70,12 @@ ...@@ -70,12 +70,12 @@
</div> </div>
<div class="form-group " > <div class="form-group " >
<label>Gambar Poli</label> <label>Gambar Poli</label>
<input type="file" name="image_poli" id="image_poli" class="form-control-file"> <input type="file" name="gambar_poli" id="gambar_poli" class="form-control-file">
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-primary" id="tambah">Add</button> <button type="submit" class="btn btn-primary" id="tambah">Add</button>
<button type="button" class="btn btn-danger" onclick="reset()">Reset</button> <button type="button" class="btn btn-danger" onclick="reset()">Reset</button>
<button type="submit" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div> </div>
</form> </form>
</div> </div>
......
...@@ -69,7 +69,8 @@ function Loadpoli() { ...@@ -69,7 +69,8 @@ function Loadpoli() {
} }
$('#tambah').on('click', function () { $('#tambah').on('click', function (e) {
e.preventDefault();
let nama_poli = $('#nama_poli').val(); let nama_poli = $('#nama_poli').val();
let kode_poli = $('#kode_poli').val(); let kode_poli = $('#kode_poli').val();
let deskripsi_poli = $('#deskripsi_poli').val(); let deskripsi_poli = $('#deskripsi_poli').val();
...@@ -94,297 +95,291 @@ $('#tambah').on('click', function () { ...@@ -94,297 +95,291 @@ $('#tambah').on('click', function () {
} else { } else {
savedatapoli(); savedatapoli();
} }
})
function saveTheoryOfDespair() {
function savedatapoli() {
let nama_poli = $('#nama_poli').val();
let kode_poli = $('#kode_poli').val();
let deskripsi_poli = $('#deskripsi_poli').val();
const fileupload = $('#gambar_poli').prop('files')[0];
let formData = new FormData();
formData.append('inama_poli', nama_poli);
formData.append('ikode_poli', kode_poli);
formData.append('ideskripsi_poli', deskripsi_poli);
formData.append('fileupload', fileupload); // set file ke tipe data binary
$.ajax({
type: 'POST',
dataType: 'json',
url: baseURL + '/api/savekelolapoli',
data:
// inama_poli: nama_poli,
// ikode_poli: kode_poli,
// ideskripsi_poli: deskripsi_poli,
formData,
} cache: false,
processData: false,
function savedatapoli() { contentType: false,
let nama_poli = $('#nama_poli').val();
let kode_poli = $('#kode_poli').val();
let deskripsi_poli = $('#deskripsi_poli').val();
const fileupload = $('#image_poli').prop('files')[0];
success: function (response) {
let formData = new FormData();
formData.append('fileupload', fileupload); // set file ke tipe data binary if (response['code'] == 0) {
swal({
console.log(fileupload); title: "",
text: "Data Berhasil Ditambahkan!",
let image = $('#kode_poli').val(); icon: "succes",
button: "ok",
$.ajax({ }, function () {
type: 'POST', location.reload();
dataType: 'json', });
url: baseURL + '/api/savekelolapoli',
data: {
inama_poli: nama_poli,
ikode_poli: kode_poli,
ideskripsi_poli: deskripsi_poli,
},
success: function (response) {
if (response['code'] == 0) {
swal({
title: "",
text: "Data Berhasil Ditambahkan!",
icon: "succes",
button: "ok",
}, function () {
location.reload();
});
} else { } else {
swal({ swal({
title: "", title: "",
text: "Data Gagal Ditambahkan!", text: "Data Gagal Ditambahkan!",
icon: "succes", icon: "succes",
button: "ok", button: "ok",
}); });
} }
}, },
error: function (xhr) { error: function (xhr) {
if (xhr.status != 200) { if (xhr.status != 200) {
//bootbox.alert(xhr.status + "-" + xhr.statusText + " <br>Silahkan coba kembali :) "); //bootbox.alert(xhr.status + "-" + xhr.statusText + " <br>Silahkan coba kembali :) ");
} else { } else {
alert('gagal error'); alert('gagal error');
}
} }
}
}); });
} }
function validasipoli(nama_poli, kode_poli) { function validasipoli(nama_poli, kode_poli) {
var exist = 0; var exist = 0;
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
url: baseURL + '/api/loadkelolapoli', url: baseURL + '/api/loadkelolapoli',
async: false, async: false,
data: { data: {
id: null, id: null,
}, },
success: function (result) { success: function (result) {
var data = result.data; var data = result.data;
for (x in data) { for (x in data) {
if (nama_poli == data[x]['nama_poli']) { if (nama_poli == data[x]['nama_poli']) {
exist = 1; exist = 1;
} }
if (kode_poli == data[x]['kode_poli']) { if (kode_poli == data[x]['kode_poli']) {
exist = 2; exist = 2;
}
} }
}
},
error: function (xhr) {
//alert(xhr.status+'-'+xhr.statusText);
}
});
return exist;
}
},
$('#edit').on('click', function () { error: function (xhr) {
let id_poli = $('#id_poli').val(); //alert(xhr.status+'-'+xhr.statusText);
let nama_poli = $('#nama_poliEdt').val(); }
let kode_poli = $('#kode_poliEdt').val(); });
let deskripsi_poli = $('#deskripsi_poliEdt').val(); return exist;
if (nama_poli == null || nama_poli == "") {
bootbox.alert({ message: 'Nama poli tidak boleh kosong', centerVertical: true });
return false;
}
else if (kode_poli == null || kode_poli == "") {
bootbox.alert({ message: 'Kode poli tidak boleh kosong', centerVertical: true });
return false;
}
else if (deskripsi_poli == null || deskripsi_poli == "") {
bootbox.alert({ message: 'Deskripsi poli tidak boleh kosong', centerVertical: true });
return false;
}
else if (validasipoli(nama_poli, kode_poli) == 1) {
bootbox.alert({ message: 'Nama poli harus berbeda!', centerVertical: true });
}
else if (validasipoli(nama_poli, kode_poli) == 2) {
bootbox.alert({ message: 'Kode poli harus berbeda!', centerVertical: true });
} else {
editdatapoli(id_poli)
} }
})
function editdatapoli(id_poli) {
let nama_poli = $('#nama_poliEdt').val();
let kode_poli = $('#kode_poliEdt').val();
let deskripsi_poli = $('#deskripsi_poliEdt').val();
// let image = $('#kode_poli').val(); $('#edit').on('click', function () {
let id_poli = $('#id_poli').val();
let nama_poli = $('#nama_poliEdt').val();
let kode_poli = $('#kode_poliEdt').val();
let deskripsi_poli = $('#deskripsi_poliEdt').val();
$.ajax({ if (nama_poli == null || nama_poli == "") {
type: 'POST', bootbox.alert({ message: 'Nama poli tidak boleh kosong', centerVertical: true });
dataType: 'json', return false;
url: baseURL + '/api/editkelolapoli', }
async: false, else if (kode_poli == null || kode_poli == "") {
data: { bootbox.alert({ message: 'Kode poli tidak boleh kosong', centerVertical: true });
id: id_poli, return false;
inama_poli: nama_poli, }
ikode_poli: kode_poli, else if (deskripsi_poli == null || deskripsi_poli == "") {
ideskripsi_poli: deskripsi_poli, bootbox.alert({ message: 'Deskripsi poli tidak boleh kosong', centerVertical: true });
}, return false;
}
else if (validasipoli(nama_poli, kode_poli) == 1) {
bootbox.alert({ message: 'Nama poli harus berbeda!', centerVertical: true });
}
else if (validasipoli(nama_poli, kode_poli) == 2) {
bootbox.alert({ message: 'Kode poli harus berbeda!', centerVertical: true });
} else {
editdatapoli(id_poli)
}
success: function (response) { })
//console.log(respoonse); function editdatapoli(id_poli) {
if (response['code'] == 0) { let nama_poli = $('#nama_poliEdt').val();
swal({ let kode_poli = $('#kode_poliEdt').val();
title: "", let deskripsi_poli = $('#deskripsi_poliEdt').val();
text: "Data Berhasil DiUbah!",
icon: "succes",
button: "ok", // let image = $('#kode_poli').val();
}, function () {
location.reload(); $.ajax({
}); type: 'POST',
dataType: 'json',
url: baseURL + '/api/editkelolapoli',
async: false,
data: {
id: id_poli,
inama_poli: nama_poli,
ikode_poli: kode_poli,
ideskripsi_poli: deskripsi_poli,
},
} else { success: function (response) {
swal({ //console.log(respoonse);
title: "", if (response['code'] == 0) {
text: "Data Gagal Ditambahkan!", swal({
icon: "succes", title: "",
button: "ok", text: "Data Berhasil DiUbah!",
}); icon: "succes",
button: "ok",
}, function () {
location.reload();
});
} } else {
swal({
title: "",
text: "Data Gagal Ditambahkan!",
icon: "succes",
button: "ok",
});
}
},
error: function (xhr) {
if (xhr.status != 200) { },
//bootbox.alert(xhr.status + "-" + xhr.statusText + " <br>Silahkan coba kembali :) "); error: function (xhr) {
} else {
alert('gagal error'); if (xhr.status != 200) {
//bootbox.alert(xhr.status + "-" + xhr.statusText + " <br>Silahkan coba kembali :) ");
} else {
alert('gagal error');
}
} }
}
}); });
} }
function loadedit(param) { function loadedit(param) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
url: baseURL + '/api/loadkelolapoli', url: baseURL + '/api/loadkelolapoli',
data: { data: {
id: param, id: param,
}, },
success: function (result) { success: function (result) {
// console.log(result); // console.log(result);
// $('.loaddata').empty(); // $('.loaddata').empty();
// console.log(result); // console.log(result);
if (result.code == 0) { if (result.code == 0) {
let data = result.data; let data = result.data;
$('#id_poli').val(data[0].id_poli); $('#id_poli').val(data[0].id_poli);
$('#nama_poliEdt').val(data[0].nama_poli); $('#nama_poliEdt').val(data[0].nama_poli);
$('#nama_poli2').val(data[0].nama_poli); $('#nama_poli2').val(data[0].nama_poli);
$('#kode_poliEdt').val(data[0].kode_poli); $('#kode_poliEdt').val(data[0].kode_poli);
$('#deskripsi_poliEdt').val(data[0].deskripsi_poli); $('#deskripsi_poliEdt').val(data[0].deskripsi_poli);
} else { } else {
alert(result.info); alert(result.info);
}
},
error: function (xhr) {
alert(xhr.status + '-' + xhr.statusText);
} }
}, });
error: function (xhr) { }
alert(xhr.status + '-' + xhr.statusText);
}
});
}
function Delete(param) { function Delete(param) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
url: baseURL + '/api/loadkelolapoli', url: baseURL + '/api/loadkelolapoli',
data: { data: {
id: param, id: param,
},
success: function (result) {
// console.log(result.data[0].nama_poli);
let nama_poli = result.data[0].nama_poli;
swal({
title: "Apakah yakin mengahapus poli '" + nama_poli + "'? \nJika anda menghapus Poli ini \nmaka Dokter Dan Ruangan \ndengan nama poli '" + nama_poli + "' akan terhapus",
type: "error",
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes!",
showCancelButton: true,
}, },
function () { success: function (result) {
$.ajax({ // console.log(result.data[0].nama_poli);
type: 'POST', let nama_poli = result.data[0].nama_poli;
dataType: 'json', swal({
url: baseURL + '/api/deletekelolapoli', title: "Apakah yakin mengahapus poli '" + nama_poli + "'? \nJika anda menghapus Poli ini \nmaka Dokter Dan Ruangan \ndengan nama poli '" + nama_poli + "' akan terhapus",
data: { type: "error",
id: param, confirmButtonClass: "btn-danger",
}, confirmButtonText: "Yes!",
success: function (result) { showCancelButton: true,
// console.log(result)
if (result.code == 0) {
swal({
title: "",
text: "Data Berhasil Dihapus!",
icon: "succes",
button: "ok",
}, function () {
location.reload();
});
} else {
swal({
title: "",
text: "Data Gagal Dihapus!",
icon: "succes",
button: "ok",
});
}
},
error: function (xhr) {
alert(xhr.status + '-' + xhr.statusText);
}
});
}, },
function () { function () {
// This function will run if the user clicked "cancel" $.ajax({
window.location.href = "<?php echo Yii::$app->request->baseUrl;?>/todo/index/"; type: 'POST',
} dataType: 'json',
); url: baseURL + '/api/deletekelolapoli',
data: {
id: param,
},
success: function (result) {
// console.log(result)
if (result.code == 0) {
swal({
title: "",
text: "Data Berhasil Dihapus!",
icon: "succes",
button: "ok",
}, function () {
location.reload();
});
} else {
swal({
title: "",
text: "Data Gagal Dihapus!",
icon: "succes",
button: "ok",
});
}
},
error: function (xhr) {
alert(xhr.status + '-' + xhr.statusText);
}
});
},
function () {
// This function will run if the user clicked "cancel"
window.location.href = "<?php echo Yii::$app->request->baseUrl;?>/todo/index/";
}
);
} }
}); });
} }
...@@ -4,6 +4,7 @@ Chart.defaults.global.defaultFontColor = '#858796'; ...@@ -4,6 +4,7 @@ Chart.defaults.global.defaultFontColor = '#858796';
// Pie Chart Example // Pie Chart Example
var ctx = document.getElementById("myPieChart"); var ctx = document.getElementById("myPieChart");
var myPieChart = new Chart(ctx, { var myPieChart = new Chart(ctx, {
type: 'doughnut', type: 'doughnut',
data: { data: {
...@@ -33,3 +34,44 @@ var myPieChart = new Chart(ctx, { ...@@ -33,3 +34,44 @@ var myPieChart = new Chart(ctx, {
cutoutPercentage: 80, cutoutPercentage: 80,
}, },
}); });
loadpoli()
function loadpoli() {
$.ajax({
type: 'POST',
dataType: 'json',
url: baseURL + '/api/loadRegisterpoli',
success: function (result) {
if (result['code'] == 0) {
//console.log (result);
var res = result['data'];
optionseg = '';
optionseg += '<option value="Pilih" disabled selected>Pilih</option>';
for (var i = 0; i < res.length; i++) {
optionseg += '<option value="' + res[i].id_poli + '">' + res[i].nama_poli + '</option>';
}
$("select#poli").html(optionseg);
} else {
bootbox.dialog({
message: "<span class='bigger-110'>" + result['info'] + "</span>",
buttons:
{
"OK":
{
"label": "<i class='icon-ok'></i> OK ",
"className": "btn-sm btn-danger",
"callback": function () {
notifyCancel('ERROR: ' + result['info'] + '. Bila ada kesulitan dimohon untuk menghubungi Admin terkait');
}
}
}
});
}
}
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment