1+ <div class="col py-1 d-flex contain-converter">
2+ <section>
3+ <div id="alert-errors">
4+ <!-- HERE IS THE NOTIFICATION -->
5+ </div>
6+ </section>
7+ <div class="form-inline py-3 px-3" style="
8+ width: 250px;margin: auto;
9+ border-radius: 15px;
10+ background-color: white;
11+ -webkit-box-shadow: -1px 7px 5px -3px rgb(107 104 107 / 64%);
12+ -moz-box-shadow: -1px 7px 5px -3px rgba(107, 104, 107, 0.64);
13+ box-shadow: -1px 7px 5px -3px rgb(107 104 107 / 64%);
14+ ">
15+ <div class="form-group">
16+ <label for="exampleInputPassword1">Mount</label>
17+ <input type="number" class="form-control" id="mount">
18+ </div>
19+ <label class="my-1 mr-2" for="inlineFormCustomSelectPref">Preference</label>
20+ <?php
21+ echo div_open ('class="form-group" ' );
22+ echo form_dropdown ('cod_base ' ,$ cod_base_currency_array ,$ cod_base_currency ,'class="form-select form-select-lg mb-3" id="cod_base" ' );
23+ echo div_close ();
24+ echo form_label ('Convert to ' );
25+ echo div_open ('class="form-group" ' );
26+ echo form_dropdown ('cod_base_convert ' ,$ cod_base_currency_array ,$ cod_base_currency ,'class="form-select form-select-lg mb-3" id="cod_base_convert" ' );
27+ echo div_close ();
28+ ?>
29+ <!-- <div class="custom-control custom-checkbox my-1 mr-sm-2">
30+ <input type="checkbox" class="custom-control-input" id="customControlInline">
31+ <label class="custom-control-label" for="customControlInline">Remember my preference</label>
32+ </div> -->
33+ <div class="contain-button d-flex justify-content-center" >
34+ <button type="submit" class="btn btn-outline-primary my-1 w-100" id="button-call" >Submit</button>
35+ </div>
36+ <br>
37+ <div class="contain-anser text-center">
38+ <p id="answer-text"></p>
39+ </div>
40+ </div>
41+ <script src="https://code.jquery.com/jquery-3.6.3.js" integrity="sha256-nQLuAZGRRcILA+6dMBOvcRh5Pe310sBpanc6+QBmyVM=" crossorigin="anonymous"></script>
42+ <!-- convertCurrency -->
43+ <script>
44+ let baseUrl = "<?php echo site_url (); ?> ";
45+ let buttonGetData = document.getElementById("button-call");
46+ buttonGetData.addEventListener('click',function(e)
47+ {
48+ e.preventDefault()
49+ let mount = document.getElementById('mount')
50+ let cod_base = document.getElementById('cod_base')
51+ let cod_base_convert = document.getElementById('cod_base_convert')
52+ let answer_text = document.getElementById('answer-text')
53+ obj={
54+ curmont: mount.value,
55+ curbase: cod_base.value,
56+ curdest: cod_base_convert.value,
57+ user_id:'gonzalez_angel',
58+ codkey:"<?php $ this ->load ->config ('currencyweb ' );echo $ this ->config ->item ('codkey ' );?> "
59+ }
60+ $.ajax({
61+ type: 'post',
62+ url: baseUrl + '/Currency_Api/convertCurrency',
63+ data: obj,
64+ success: function(answer)
65+ {
66+ answer = answer.split('\n')
67+ answer = JSON.parse(answer[0])
68+ console.log(answer)
69+ if(answer.result == 'user_id is not valid'){
70+ notificationError('user_id is not valid','danger')
71+ closeNotification('#alert')
72+ };
73+ if(answer.result !== 1 ){
74+ notificationError(answer.result,'danger')
75+ // setTimeout(function () {
76+ // // Closing the alert
77+ // $('#alert').alert('close');
78+ // }, 3000);
79+ closeNotification('#alert')
80+ };
81+ if(answer.result == 1) {
82+ answer_text.innerHTML=`${answer.currency_mont}`
83+ }
84+ // buttonGetData.innerHTML=['',]
85+ // location.reload()
86+ // return
87+ },
88+ error: function(result)
89+ {
90+ // return
91+ // buttonGetData.innerHTML=['<i class="bi bi-x-octagon-fill" style="font-size: 30px;"></i>',]
92+ // console.log(result)
93+ }
94+ });
95+ // return
96+ })
97+ const alertError = document.getElementById('alert-errors')
98+ const notificationError = (message, type) =>
99+ {
100+ const wrapper = document.createElement('div')
101+ wrapper.innerHTML =
102+ [
103+ `<div class="alert alert-${type} alert-dismissible text-center custom-alerts py-0 px-0" role="alert" id="alert" style=" position: fixed; width: 55%; left: 30%; top: 1%; z-index: 10000000000;">`,
104+ '<br>',
105+ `<p>${message}</p>`,
106+ '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>',
107+ '<p id="error-message" style="color: red;font-size: 25px;"></p>',
108+ '</div>'
109+ ].join('')
110+ alertError.append(wrapper)
111+ }
112+ /*
113+ * Params id type:string example: #alert
114+ */
115+ function closeNotification(id){
116+ setTimeout(function () {
117+ // Closing the alert
118+ $(id).alert('close');
119+ }, 3000)
120+ }
121+
122+ </script>
0 commit comments