subprogram.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. .prev-holder, .className-wrap, .description-wrap, .tooltip-element, .copy-button {
  6. display:none !important;
  7. }
  8. .form-field{
  9. flex:0 0 50%;
  10. position:relative;
  11. width:50%;
  12. outline: 1px solid #a9a9a9;
  13. }
  14. .frmb {
  15. display:flex !important;
  16. flex-wrap:wrap !important;
  17. min-height:40px !important;
  18. }
  19. input, select {
  20. border: 0 !important;
  21. background: transparent !important;
  22. border-bottom: 1px solid #cdcdcd !important;
  23. }
  24. .tb-container{
  25. background: #fff;
  26. margin-top: 1em;
  27. }
  28. tbody > tr {
  29. line-height: 45px !important;
  30. min-height: 45px !important;
  31. height: 45px !important;
  32. }
  33. /* @media only screen and (max-width: 700px) {
  34. .field-label{
  35. white-space: nowrap;
  36. overflow: hidden;
  37. text-overflow: ellipsis;
  38. max-width: 100px;
  39. font-size: 14px !important;
  40. padding-left:0px !important;
  41. } */
  42. </style>
  43. <br/>
  44. <br/>
  45. <form action="{{route('pembuatan-program.subprogram.update',[$data->id_template_program, $data->id])}}" method="POST" enctype="multipart/form-data" id="form-edit">
  46. @csrf
  47. <input type="hidden" name="total_label" id="total_label">
  48. <input type="hidden" name="total_tipe_kolom" id="total_tipe_kolom">
  49. <input type="hidden" name="total_master_option" id="total_master_option">
  50. <input type="hidden" name="total_required" id="total_required">
  51. <input type="hidden" name="total_description" id="total_description">
  52. <div class="col">
  53. <div class="form-group">
  54. <label for="">Nama Sub Program *</label>
  55. <input type="text" class="form-control" id="namaProgram" name="nama" placeholder="No Data Available" value="{{$data->nama}}" required style="text-transform:uppercase" >
  56. <!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
  57. </div>
  58. <div class="row">
  59. <div class="col-md-9"></div>
  60. <!-- <div class="btn btn-primary" style="background: #B4CD93" id="add-item"><i class="fas fa-plus-circle"></i> Tambah Item Program</div> -->
  61. </div>
  62. <button type="button" class="btn btn-primary btn-lg btn-block" style="background: #193865;margin-top: 1em">Item Capaian Program</button>
  63. <div id="fb-editor"></div>
  64. </form>
  65. <div class="tb-container">
  66. <div class="row" style="padding:20px">
  67. <div class="col-md-8"></div>
  68. <div class="col-md-4">
  69. <button type="button" class="btn btn-primary confirmation" data-target="form-edit" id="btn-submit" style="background: #193865">Simpan Perubahan</button>
  70. <a href="{{route('pembuatan-program.edit',$data->id_template_program)}}" class="btn btn-primary" id="btn-back" style="background: #fff;color: #193865"> Kembali</a>
  71. </div>
  72. </div>
  73. </div>
  74. <script>
  75. </script>
  76. <script>
  77. $('#file_input').on('change',function(){
  78. var file = $(this).get(0).files[0];
  79. if(file){
  80. var reader = new FileReader();
  81. reader.onload = function(){
  82. $('#file_preview').attr('src',reader.result);
  83. $('#card_file_preview').show();
  84. }
  85. reader.readAsDataURL(file);
  86. }else{
  87. $('#card_file_preview').hide();
  88. }
  89. });
  90. var optKolom = [];
  91. @foreach($input as $key => $opt)
  92. optKolom.push({"kolom":"{{$key}}","type":"{{$opt['type']}}"});
  93. @endforeach
  94. // numbersString.split(',');
  95. //action tambah item
  96. $('#add-item').on('click',function(){
  97. var uniqid = Date.now();
  98. //initialize attribute
  99. var id = '<input type="hidden" class="uniqid" value="'+uniqid+'">';
  100. //kolom
  101. var kolom = '<td><select class="form-control kolom" onChange="setKolom('+uniqid+')" id="parent-'+uniqid+'" data-id="'+uniqid+'" required name="kolom_'+uniqid+'">';
  102. kolom += '<option value=""></option>';
  103. $.each( optKolom, function( index, value ) {
  104. kolom += '<option value="'+value.kolom+'" data-id="'+value.type+'" id="'+uniqid+'">'+value.kolom+'</option>';
  105. });
  106. kolom += '</select></td>';
  107. //label
  108. var label = '<td><input type="text" class="form-control label" value="" required name="label_'+uniqid+'">'
  109. //target
  110. var tipeKolom = `<td><select class="tipeKolom form-control" id="tipeKolom-`+uniqid+`" required name="tipe_kolom_`+uniqid+`">
  111. </select></td>`;
  112. //isRequired
  113. var isRequired = `<td><select class="is_required form-control" required name="is_required_`+uniqid+`">
  114. <option value="0">Tidak</option>
  115. <option value="1">Ya</option>
  116. </select></td>`;
  117. var aksi = '<td><center><a data-id="'+uniqid+'" onClick="removeData('+uniqid+')"><i class="fas fa-trash" style="color: #E12D2D" ></i></a></center></td>';
  118. var attribute = '<tr id="tr-'+uniqid+'">'+id+kolom+label+tipeKolom+isRequired+aksi+'</tr>';
  119. $('#body').append(attribute);
  120. });
  121. var optTipeKolom = [];
  122. optTipeKolom['text'] = `<option value="text">Text</option>
  123. <option value="file">File/Attachment</option>
  124. <option value="provinsi">Provinsi</option>
  125. <option value="kabkot">Kota/Kabupaten</option>`;
  126. optTipeKolom['number'] = `<option value="number">Numeric</option>`;
  127. optTipeKolom['date'] = `<option value="date">Date</option>`;
  128. function setKolom(uniqid){
  129. var value = $('#parent-'+uniqid).children("option:selected").attr('data-id');
  130. $('#tipeKolom-'+uniqid).children('option').remove();
  131. $('#tipeKolom-'+uniqid).append(optTipeKolom[value]);
  132. checkDuplicate();
  133. };
  134. function checkDuplicate(){
  135. var selected = [];
  136. var invalid = 0;
  137. $('.kolom option:selected').each(function(i, obj) {
  138. //remove tooltip
  139. $('#parent-'+obj.id).tooltip('dispose');
  140. //check if kolom is duplicate
  141. if ($.inArray(obj.value, selected) != -1){
  142. $('#parent-'+obj.id).css({'color':'red'});
  143. $('#parent-'+obj.id).children('option').css({'color':'#8898aa'});
  144. $('#parent-'+obj.id).tooltip({title: 'Kolom "'+obj.value+'" sudah digunakan'});
  145. invalid++;
  146. }else{
  147. $('#parent-'+obj.id).css({'color':'#8898aa'});
  148. }
  149. selected.push(obj.value);
  150. });
  151. if(invalid>0){
  152. $('#btn-submit').prop('disabled',true);
  153. return false;
  154. }else{
  155. $('#btn-submit').prop('disabled',false);
  156. return true;
  157. }
  158. }
  159. //trigger for first time;
  160. checkDuplicate();
  161. $('#btn-submit').on('click',function(){
  162. //get all label
  163. var total_label = '';
  164. $('.fld-label').each(function(i, obj) {
  165. if(total_label!=''){
  166. total_label += ',';
  167. }
  168. total_label += obj.value;
  169. });
  170. //get all tipe_kolom
  171. var total_tipe_kolom = '';
  172. $('.fld-title').each(function(i, obj) {
  173. if(total_tipe_kolom!=''){
  174. total_tipe_kolom += ',';
  175. }
  176. total_tipe_kolom += obj.value;
  177. });
  178. //get all master option
  179. var total_master_option = '';
  180. $('.fld-options').each(function(i, obj) {
  181. if(total_master_option!=''){
  182. total_master_option += ',';
  183. }
  184. total_master_option += obj.value;
  185. });
  186. //get all required trigger
  187. var total_required = '';
  188. $('.fld-required').each(function(i, obj) {
  189. if(total_required!=''){
  190. total_required += ',';
  191. }
  192. total_required += obj.checked;
  193. });
  194. //get all ID
  195. var total_description = '';
  196. $('.fld-description').each(function(i, obj) {
  197. if(total_description!=''){
  198. total_description += ',';
  199. }
  200. total_description += obj.value;
  201. });
  202. $('#total_label').val(total_label);
  203. $('#total_tipe_kolom').val(total_tipe_kolom);
  204. $('#total_master_option').val(total_master_option);
  205. $('#total_required').val(total_required);
  206. $('#total_description').val(total_description);
  207. });
  208. function removeData(uniqid){
  209. $('#tr-'+uniqid).remove();
  210. }
  211. </script>
  212. <script src="{{asset('templates/assets/js/form-builder.min.js')}}"></script>
  213. <script>
  214. var options = {
  215. disabledActionButtons: ['data','save','clear'],
  216. disabledFieldButtons: {
  217. text: ['copy'], // disables the remove butotn for text fields
  218. select: ['copy'], // disables the edit button for select fields
  219. date: ['copy'], // disables the edit button for select fields
  220. file: ['copy'], // disables the edit button for select fields
  221. number: ['copy'] // disables the edit button for select fields
  222. },
  223. typeUserAttrs: {
  224. select: {
  225. label: {
  226. label: 'Label',
  227. value: '',
  228. },
  229. options: {
  230. label: 'Master Option',
  231. options: {
  232. @foreach($masterOption as $row)
  233. '{{$row->id}}':'{{$row->label}}',
  234. @endforeach
  235. },
  236. style: 'border: 1px solid red'
  237. },
  238. title:{
  239. label: 'Tipe Data',
  240. value: 'select',
  241. readonly: 'true'
  242. },
  243. className:{
  244. label: 'Form Class',
  245. value: 'form-control',
  246. readonly: 'true'
  247. }
  248. },
  249. text: {
  250. label: {
  251. label: 'Label',
  252. value: '',
  253. },
  254. title:{
  255. label: 'Tipe Data',
  256. value: 'text',
  257. readonly: 'true'
  258. },
  259. className:{
  260. label: 'Form Class',
  261. value: 'form-control',
  262. readonly: 'true'
  263. }
  264. },
  265. number: {
  266. label: {
  267. label: 'Label',
  268. value: '',
  269. },
  270. title:{
  271. label: 'Tipe Data',
  272. value: 'number',
  273. readonly: 'true'
  274. },
  275. className:{
  276. label: 'Form Class',
  277. value: 'form-control',
  278. readonly: 'true'
  279. }
  280. },
  281. date: {
  282. label: {
  283. label: 'Label',
  284. value: '',
  285. },
  286. title:{
  287. label: 'Tipe Data',
  288. value: 'date',
  289. readonly: 'true'
  290. },
  291. className:{
  292. label: 'Form Class',
  293. value: 'form-control',
  294. readonly: 'true'
  295. }
  296. },
  297. file: {
  298. label: {
  299. label: 'Label',
  300. value: '',
  301. },
  302. title:{
  303. label: 'Tipe Data',
  304. value: 'file',
  305. readonly: 'true'
  306. },
  307. className:{
  308. label: 'Form Class',
  309. value: 'form-control',
  310. readonly: 'true'
  311. }
  312. }
  313. },
  314. typeUserDisabledAttrs: {
  315. 'text': [
  316. 'name',
  317. 'access',
  318. 'label',
  319. 'className',
  320. 'subtype',
  321. 'value',
  322. 'placeholder',
  323. 'maxlength'
  324. ],
  325. 'number': [
  326. 'name',
  327. 'access',
  328. 'label',
  329. 'className',
  330. 'subtype',
  331. 'value',
  332. 'min',
  333. 'max',
  334. 'step',
  335. 'placeholder',
  336. 'maxlength'
  337. ],
  338. 'date': [
  339. 'name',
  340. 'access',
  341. 'label',
  342. 'className',
  343. 'subtype',
  344. 'value',
  345. 'min',
  346. 'max',
  347. 'step',
  348. 'placeholder',
  349. 'maxlength'
  350. ],
  351. 'file': [
  352. 'name',
  353. 'access',
  354. 'label',
  355. 'className',
  356. 'subtype',
  357. 'value',
  358. 'placeholder',
  359. 'maxlength',
  360. 'multiple'
  361. ],
  362. 'select': [
  363. 'name',
  364. 'access',
  365. 'className',
  366. 'subtype',
  367. 'options',
  368. 'placeholder',
  369. 'label',
  370. 'multiple',
  371. ]
  372. },
  373. inputSets: [
  374. {
  375. label: 'Input Text',
  376. name: 'input-text', // optional - one will be generated from the label if name not supplied
  377. showHeader: false, // optional - Use the label as the header for this set of inputs
  378. fields: [
  379. {
  380. type: 'text',
  381. label: 'Input Text',
  382. className: 'form-control',
  383. }
  384. ]
  385. },
  386. {
  387. label: 'File/Attachment',
  388. name: 'file-attachment', // optional - one will be generated from the label if name not supplied
  389. showHeader: false, // optional - Use the label as the header for this set of inputs
  390. fields: [
  391. {
  392. type: 'file',
  393. label: 'File/Attachment',
  394. className: 'form-control',
  395. }
  396. ]
  397. },
  398. {
  399. label: 'Provinsi',
  400. name: 'provinsi', // optional - one will be generated from the label if name not supplied
  401. showHeader: false, // optional - Use the label as the header for this set of inputs
  402. fields: [
  403. {
  404. type: 'text',
  405. label: 'Provinsi',
  406. className: 'form-control',
  407. title:'provinsi'
  408. }
  409. ]
  410. },
  411. {
  412. label: 'Kota/Kabupaten',
  413. name: 'kabkot', // optional - one will be generated from the label if name not supplied
  414. showHeader: false, // optional - Use the label as the header for this set of inputs
  415. fields: [
  416. {
  417. type: 'text',
  418. label: 'Kota/Kabupaten',
  419. className: 'form-control',
  420. title:'kabkot'
  421. }
  422. ]
  423. },
  424. {
  425. label: 'Number',
  426. name: 'numbers', // optional - one will be generated from the label if name not supplied
  427. showHeader: false, // optional - Use the label as the header for this set of inputs
  428. fields: [
  429. {
  430. style:'width:100%',
  431. type: 'number',
  432. label: 'Number',
  433. className: 'form-control',
  434. }
  435. ]
  436. },
  437. {
  438. label: 'Date',
  439. name: 'dates', // optional - one will be generated from the label if name not supplied
  440. showHeader: false, // optional - Use the label as the header for this set of inputs
  441. fields: [
  442. {
  443. type: 'date',
  444. label: 'Date',
  445. className: 'form-control',
  446. }
  447. ]
  448. },
  449. {
  450. label: 'Select Option',
  451. name: 'select-option', // optional - one will be generated from the label if name not supplied
  452. showHeader: false, // optional - Use the label as the header for this set of inputs
  453. fields: [
  454. {
  455. type: 'select',
  456. label: 'Select Option',
  457. className: 'form-control'
  458. }
  459. ]
  460. },
  461. ],
  462. disableFields: [
  463. 'autocomplete',
  464. 'button',
  465. 'checkbox-group',
  466. 'date',
  467. 'file',
  468. 'header',
  469. 'hidden',
  470. 'number',
  471. 'paragraph',
  472. 'radio-group',
  473. 'select',
  474. 'starRating',
  475. 'text',
  476. 'textarea',
  477. ],
  478. @if(!empty($data->itemProgram))
  479. defaultFields: [
  480. @foreach($data->itemProgram->sortBy('order_by') as $key => $row)
  481. {
  482. className: "form-control",
  483. label: "{{$row->label}}", //label
  484. description: "{{$row->id}}", //id
  485. required: {{$row->is_required==1?'true':'false'}}, //is_required
  486. type: "{{$row->type}}", //type form builder (custom attribute)
  487. title: "{{$row->tipe_kolom}}", //tipe_kolom
  488. options: "{{$row->id_master_option}}"
  489. },
  490. @endforeach
  491. ],
  492. @endif
  493. };
  494. $('#fb-editor').formBuilder(options);
  495. $('.prev-holder').hide();
  496. </script>
  497. @endsection