xo::api proc debug_widget (public)
xo::api debug_widget proc_spec
Defined in packages/xotcl-core/tcl/01-debug-procs.tcl
Return HTML code for a debug switch that lets an admin turn debugging of functions and methods on and off. This functionality is only allowed to site-wide admins.
- Parameters:
- proc_spec (required)
- Testcases:
- No testcase defined.
Source code: # # Return HTML code for a debug switch that lets an admin turn # debugging of functions and methods on and off. This # functionality is only allowed to site-wide admins. # if {![acs_user::site_wide_admin_p] || [info commands ::nsf::method::property] eq "" || $::nsf::version < 2.1 } { return "" } switch [llength $proc_spec] { 1 {lassign [list "" ::nx::Object nsfproc $proc_spec] scope obj methodType method if {![string match ::* $method]} { set method ::$method } # # In case $proc_spec is a cmd, it has to be a nsfproc # if {[nsf::cmd::info type $method] ne "nsfproc"} { return "" } } 2 {lassign $proc_spec methodType obj; set scope ""} 3 {lassign $proc_spec obj methodType method; set scope ""} 4 {lassign $proc_spec scope obj methodType method} default { ns_log notice "[self] debug_widget: Unexpected format <$proc_spec> consists of [llength $proc_spec] parts" return "" } } if {$methodType eq "proc"} { set modifier "-per-object" } elseif {$methodType in {instproc nsfproc}} { set modifier "" } elseif {$methodType in {Class Object}} { return "" } else { ns_log warning "[self] debug_widget unexpected method type <$methodType>" set modifier "" } set isObject [:scope_eval $scope ::nsf::is object $obj] if {!$isObject} { return "" } set debug_p [:scope_eval $scope ::nsf::method::property $obj {*}$modifier $method debug] # # Increment global form_id # set form_id "form-[incr ::__form_id]" # # Add the JavaScript function only once, which will toggle the # debug state in the background (template::add_script would add # it multiple times). # if {$::__form_id eq "1"} { template::add_body_script -script { function ajax_submit(form) { var xhr = new XMLHttpRequest(); xhr.open('POST', '/xotcl/admin/toggle-debug', true); xhr.onreadystatechange = function() { if (this.readyState == 4) { if (this.status != 200) { alert('AJAX submit unexpected response: ' + this.status); } } } xhr.send(new FormData(form)); }; } } # # Add the required js and CSS. We use here bootstrap + titatoggle, # and assume, we have bootstrap3 installed # #template::head::add_css -href urn:ad:css:bootstrap3 #template::head::add_javascript -src urn:ad:js:bootstrap3 template::head::add_css -href "/resources/xotcl-core/titatoggle/titatoggle-dist.css" # # Return an HTML snippet with a form and the computed form-ID # if {$debug_p} {set state checked} {set state ""} set html [subst { <form id="$form_id" class="form" method="POST" action="/xotcl/admin/toggle-debug"> <div class="checkbox checkbox-slider--b-flat"> <label class="checkbox-inline"> <input class="debug form-control" id="$form_id-control" name="debug" type="checkbox" $state><span>Debug</span> <input name="proc_spec" type="hidden" value="$proc_spec"> <input name="return_url" type="hidden" value="[ns_quotehtml [ad_return_url]]"> </label> </div> </form> }] template::add_body_script -script [subst { document.getElementById('$form_id-control').addEventListener('click', function (event) { ajax_submit(this.form); }); }] return $htmlXQL Not present: Generic, PostgreSQL, Oracle