Refactor previous name into dedicated service (#7571)
[openemr.git] / interface / modules / zend_modules / public / js / installer / action.js
blobfd1247102bcb057f34d3e3e3062bdd25c67a8164
1 /**
2  * interface/modules/zend_modules/public/js/installer/action.js
3  *
4  * @package   OpenEMR
5  * @link      https://www.open-emr.org
6  * @author    Jacob T.Paul <jacob@zhservices.com>
7  * @author    Vipin Kumar <vipink@zhservices.com>
8  * @author    Jerry Padgett <sjpadgett@gmail.com>
9  * @copyright Copyright (c) 2020-2024 Jerry Padgett <sjpadgett@gmail.com>
10  * @author    Remesh Babu S <remesh@zhservices.com>
11  * @copyright Copyright (c) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
12  * @license   https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13  */
15 function register(status, title, name, method, type) {
16     $.post("./Installer/register", {st: status, mod_title: title, mod_name: name, mod_method: method, mtype: type},
17         function (data) {
18             if (data == "Success") {
19                 window.location.reload();
20             } else {
21                 const resultTranslated = js_xl(data);
22                 $('#err').html(resultTranslated.msg).fadeIn().delay(2000).fadeOut();
23             }
24         }
25     );
28 function manage(id, action) {
29     if (action === 'unregister') {
30         if (!confirm("Please Confirm with OK to Unregister this Module.")) {
31             return false;
32         }
33     }
34     if (action === 'reset_module') {
35         if (!confirm("Please Confirm with OK to Reset Module!\nThis action may possibly remove database dependencies that are only related to this module.")) {
36             return false;
37         }
38     }
39     let install_upgrade_log = $("#install_upgrade_log");
40     install_upgrade_log.empty();
42     if (document.getElementById('mod_enc_menu'))
43         modencmenu = document.getElementById('mod_enc_menu').value;
44     else
45         modencmenu = '';
46     if (document.getElementById('mod_nick_name_' + id))
47         modnickname = document.getElementById('mod_nick_name_' + id).value;
48     else
49         modnickname = '';
50     $.ajax({
51         type: 'POST',
52         url: "./Installer/manage",
53         data: {modId: id, modAction: action, mod_enc_menu: modencmenu, mod_nick_name: modnickname},
54         beforeSend: function () {
55             $('.modal').show();
56         },
57         success: function (data) {
58             try {
59                 var data_json = JSON.parse(data);
60                 if (data_json.status.toUpperCase() === "SUCCESS") {
61                     if (data_json.output != undefined && data_json.output.length > 1) {
62                         install_upgrade_log.empty().show().append(data_json.output);
64                         $(".show_hide_log").click(function (event) {
65                             $(event.target).next("div.spoiler").toggle("slow");
66                         });
67                     }
69                     if (parent.left_nav.location) {
70                         parent.left_nav.location.reload();
71                         parent.Title.location.reload();
72                         if (self.name == 'RTop') {
73                             parent.RBot.location.reload();
74                         } else {
75                             parent.RTop.location.reload();
76                         }
77                         top.document.getElementById('fsright').rows = '*,*';
78                     }
79                     if (data_json.output == undefined || data_json.output.length <= 1) {
80                         window.location.reload();
81                     }
82                 } else {
83                     alert(data_json.status);
84                     window.location.reload();
85                 }
86             } catch (e) {
87                 if (e instanceof SyntaxError) {
88                     install_upgrade_log.append(data);
89                 } else {
90                     console.log(e);
91                     install_upgrade_log.append(data);
92                 }
93             }
95         },
96         complete: function () {
97             $('.modal').hide();
98         }
99     });
102 var blockInput = function (element) {
103     $(element).prop('disabled', true);
104     $(element).css("background-color", "#c9c6c6");
105     $(element).closest("a").click(function () {
106         return false;
107     });
110 function configure(id, imgpath) {
111     if ($("#ConfigRow_" + id).css("display") != "none") {
112         $(".config").hide();
113         $("#ConfigRow_" + id).fadeOut();
114     } else {
115         $.post("./Installer/configure", {mod_id: id},
116             function (data) {
117                 $(".config").hide();
118                 $("#ConfigRow_" + id).hide();
119                 $("#ConfigRow_" + id).html('<td colspan="10" style="background-color: var(--light);">' + data + '</td>').fadeIn();
120             }
121         );
122     }
125 function custom_toggle(obj) {
126     if ($("#" + obj).css("display") != "none") {
127         $("#" + obj).fadeOut();
128     } else {
129         $("#" + obj).fadeIn();
130     }
133 function SaveMe(frmId, mod_id) {
134     var SelAccIndTab = $('#configaccord' + mod_id).accordion('getSelected');
135     if (SelAccIndTab)
136         var Acctitle = SelAccIndTab.panel('options').title;
138     var SelTab = $('#tab' + mod_id).tabs('getSelected');
139     if (SelTab)
140         var Tabtitle = SelTab.panel('options').title;
142     if (frmId == 'hooksform') {
143         $.ajax({
144             type: 'POST',
145             url: "./Installer/SaveHooks",
146             data: $('#' + frmId + mod_id).serialize(),
147             success: function (data) {
148                 $.each(data, function (jsonIndex, jsonValue) {
149                     if (jsonValue['return'] == 1) {
150                         $("#hook_response" + mod_id).html(jsonValue['msg']).fadeIn().fadeOut(1000);
151                         $(function () {
152                             if (Tabtitle)
153                                 $('#tab' + mod_id).tabs('select', Tabtitle);
154                         });
155                     }
156                 });
157             }
158         });
159     }
162 function DeleteACL(aclID, user, mod_id, msg) {
163     var SelAccIndTab = $('#configaccord' + mod_id).accordion('getSelected');
164     if (SelAccIndTab)
165         var Acctitle = SelAccIndTab.panel('options').title;
166     if (confirm(msg)) {
167         $.ajax({
168             type: 'POST',
169             url: "./Installer/DeleteAcl",
170             data: {
171                 aclID: aclID,
172                 user: user
173             },
174             success: function (data) {
175                 $.each(data, function (jsonIndex, jsonValue) {
176                     if (jsonValue['return'] == 1) {
177                         $("#ConfigRow_" + mod_id).hide();
178                         configure(mod_id, '');
179                         alert(jsonValue['msg']);
180                         $(function () {
181                             if (Acctitle)
182                                 $('#configaccord' + mod_id).accordion('select', Acctitle);
183                         });
184                     }
185                 });
186             }
187         });
188     }
191 function DeleteHooks(hooksID, mod_id, msg) {
192     var SelTab = $('#tab' + mod_id).tabs('getSelected');
193     if (SelTab)
194         var Tabtitle = SelTab.panel('options').title;
195     if (confirm(msg)) {
196         $.ajax({
197             type: 'POST',
198             url: "./Installer/DeleteHooks",
199             data: {
200                 hooksID: hooksID
201             },
202             success: function (data) {
203                 $.each(data, function (jsonIndex, jsonValue) {
204                     if (jsonValue['return'] == 1) {
205                         $("#ConfigRow_" + mod_id).hide();
206                         configure(mod_id, '');
207                         alert(jsonValue['msg']);
208                         $(function () {
209                             if (Tabtitle)
210                                 $('#tab' + mod_id).tabs('select', Tabtitle);
211                         });
212                     }
213                 });
214             }
215         });
216     }
220  * Save Settings Tab Contents
222  * @param {string} frmId
223  * @param {int} mod_id
224  * @returns {undefined}
225  */
226 function saveConfig(frmId, mod_id) {
227     $.ajax({
228         type: 'POST',
229         url: "./Installer/saveConfig",
230         data: $('#' + frmId + mod_id).serialize(),
231         success: function (data) {
232             var resultTranslated = js_xl('Configuration saved successfully');
233             $('#target' + data.modeId).html(resultTranslated.msg + ' ....').show().fadeOut(4000);
234         }
235     });
239 function validateNickName(modId) {
240     Nickname = $("#mod_nick_name_" + modId).val();
241     if ($.trim(Nickname) != "") {
242         $.ajax({
243             type: 'POST',
244             url: "./Installer/nickName",
245             data: {
246                 nickname: Nickname,
247             },
248             success: function (data) {
249                 if (data != 0) {
250                     $("#mod_nick_name_" + modId).css("background", "#FFB9B5");
251                     $("#mod_nick_name_message_" + modId).html("* Duplicate Nick Name");
252                 } else {
253                     $("#mod_nick_name_" + modId).css("background", "");
254                     $("#mod_nick_name_message_" + modId).html("");
255                 }
256             },
257             error: function () {
258                 alert("Ajax Error");
259             }
260         });
261     } else {
262         $("#mod_nick_name_" + modId).css("background", "");
263         $("#mod_nick_name_message_" + modId).html("");
264     }