Web based family history software

Question Context help visibility

  • mlocati
  • Topic Author
  • Visitor
  • Visitor
14 years 6 months ago #1 by mlocati
Context help visibility was created by mlocati
It would be wonderful if the ? contextual help could be shown/hidden directly in javascript, without the need to reload the page.

This way, the current status of the page could be maintained (current data shown, fields manually set and for which users may need help, ...)

Technically, this could be implemented by assigning a css class to the question marks, and a javascript function could look for all the tags with that class and make them visible/hidden (node.style.display="inline/none" or node.style.visibility="visible/hidden").

That script could also set a cookie, so that any other pages could maintain the question marks visibility... I'm thinking in particular to the sub-windows opened by the main window (for example the edit_interface.php?action=add&fact=RESI&pid=I1) for whom at the moment there's no possibility to view context help.

--
Michele

Please Log in or Create an account to join the conversation.

More
14 years 6 months ago #2 by fisharebest
Replied by fisharebest on topic Re: Context help visibility
IIRC, the help icons already have a css class of "help".

Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

  • mlocati
  • Topic Author
  • Visitor
  • Visitor
14 years 6 months ago #3 by mlocati
Replied by mlocati on topic Re: Context help visibility
Here I am with some code to show/hide contextual help links without the need to refresh the pages.
In the attached zip you can find the files I modified (based on webtrees-8359).


I've placed the javascript code that manage the visibility of help links (and the text of the Help menu) at the end of /js/webtrees.js, since this script is included by the function print_header of /includes/functions/functions_print.php (and I'm pretty sure it's always called in every page where there's the Help menu).


When the visibility is toggled, we need to set the $_SESSION variable, so that the visibility is maintained in subsequent pages (and sub-windows like the "Add fact to individual"). So the javascript function I inserted in the /js/webtrees.js calls, via am XMLHttpRequest object, a page on the server which sets that session variable. This is the new php script that I called /set_session_variable.php.
Since the show_context_help session variable is set automatically by the file /includes/session.php, that page simply includes this file.


Looking at that /includes/session.php file, I found some code that is really unclear to me:
Code:
$show_context_help = ''; if (!empty($_REQUEST['show_context_help'])) $show_context_help = $_REQUEST['show_context_help']; if (!isset($_SESSION['show_context_help'])) $_SESSION['show_context_help'] = $SHOW_CONTEXT_HELP; if (isset($SHOW_CONTEXT_HELP) && $show_context_help==='yes') $_SESSION['show_context_help'] = true; if (isset($SHOW_CONTEXT_HELP) && $show_context_help==='no') $_SESSION['show_context_help'] = false;
This code sets the session variable to the value received by the $_REQUEST only if the $SHOW_CONTEXT_HELP value is set.
Why? I don't understand... If I'm missing something please let me know, but I think this code is better:
Code:
switch (empty($_REQUEST['show_context_help']) ? '' : $_REQUEST['show_context_help']) { case 'yes': $_SESSION['show_context_help'] = true; break; case 'no': $_SESSION['show_context_help'] = false; break; default: if (!isset($_SESSION['show_context_help'])) $_SESSION['show_context_help'] = isset($SHOW_CONTEXT_HELP) ? $SHOW_CONTEXT_HELP : true; }

I then modified the file /includes/functions/functions_print.php to always print contextual help links, setting their visibility to 'hidden' when the $_SESSION variable is set to false.

And finally I modified the /includes/classes/class_menubar.php to change the contextual items of the Help menu.
The menu contains one item, with two span: 'Show contextual help' and 'Hide contextual help'. One of them is initially visible (depending on the $_SESSION variable); their visibility is switched by the javascript function I included in the /js/webtrees.js file.
This should be fine, except the case when tge Help menu is rendered with the getMenuAsDropdown method: the two spans are not suitable for this case. I don't know if the getMenuAsDropdown method could be called in some circustance... For now it seems to me it's not.

Ciao!
Michele

File Attachment:

File Name: webtrees_8...hele.zip
File Size:51 KB

Please Log in or Create an account to join the conversation.

More
14 years 6 months ago #4 by kiwi
Replied by kiwi on topic Re: Context help visibility

This should be fine, except the case when tge Help menu is rendered with the getMenuAsDropdown method: the two spans are not suitable for this case. I don't know if the getMenuAsDropdown method could be called in some circumstance... For now it seems to me it's not.

I think you are right, for now its not used anywhere for Help. That function IS used in some themes for other menu items though. At the very least you would need to add a comment in the code warning that it can no longer be used for Help. Those alternative menu display functions exist to allow users to customise their menus in many different ways. Someone might want to use it for Help in the future.

But I have a bigger question - Why does Help need a show/hide option at all? Can't we just make it permanently on show? Its not a large icon, so why bother hiding it? There has been a very old bug with it in PGV, I'd hate to introduce any more complications. Keep it simple.

Please Log in or Create an account to join the conversation.

  • mlocati
  • Topic Author
  • Visitor
  • Visitor
14 years 6 months ago #5 by mlocati
Replied by mlocati on topic Re: Context help visibility
kiwi wrote:

I think you are right, for now its not used anywhere for Help. That function IS used in some themes for other menu items though. At the very least you would need to add a comment in the code warning that it can no longer be used for Help. Those alternative menu display functions exist to allow users to customise their menus in many different ways. Someone might want to use it for Help in the future.

There's another solution: adding a new parameter to the Menu class constructor, le'ts say $optionLabel, letting the themes to specify the label to use when rendering the menu as a select. This new parameter could have a default value of null meaning that we can use the usual $label. So, for contextual menu item, we could have the two spans in <li> items, and a text like "switch context help" in <option> items.

kiwi wrote:

But I have a bigger question - Why does Help need a show/hide option at all? Can't we just make it permanently on show? Its not a large icon, so why bother hiding it?

I don't think I'm the right person to answer this kind of questions. I've been using pgv just as a casual user (also because of it poor Italian translation), so my opinions are not the best ones we can have.

kiwi wrote:

Keep it simple.

I agree with you: this should be always be kept in mind when writing any piece of code... Better 10 clear lines of code than just one but cryptic.

Please Log in or Create an account to join the conversation.

  • mlocati
  • Topic Author
  • Visitor
  • Visitor
14 years 6 months ago #6 by mlocati
Replied by mlocati on topic Re: Context help visibility
And here's the code that show an implementation of what I meant, based on webtrees-8386.

I changed the "webtrees" theme to test the help menu rendered as a <select>.

The new context menu works a charm... Furthermore, other menu items (which I didn't touched) don't work.
Looking at the code, I see that the options have a value of "#", so the script associated to the <select> does this:
document.location="#".
Instead, the item I added has a value of "javascript:switchContextHelp(true)", so the <select> script does this:
document.location="javascript:switchContextHelp(true)".
This syntax is very strange, I've never seen such things, but it works (tested under Firefox, Chrome, IE8, Safari, Opera)...
Thinking a bit about it, anyway, doing something like
document.location="javascript:DoSomething()"
is like pressing this link
<a href="javascript:DoSomething()">...</a>
So it's normal that the <select> script works... Today too I've learned a new thing (which anyway I don't think I'll use ;) )

File Attachment:

File Name: webtrees_8...hele.zip
File Size:33 KB

Please Log in or Create an account to join the conversation.

  • ToyGuy
  • Offline
  • Moderator
  • Moderator
  • Live like it's Christmas every day - Santa Stephen
More
14 years 6 months ago #7 by ToyGuy
Replied by ToyGuy on topic Re: Context help visibility
Any day we learn something new is a good day. Chances are, if we didn't learn something new, we're probably six-feet under and I, for one, don't relish that option.

Thanks for your polite and succinct posts which also educate the rest of it.
-Stephen

Santa Stephen the Fabled Santa
Latest webtrees at MyArnolds.com
Hosted by webtreesonline.com , a division of GeneHosts LLC
MacOS 10.6.8, Apache 2.2+, PHP 5.4.16, MySQL 5.5.28

Please Log in or Create an account to join the conversation.

More
14 years 6 months ago #8 by WGroleau
Replied by WGroleau on topic Re: Context help visibility

But I have a bigger question - Why does Help need a show/hide option at all? Can't we just make it permanently on show? Its not a large icon, so why bother hiding it? There has been a very old bug with it in PGV, I'd hate to introduce any more complications.

I agree; simplify. If someone finds the icon too big, they can make a smaller one for their theme.

--
Wes Groleau
UniGen.us/

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum