From 2885115ed8b6017f405451ea17d0914699f46f8e Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Mon, 28 Nov 2022 14:56:52 -0700 Subject: [PATCH] Live on demand domain search. --- themes/default/template.php | 161 +++++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 66 deletions(-) diff --git a/themes/default/template.php b/themes/default/template.php index a44583b113..1c573f3b51 100644 --- a/themes/default/template.php +++ b/themes/default/template.php @@ -298,6 +298,8 @@ $('#domains_hide').on('click', function() { hide_domains(); }); function show_domains() { + search_domains('domains_list'); + $('#domains_visible').val(1); var scrollbar_width = (window.innerWidth - $(window).width()); //gold: only solution that worked with body { overflow:auto } (add -ms-overflow-style: scrollbar; to style for ie 10+) if (scrollbar_width > 0) { @@ -308,7 +310,7 @@ $(document).scrollTop(0); $('#domains_container').show(); $('#domains_block').animate({marginRight: '+=300'}, 400, function() { - $('#domains_filter').trigger('focus'); + $('#domains_search').trigger('focus'); }); } @@ -316,8 +318,7 @@ $('#domains_visible').val(0); $(document).ready(function() { $('#domains_block').animate({marginRight: '-=300'}, 400, function() { - $('#domains_filter').val(''); - domain_search($('#domains_filter').val()); + $('#domains_search').val(''); $('.navbar').css('margin-right','0'); //restore navbar margin $('#domains_container').css('right','0'); //domain container right position $('#domains_container').hide(); @@ -556,7 +557,6 @@ }); {/literal} - //link list rows {literal} $('.tr_hover tr,.list tr').each(function(i,e) { @@ -1017,6 +1017,94 @@ {*//session timer *} {$session_timer} + {*//domain selector *} + function search_domains(element_id) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + //if (this.readyState == 4 && this.status == 200) { + // document.getElementById(element_id).innerHTML = this.responseText; + //} + + //remove current options + document.getElementById(element_id).innerHTML = ''; + + if (this.readyState == 4 && this.status == 200) { + + //create the json object from the response + obj = JSON.parse(this.responseText); + + //update the domain count + document.getElementById('domain_count').innerText = '('+ obj.length +')'; + + //add new options from the json results + for (var i=0; i < obj.length; i++) { + + //get the variables + domain_uuid = obj[i].domain_uuid; + domain_name = obj[i].domain_name; + if (obj[i].domain_description != null) { + // domain_description = DOMPurify.sanitize(obj[i].domain_description); + } + + //create a div element + var div = document.createElement('div'); + + //add a div title + div.title = obj[i].domain_name; + + //add a css class + div.classList.add("domains_list_item"); + + //alternate the background color + if(i%2==0) { + div.style.background = '{$domain_selector_background_color_1}'; + } + else { + div.style.background = '{$domain_selector_background_color_2}'; + } + + //set the active domain style + if ('{$domain_uuid}' == obj[i].domain_uuid) { + div.style.background = '{$domain_active_background_color}'; + div.style.fontWeight = 'bold'; + //div.classList.add("domains_list_item_active"); + //var item_description_class = 'domain_active_list_item_description'; + } + else { + //div.classList.add("domains_list_item_inactive"); + //var item_description_class = 'domain_inactive_list_item_description'; + } + + link_label = obj[i].domain_name; + if (obj[i].domain_description != null) { + link_label += ' - ' + obj[i].domain_description; + } + var a_tag = document.createElement('a'); + a_tag.setAttribute('href','{$domains_app_path}?domain_uuid='+obj[i].domain_uuid+'&domain_change=true'); + a_tag.innerText = link_label; + div.appendChild(a_tag); + + //div.innerHTML = ''+obj[i].domain_name+' '; + //if (obj[i].domain_description != null) { + // div.innerHTML += ' - '+obj[i].domain_description+''; + //} + + document.getElementById(element_id).appendChild(div); + } + } + }; + search = document.getElementById('domains_search'); + if (search.value) { + //xhttp.open("GET", "/core/domains/domain_list.php?search="+search.value, true); + xhttp.open("GET", "/core/domains/domain_json.php?search="+search.value, true); + } + else { + //xhttp.open("GET", "/core/domains/domain_list.php", true); + xhttp.open("GET", "/core/domains/domain_json.php", true); + } + xhttp.send(); + } + {*//domain selector *} @@ -1033,70 +1121,11 @@
-
- {foreach $domains as $row} - {if $row.domain_enabled} - {*//alternate background colors of inactive domains *} - {if $background_color == $domain_selector_background_color_1} - {$background_color=$domain_selector_background_color_2} - {else} - {$background_color=$domain_selector_background_color_1} - {/if} - {*//set active domain color *} - {if $domain_active_background_color != ''} - {if $row.domain_uuid == $domain_uuid}{$background_color=$domain_active_background_color}{/if} - {/if} - {*//active domain text hover color *} - {if $settings.theme.domain_active_text_color_hover != '' && $row.domain_uuid == $domain_uuid} -
- {elseif $settings.theme.domain_inactive_text_color_hover != '' && $row.domain_uuid != $domain_uuid} -
- {else} -
- {/if} - {*//domain link *} - {$row.domain_name} - {*//domain description *} - {if $row.domain_description != ''} - {*//active domain description text color *} - {if $settings.theme.domain_active_desc_text_color != '' && $row.domain_uuid == $domain_uuid} - - {$row.domain_description} - {*//inactive domains description text color *} - {elseif $settings.theme.domain_inactive_desc_text_color != '' && $row.domain_uuid != $domain_uuid} - - {$row.domain_description} - {*//default domain description text color *} - {else} - - {$row.domain_description} - {/if} - {/if} -
- {$ary_domain_names[]=$row.domain_name} - {$ary_domain_descs[]=$row.domain_description|replace:'"':'\"'} - {/if} - {/foreach} -
- - - +