forked from websavers/WHMCS-admin-tab-creator-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusyrack_admin_tabs.js
59 lines (54 loc) · 1.91 KB
/
busyrack_admin_tabs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function br_updateCounter(tableid) {
var counter = $(tableid + "tbody tr:not(.none)").length;
$(".br_counter").text("(" + counter + ")");
}
// Adds the tab to the page
function br_injectTab(name, pagename, position) {
var css_name = name.replace(" ", "_");
var error = false;
if ($("ul[role='tablist']").length > 0) {
$("ul[role='tablist'] li:nth-child(" + position + ")").before(
'<li><a href="#' + css_name + '_content" id="' + css_name + '" role="tab" data-toggle="tab">'+ name + '</a></li>'
);
} else {
error = true;
}
if (pagename.includes("clients")){
target = '.tab-content.client-tabs';
}
else if (pagename == 'supporttickets'){
target = '.tab-content.admin-tabs';
}
else{ target = null; }
if ($(target).length > 0) {
$(target).append( // WHMCS 6+ blend template
'<div class="tab-pane" id="' + css_name + '_content"><div id="tab_content"><i class="fas fa-spinner fa-spin"></i> Loading...</div></div>'
);
} else {
error = true;
}
if (error) console.error('busyrack_admin_tabs.js: unsupported admin template.');
}
// Shows the tab content
function br_loadBZTab(module_name,target,type,offset,callback) {
location.hash = '#'+target;
$.post("addonmodules.php?module=" + module_name + "&action="+type, {
action: type,
id: refid,
userid: userid,
target: target,
offset: offset
}).done(function(data){
if ($('#' + target + " #tab_content").length > 0) {
$('#' + target + " #tab_content").html(data);
} else if ($("#tab"+target+"box #tab_content").length > 0) {
$("#tab"+target+"box #tab_content").html(data);
}
callback(data);
}).fail(function(error){
console.log(error.responseText);
if ($('#' + target + " #tab_content").length > 0) {
$('#' + target + " #tab_content").html(error.responseText);
}
});
}