Ferreteria/v0.5/menu: Difference between revisions
< Ferreteria | v0.5
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
Menus in Ferreteria are static HTML which use URL data to convey state-changes. Many of the same classes and code are also used for isolated action-links which can be placed anywhere on a page, as appropriate (e.g. "[recalculate]", "[void]"). | Menus in Ferreteria are static HTML which use URL data to convey state-changes. Many of the same classes and code are also used for isolated action-links which can be placed anywhere on a page, as appropriate (e.g. "[recalculate]", "[void]"). | ||
==Changes from v0.4== | ==Changes from v0.4== | ||
The code for adding a menu entry to a section-header used to look like this: | The code for adding a menu entry to a section-header used to look like this: | ||
<syntaxhighlight lang=php> | <syntaxhighlight lang=php> | ||
Line 30: | Line 28: | ||
$oGrp->SetNode($ol); | $oGrp->SetNode($ol); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The v0.5 methodology looks like this: | The v0.5 methodology (not yet tested, so it may end up being revised further) looks like this: | ||
<syntaxhighlight lang=php> | <syntaxhighlight lang=php> | ||
$oMenu = caApp::Me()->GetHeaderMenu(); | $oMenu = caApp::Me()->GetHeaderMenu(); | ||
// create & configure settings for "[add] => create new permission" menu item | // create & configure settings for "[add] => create new permission" menu item | ||
$ol = new \ | $ol = new F\cMenuOptionLink; | ||
$oa = $ol->GetArgPod(); | $oa = $ol->GetArgPod(); | ||
$oa->BasePath()->SetIt($this->LinkURL()); // base URL to prefix all output URLs | $oa->BasePath()->SetIt($this->LinkURL()); // base URL to prefix all output URLs | ||
Line 44: | Line 42: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Changes: | Changes: | ||
* <code>fcMenuOptionLink</code> has been renamed <code>ferret\cMenuOptionLink</code>. | |||
* We now create the MenuOptionLink object directly, rather than spawning it using a static function. | * We now create the MenuOptionLink object directly, rather than spawning it using a static function. | ||
* The function name for adding the Link to a parent object has changed from SetNode() to AddTwig(). | * The function name for adding the Link to a parent object has changed from SetNode() to AddTwig(). | ||
Line 68: | Line 67: | ||
<syntaxhighlight lang=php> | <syntaxhighlight lang=php> | ||
$oMenu = cApp::Me()->GetHeaderMenu(); | $oMenu = cApp::Me()->GetHeaderMenu(); | ||
$ol = new \ | $ol = new F\cMenuOptionLink; | ||
$oa = $ol->GetArgPod(); | $oa = $ol->GetArgPod(); | ||
$oa->BasePath()->SetIt($this->LinkURL()); | $oa->BasePath()->SetIt($this->LinkURL()); |
Revision as of 00:43, 20 May 2022
About
Menus in Ferreteria are static HTML which use URL data to convey state-changes. Many of the same classes and code are also used for isolated action-links which can be placed anywhere on a page, as appropriate (e.g. "[recalculate]", "[void]").
Changes from v0.4
The code for adding a menu entry to a section-header used to look like this:
$oag = \fcHeaderMenuGroup::CreateCollection();
$oag->ChoiceKey()->SetIt('do');
$oag->BasePath()->SetIt($urlSelf);
// create & configure settings for "edit" menu item
$oa = \fcMenuOptionLink::CreateCollection();
$oag->CopyValuesTo($oa);
$oa->ChoiceValue()->SetIt('edit');
$oa->Popup()->SetIt('edit this invoice');
// create edit menu item object
$ol = new \fcMenuOptionLink($oa);
// add it to the menu group
$oGrp->SetNode($ol);
// create & configure settings for "empty the invoice" menu item
$oa = \fcMenuOptionLink::CreateCollection();
$oag->CopyValuesTo($oa);
$oa->ChoiceValue()->SetIt('empty');
$oa->Popup()->SetIt('remove all lines from this invoice');
// create edit menu item object
$ol = new \fcMenuOptionLink($oa);
// add it to the menu group
$oGrp->SetNode($ol);
The v0.5 methodology (not yet tested, so it may end up being revised further) looks like this:
$oMenu = caApp::Me()->GetHeaderMenu();
// create & configure settings for "[add] => create new permission" menu item
$ol = new F\cMenuOptionLink;
$oa = $ol->GetArgPod();
$oa->BasePath()->SetIt($this->LinkURL()); // base URL to prefix all output URLs
$oa->ChoiceKey()->SetIt('do'); // name of option group to which this option belongs
$oa->ChoiceValue()->SetIt('add'); // value of key for this action
$oa->Popup()->SetIt('create new permission'); // (optional) hover-over text
$doAdd = $ol->GetIsSelected();
$oMenu->AddTwig($ol);
Changes:
fcMenuOptionLink
has been renamedferret\cMenuOptionLink
.- We now create the MenuOptionLink object directly, rather than spawning it using a static function.
- The function name for adding the Link to a parent object has changed from SetNode() to AddTwig().
- In the v0.4 example, the parent is a Group object; in the v0.5 example, it's a HeaderMenu object.
Another example, using the same code being converted from v0.4 to v0.5.
v0.4:
// "edit" menu only appears if we're not adding
$oMenu = cApp::Me()->GetHeaderMenu();
$oa = \fcMenuOptionLink::CreateCollection();
$oa->BasePath()->SetIt($this->LinkURL());
$oa->ChoiceKey()->SetIt('do');
$oa->ChoiceValue()->SetIt('edit');
$oa->Popup()->SetIt('edit this project');
$ol = new \fcMenuOptionLink($oa);
$doEdit = $ol->GetIsSelected();
$oMenu->SetNode($ol);
v0.5:
$oMenu = cApp::Me()->GetHeaderMenu();
$ol = new F\cMenuOptionLink;
$oa = $ol->GetArgPod();
$oa->BasePath()->SetIt($this->LinkURL());
$oa->ChoiceKey()->SetIt('do');
$oa->ChoiceValue()->SetIt('edit');
$oa->Popup()->SetIt('edit this project');
$doEdit = $ol->GetIsSelected();
$oMenu->AddTwig($ol);