add.blade.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php $getStatus = \App\Model\Privillage\Role::where('id',Auth::user()->role_id)->value('akses'); ?>
  2. @extends('dev.core.using')
  3. @section('content')
  4. <style>
  5. input, select {
  6. border: 0 !important;
  7. background: transparent !important;
  8. border-bottom: 1px solid #cdcdcd !important;
  9. }
  10. .tb-container{
  11. background: #fff;
  12. margin-top: 1em;
  13. }
  14. tbody > tr {
  15. line-height: 45px !important;
  16. min-height: 45px !important;
  17. height: 45px !important;
  18. }
  19. .ic {
  20. width: 1.5rem;
  21. height: 1.3rem;
  22. border-radius: .5rem;
  23. text-align: center;
  24. cursor:pointer;
  25. /* background: #cdcdcd; */
  26. /* padding-top: .3rem; */
  27. font-size: 1em;
  28. list-style: none;
  29. color: #000;
  30. }
  31. </style>
  32. <br/>
  33. <br/>
  34. <form action="{{route('aktivasi-program.create')}}" method="POST" id="form-create">
  35. @csrf
  36. <div class="col">
  37. <div class="form-group">
  38. <label for="exampleInputEmail1">Tahun Program *</label>
  39. <input type="" class="form-control" id="tahunProgram" placeholder="No Data Available" name="value" required>
  40. <small id="tahunProgramHelp" class="form-text text-muted" style="color:red !important"></small>
  41. <!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
  42. </div>
  43. <div class="form-group">
  44. <label for="exampleInputEmail1">Status *</label>
  45. <select class="form-control" id="status" name="status" required>
  46. <option value="0">Draft</option>
  47. <option value="1">Aktif</option>
  48. <option value="2">Selesai</option>
  49. </select>
  50. </div>
  51. <div class="row">
  52. <div class="col-md-10"></div>
  53. <div class="col-md-2">
  54. <div class="btn btn-primary" style="background: #B4CD93;float:right" id="add-program"><i class="fas fa-plus-circle"></i> Tambah</div>
  55. </div>
  56. </div>
  57. <div class="btn btn-primary btn-lg btn-block" style="background: #193865;margin-top: 1em">Program</div>
  58. <div class="tb-container">
  59. <table class="table table-bordered">
  60. <thead >
  61. <tr class="table-dark">
  62. <th scope="col" width="300px">Program</th>
  63. <th scope="col" width="300px">Sub Program</th>
  64. <th scope="col">Periode</th>
  65. <th scope="col">Jumlah</th>
  66. <th scope="col">Aksi</th>
  67. </tr>
  68. </thead>
  69. <tbody id="tbody">
  70. <input type="hidden" name="uniqids" id="uniqids">
  71. </tbody>
  72. </table>
  73. </div>
  74. <div class="tb-container">
  75. <div class="row" style="padding:20px">
  76. <div class="col-md-8"></div>
  77. <div class="col-md-4">
  78. <button type="button" class="btn btn-primary confirmation" data-target="form-create" id="btn-submit" style="background: #193865"><i class="fa fa-save"></i> Simpan Perubahan</button>
  79. <a href="{{route('aktivasi-program')}}" class="btn btn-primary" id="btn-back" style="background: #fff;color: #193865">Batal</a>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </form>
  85. <script>
  86. $('#add-program').click(function() {
  87. var uniqid = Date.now();
  88. var id = '<input type="hidden" class="uniqid" value="'+uniqid+'">';
  89. var program = `<td><select class="form-control program" id="program-`+uniqid+`" name="id_template_program_`+uniqid+`" onChange="selectSubProgram(`+uniqid+`)">`
  90. @foreach($templateProgram as $opt)
  91. program += `<option value="{{$opt->id}}" id="`+uniqid+`">{{$opt->nama}}</option>`
  92. @endforeach
  93. program += `</select></td>`;
  94. var subprogram = `<td><select class="form-control subprogram" id="subprogram-`+uniqid+`" name="id_template_program_detail_`+uniqid+`">`
  95. subprogram += `</select></td>`;
  96. var periode = `<td>
  97. <select class="form-control" name="satuan_`+uniqid+`" id="satuan_`+uniqid+`" onChange="setJumlah(`+uniqid+`)">
  98. <option value="Tahun">Tahun</option>
  99. <option value="Bulan">Bulan</option>
  100. </select>
  101. </td>`;
  102. var jumlah = `<td>
  103. <select class="form-control" name="jumlah_`+uniqid+`" id="jumlah_`+uniqid+`">
  104. </select>
  105. </td>`;
  106. var aksi = '<td><center><a id="btn-remove" onClick="removeData('+uniqid+')"><i class="fas fa-trash" style="color: #E12D2D" ></i></a></center></td>';
  107. var attribute = '<tr id="tr-'+uniqid+'">'+id+program+subprogram+periode+jumlah+aksi+'</tr>';
  108. $('#tbody').append(attribute);
  109. setJumlah(uniqid);
  110. selectSubProgram(uniqid);
  111. // checkDuplicate();
  112. })
  113. function selectSubProgram(uniqid){
  114. var id_program = $('#program-'+uniqid).val();
  115. $.ajax({
  116. url: "{{url('api/pembuatan-program')}}/subprogram?id_template_program="+id_program,
  117. dataType: "json",
  118. type: "GET",
  119. async: true,
  120. data: { },
  121. beforeSend: function(){
  122. $('#subprogram-'+uniqid).children('option').remove();
  123. },
  124. success: function (result) {
  125. var opt = '';
  126. $.each( result.data, function( index, value ){
  127. opt += '<option value="'+value.id+'">'+value.nama+'</option>';
  128. });
  129. $('#subprogram-'+uniqid).append(opt);
  130. console.log(result.data);
  131. },
  132. error: function (xhr, exception) {
  133. var msg = "";
  134. if (xhr.status === 0) {
  135. msg = "Not connect.\n Verify Network." + xhr.responseText;
  136. } else if (xhr.status == 404) {
  137. msg = "Requested page not found. [404]" + xhr.responseText;
  138. } else if (xhr.status == 500) {
  139. msg = "Internal Server Error [500]." + xhr.responseText;
  140. } else if (exception === "parsererror") {
  141. msg = "Requested JSON parse failed.";
  142. } else if (exception === "timeout") {
  143. msg = "Time out error." + xhr.responseText;
  144. } else if (exception === "abort") {
  145. msg = "Ajax request aborted.";
  146. } else {
  147. msg = "Error:" + xhr.status + " " + xhr.responseText;
  148. }
  149. console.log(msg);
  150. }
  151. });
  152. }
  153. // function checkDuplicate(){
  154. // var selected = [];
  155. // var invalid = 0;
  156. // $('.program option:selected').each(function(i, obj) {
  157. // //remove tooltip
  158. // $('#parent-'+obj.id).tooltip('dispose');
  159. // //check if kolom is duplicate
  160. // if ($.inArray(obj.value, selected) != -1){
  161. // $('#parent-'+obj.id).css({'color':'red'});
  162. // $('#parent-'+obj.id).children('option').css({'color':'#8898aa'});
  163. // $('#parent-'+obj.id).tooltip({title: 'Program "'+obj.value+'" sudah digunakan'});
  164. // invalid++;
  165. // }else{
  166. // $('#parent-'+obj.id).css({'color':'#8898aa'});
  167. // }
  168. // selected.push(obj.value);
  169. // });
  170. // if(invalid>0){
  171. // $('#btn-submit').prop('disabled',true);
  172. // return false;
  173. // }else{
  174. // $('#btn-submit').prop('disabled',false);
  175. // return true;
  176. // }
  177. // }
  178. // checkDuplicate();
  179. $('#btn-submit').on('click',function(){
  180. // var check = checkDuplicate();
  181. // if(check){
  182. var uniqids = '';
  183. $('.uniqid').each(function(i, obj) {
  184. if(uniqids!=''){
  185. uniqids += ',';
  186. }
  187. uniqids += obj.value;
  188. });
  189. $('#uniqids').val(uniqids);
  190. // }
  191. });
  192. function removeData(uniqid){
  193. $('#tr-'+uniqid).remove();
  194. // checkDuplicate();
  195. }
  196. function setJumlah(uniqid){
  197. var satuan = $('#satuan_'+uniqid).find(":selected").val();
  198. var jumlah = 0;
  199. if(satuan=='Tahun'){
  200. jumlah = 12;
  201. }else if(satuan=='Bulan'){
  202. jumlah = 1;
  203. }
  204. var option = '';
  205. for(var i = 1;i<=jumlah;i++){
  206. option += '<option value="'+i+'">'+i+'</option>';
  207. }
  208. $('#jumlah_'+uniqid).children('option').remove();
  209. $('#jumlah_'+uniqid).append(option);
  210. }
  211. </script>
  212. @endsection