|
1 | 1 |
|
2 | 2 | <div class="col py-1"> |
3 | | - <section> |
4 | | - <div id="contain-modal"> |
| 3 | + <!-- <section> |
| 4 | + <div id="contain-modal"> --> |
5 | 5 | <!-- HERE IS THE DIALOG PLACE --> |
| 6 | + <!-- </div> --> |
| 7 | + <!-- </section> --> |
| 8 | + <section> |
| 9 | + <div id="alert-errors"> |
| 10 | + <!-- HERE IS THE NOTIFICATION --> |
6 | 11 | </div> |
7 | 12 | </section> |
8 | 13 | <section> |
|
14 | 19 | <div class="contain-table"> |
15 | 20 | <!-- HERE IS THE DATA DISPLAY --> |
16 | 21 | <?php |
17 | | - |
18 | 22 | $htmldisplaymessageapibutton = 'wait for the system to get the coin rates from the internet.'; |
19 | 23 | if($active) |
20 | 24 | { |
|
23 | 27 | echo form_button('button-call', $buttonicon, 'class="btn btn-outline-success" id="button-call"'); |
24 | 28 | echo div_close(); |
25 | 29 | } |
26 | | - |
27 | | - |
28 | 30 | $htmldatadisplaymycurrencies = 'There is no data today, yet ..'.$htmldisplaymessageapibutton; |
29 | 31 | if(is_array($currency_list_dbarraypre) ) |
30 | 32 | { |
|
36 | 38 | $htmldatadisplaymycurrencies = $this->table->generate($currency_list_dbarraypre); |
37 | 39 | } |
38 | 40 | } |
39 | | - |
40 | 41 | $htmldatadisplayallcurrencies = 'The data of world currency rates today is not yet present.. '.$htmldisplaymessageapibutton; |
41 | 42 | if(is_array($currency_list_dbarraynow)) |
42 | 43 | { |
|
48 | 49 | $htmldatadisplayallcurrencies = $this->table->generate($currency_list_dbarraynow); |
49 | 50 | } |
50 | 51 | } |
51 | | - |
52 | 52 | echo heading('Your preferred currency rates',2,'style="text-align: center"'); |
53 | 53 | echo div_open(''); |
54 | 54 | echo '<section>'.$htmldatadisplaymycurrencies.'</section>'; |
55 | 55 | echo div_close(); |
56 | | - |
57 | 56 | echo heading('Your today all currency rates',2,'style="text-align: center"'); |
58 | 57 | echo div_open(''); |
59 | 58 | echo '<section>'.$htmldatadisplayallcurrencies.'</section>'; |
60 | 59 | echo div_close(); |
61 | | - |
62 | 60 | ?> |
63 | 61 | </div> |
64 | 62 | </section> |
|
68 | 66 | let uricall = baseUrl + '/Currency_Api'; |
69 | 67 | let user_st = "<?php echo $active; ?>"; |
70 | 68 | let user_id = "<?php $user_id = 'gonzalez_angel'; echo $user_id; ?>"; |
71 | | - |
| 69 | + let tableId = '#table_id'; |
| 70 | + let tableId2 = '#table_id2'; |
| 71 | + let urlUpdateRateAmount = '/updateRateAmount' |
72 | 72 | $(document).ready( function () |
73 | 73 | { |
74 | | - |
75 | | - table1 = $('#table_id').DataTable ( |
76 | | - { |
77 | | - order: [0], paging:false, searching:false, |
78 | | - columnDefs: [ {title:'code',targets:0},{title:'base',targets:1},{title:'rate',targets:2},{title:'currency',targets:3} ] |
79 | | - } |
80 | | - ); |
81 | | - |
82 | | - table2 = $('#table_id2').DataTable( |
| 74 | + // CREATE TABLE WITH DATATABLE |
| 75 | + function createDataTable(id){ |
| 76 | + let table = $(id).DataTable( |
83 | 77 | { |
84 | 78 | order: [0], paging:true, searching:true, |
85 | 79 | columnDefs: [ {title:'code',targets:0},{title:'base',targets:1},{title:'rate',targets:2},{title:'currency',targets:3} ] |
86 | | - } |
87 | | - ); |
88 | | - |
89 | | - if(user_st) |
90 | | - { |
91 | | - |
92 | | - /* table today prefered currencies data click on amount */ |
93 | | - |
94 | | - $('#table_id tbody').on('click', 'tr', function () |
| 80 | + }); |
| 81 | + return table |
| 82 | + } |
| 83 | + let table1 = createDataTable(tableId) |
| 84 | + let table2 = createDataTable(tableId2) |
| 85 | + // EVENT TABLE EDIT |
| 86 | + function addEventClickTable(id,table,url){ |
| 87 | + $(id+' tbody').on('click', 'tr', function () |
95 | 88 | { |
96 | | - var data = table1.row(this).data() |
97 | | - |
| 89 | + var data = table.row(this).data() |
98 | 90 | alert(data,'primary') |
99 | | - |
100 | 91 | let buttonEditData = document.getElementById("edit"); |
101 | 92 | let messageError = document.getElementById("error-message"); |
102 | | - |
103 | 93 | buttonEditData.addEventListener("click",function(event) |
104 | 94 | { |
105 | | - |
106 | 95 | event.preventDefault() |
107 | | - |
108 | 96 | let codTasa = document.getElementById("cod_tasa"); |
109 | 97 | let monTasaMoneda = document.getElementById("mon_tasa_moneda"); |
110 | 98 | let object = { |
|
114 | 102 | mon_tasa_moneda:monTasaMoneda.value |
115 | 103 | } |
116 | 104 | let button = document.getElementById('edit') |
117 | | - |
118 | 105 | $.ajax({ |
119 | 106 | type: 'post', |
120 | | - url: uricall + '/updateRateAmount', |
| 107 | + url: uricall + url, |
121 | 108 | data: object, |
122 | 109 | success: function(result) |
123 | 110 | { |
|
149 | 136 | }); |
150 | 137 | }) |
151 | 138 | }); |
152 | | - |
153 | | - /* table today all currencies data click on amount */ |
154 | | - |
155 | | - $('#table_id2 tbody').on('click', 'tr', function () |
156 | | - { |
157 | | - var data = table2.row(this).data() |
158 | | - alert(data,'primary') |
159 | | - |
160 | | - let buttonEditData = document.getElementById("edit"); |
161 | | - let messageError = document.getElementById("error-message"); |
162 | | - |
163 | | - buttonEditData.addEventListener("click",function(event) |
164 | | - { |
165 | | - event.preventDefault() |
166 | | - let codTasa = document.getElementById("cod_tasa"); |
167 | | - let monTasaMoneda = document.getElementById("mon_tasa_moneda"); |
168 | | - let object = { |
169 | | - method:'post', |
170 | | - user_id:user_id, |
171 | | - cod_tasa:codTasa.value, |
172 | | - mon_tasa_moneda:monTasaMoneda.value |
173 | | - } |
174 | | - let button = document.getElementById('edit') |
175 | | - |
176 | | - $.ajax({ |
177 | | - type: 'post', |
178 | | - url: uricall + '/updateRateAmount', |
179 | | - data: object, |
180 | | - success: function(result) |
181 | | - { |
182 | | - let answer = result.split('\n') |
183 | | - answer = JSON.parse(answer[0]) |
184 | | - if(answer.result !== 1) |
185 | | - { |
186 | | - button.innerHTML = ['<i class="bi bi-x-octagon-fill" style="color: red;font-size: 25px;"></i>',] |
187 | | - messageError.innerHTML=`${answer.result}` |
188 | | - } |
189 | | - else |
190 | | - { |
191 | | - button.innerHTML ='<i class="bi bi-check-circle" style="font-size: 25px;"></i>'; |
192 | | - button.addEventListener('click',function() |
193 | | - { |
194 | | - $('.alert').alert('close') |
195 | | - location.reload() |
196 | | - }) |
197 | | - } |
198 | | - }, |
199 | | - error: function(result) |
200 | | - { |
201 | | - button.innerHTML = '<i class="bi bi-x-octagon-fill" style="color: red;font-size: 25px;"></i>' |
202 | | - button.addEventListener('click',function() |
203 | | - { |
204 | | - $('.alert').alert('close') |
205 | | - }) |
206 | | - } |
207 | | - }); |
208 | | - }) |
209 | | - }); |
210 | | - |
| 139 | + } |
| 140 | + if(user_st) |
| 141 | + { |
| 142 | + /* table today prefered currencies data click on amount */ |
| 143 | + addEventClickTable(tableId,table1,urlUpdateRateAmount) |
| 144 | + /* table today all currencies data click on amount */ |
| 145 | + addEventClickTable(tableId2,table2,urlUpdateRateAmount) |
211 | 146 | } |
212 | | - |
213 | 147 | let buttonGetData = document.getElementById("button-call"); |
214 | | - |
215 | 148 | buttonGetData.addEventListener('click',function() |
216 | 149 | { |
217 | 150 | let object = { |
|
221 | 154 | } |
222 | 155 |
|
223 | 156 | buttonGetData.innerHTML=['<div class="spinner-border" role="status">','<span class="visually-hidden">Loading...</span>','</div>'] |
224 | | - |
225 | 157 | $.ajax({ |
226 | | - type: 'get', |
| 158 | + type: 'post', |
227 | 159 | url: uricall + '/callApisAndSaveDB', |
228 | 160 | data: object, |
229 | 161 | success: function(result) |
230 | 162 | { |
| 163 | + let answer = result.split('\n') |
| 164 | + answer = JSON.parse(answer[0]) |
| 165 | + if(answer.result !== 1 ){ |
| 166 | + notificationError(answer.result,'danger') |
| 167 | + } |
231 | 168 | buttonGetData.innerHTML=['<?php echo $buttonicon; ?>',] |
232 | 169 | location.reload() |
233 | 170 | }, |
|
238 | 175 | } |
239 | 176 | }); |
240 | 177 | }) |
241 | | - |
242 | 178 | }) |
243 | | - |
244 | 179 | const alertPlaceholder = document.getElementById('liveAlertPlaceholder') |
245 | 180 | const alert = (message, type) => |
246 | 181 | { |
247 | 182 | const wrapper = document.createElement('div') |
248 | | - |
249 | 183 | wrapper.innerHTML = |
250 | 184 | [ |
251 | | - '<div class="alert alert-${type} alert-dismissible text-center custom-alerts" role="alert" style=" position: fixed; width: 55%; left: 30%; top: 30%; z-index: 10000000000;">', |
| 185 | + `<div class="alert alert-${type} alert-dismissible text-center custom-alerts" role="alert" style=" position: fixed; width: 55%; left: 30%; top: 30%; z-index: 10000000000;">`, |
252 | 186 | '<br>', |
253 | 187 | '<form class="" method="POST" action="<?php echo site_url() ?>/Currency_Manager/updatecurrency" target="_self" id="edit-form">', |
254 | 188 | '<div class="form-group">', |
|
266 | 200 | '<p id="error-message" style="color: red;font-size: 25px;"></p>', |
267 | 201 | '</div>' |
268 | 202 | ].join('') |
269 | | - |
270 | 203 | alertPlaceholder.append(wrapper) |
271 | 204 | } |
272 | | - |
| 205 | + const alertError = document.getElementById('alert-errors') |
| 206 | + const notificationError = (message, type) => |
| 207 | + { |
| 208 | + const wrapper = document.createElement('div') |
| 209 | + wrapper.innerHTML = |
| 210 | + [ |
| 211 | + `<div class="alert alert-${type} alert-dismissible text-center custom-alerts py-0 px-0" role="alert" style=" position: fixed; width: 55%; left: 30%; top: 1%; z-index: 10000000000;">`, |
| 212 | + '<br>', |
| 213 | + `<p>${message}</p>`, |
| 214 | + '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>', |
| 215 | + '<p id="error-message" style="color: red;font-size: 25px;"></p>', |
| 216 | + '</div>' |
| 217 | + ].join('') |
| 218 | + alertError.append(wrapper) |
| 219 | + } |
273 | 220 | </script> |
274 | 221 |
|
0 commit comments