Elxis CMS Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Elxis 4.x documentation for users and developers
 
Pages: [1]
  Print  
Author Topic: Connecting component back-end toolbar buttons with respective tasks  (Read 966 times)
jmous
Newbie
*
Offline Offline

Posts: 10



« on: March 20, 2012, 14:06:00 »

Hello all,
After reading the  Elxis Component Development Guide i still need help on how the tasks in the administrative part actually work.

I guess i need a little more on that (page 23) :
"When you click a button a JavaScript function is being executed that fills-in our form’s “task” input text
with the button’s task and submits the form. The tasks are “save” for the Save button and “cancel” for the Cancel button."

Suppose i need two forms and both forms load the same toolbar (cancel and save)
the first form is loaded when task=config
the second form is loaded when task=new
When the html part posts the form following a config\save or a new\save, what's the idea of understanding which save was pressed and continue with the appropriate function execution in the component's main class?

Thank you in advance
 
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7682



WWW
« Reply #1 on: March 20, 2012, 19:36:54 »

Why you need 2 forms? This is crazy!
All edit pages consist by 1 form. The form should contain a hidden field named "task".
<input type="hidden" name="task" value="" />

When you click on a button having task "test", Elxis fills in the hidden field with this value and then submits the form.
<input type="hidden" name="task" value="test" />
In your main component file (admin.xxx.php) you should add a routing for this task:
if ($task == 'test') {
   doSomething();
}
Logged

jmous
Newbie
*
Offline Offline

Posts: 10



« Reply #2 on: March 20, 2012, 23:55:31 »

Thanks, maybe i wasn't clear enough
In my example the control panel has two options (links).
One link to the component's configuration page(link to page task=config)
One link to the component's add new item page (link to page task=new)
Both these pages (and not forms as i mistook before) load a save-cancel toolbar
If i understood well, when i press save in the configuration page the task executed in admin.xxx.php is
if($task=='save'){
 save configuration options to file
}
Now i am back in the control panel and move to the add new item page. Fill in the form and press save.
Do i need to override the value of the save button to something like  "save_item" so that in the admin.xxx.php
if($task=='save_item'){
 do something else
}

Or should i add an other hidden field (name='option') noting which page sent me the 'save' task
and in admin.xxx.php :
if($task=='save'){
     if($option=='config'){ do smthing}
     if($option=='new'){ do smthing else}
}
If what i am asking doesn't make sense maybe i am missing something more basic. 
Logged
apkoutsou
Sr. Member
****
Offline Offline

Posts: 326


WWW
« Reply #3 on: March 21, 2012, 12:42:27 »

There is a lot yet to do. The toolbar is controlled by zzz.toolbar.php and zzz.toolbar.html.php files. Study those two files. When you add a new toolbar item you set the task variable that will fill the hidden task input when form submitted. So you do not have to create a new input.

So you have to code:

if($task=='save'){
  // do something
} elseif($task=='save'){
   // do something
}elseif($option=='new'){
  // do something
}

Logged

LawyersVoice.gr - Το forum των νέων δικηγόρων
jmous
Newbie
*
Offline Offline

Posts: 10



« Reply #4 on: March 21, 2012, 13:23:14 »

Thanx a lot!
I just checked the toolbar files in some elxis core components and I guess what i need partly lies there.
I will study those and I am confident that I will figure out the rest.

PS: there is something i don't get in your code ( ???checking the condition $task='save' twice) - Not important as you gave me the right direction.
Logged
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7682



WWW
« Reply #5 on: March 21, 2012, 19:08:03 »

Use different task names for different edit pages.

Example:
mosMenuBar::save(); //no task specified, the default "save" task will be applied
mosMenuBar::save('savearticle'); //task = savearticle
mosMenuBar::save('savecategory'); //task = savecategory
mosMenuBar::save('save_the_planet'); //task = save_the_planet

Here is a fully custom save button:
mosMenuBar::customX('saveitem', 'save.png', 'save_f2.png', $adminLanguage->A_SAVE, true ); //task = saveitem

Catch the current task and proceed to the requested action (file admin.xxx.php) :

Code:
<?php 
$task 
mosGetParam($_REQUEST'task''');
switch (
$task) {
   case 
'save'doSave(); break;
   case 
'savearticle'doSaveArticle(); break;
   case 
'savecategory'doSaveCategory(); break;
   case 
'save_the_planet'doSaveThePlanet(); break;
   case 
'saveitem'saveItemPlease(); break;
   default: 
pageNotFound(); break;
}
?>

Informational note for Elxis 4.0 Nautilus:
Elxis 4.0 does not uses option and task variables. It does not even use any POST/GET variables!
Elxis Nautilus routes the user request by analysing the URI segments.

I paste a part of the routing procedure of component Search

Code:
<?php 
private function makeRoute() {
$c count($this->segments);
if ($c == 0) { return; }
if ($c 1) {
exitPage::make('404''CSEA-0003');
}

if ($this->segments[0] == 'osdescription.xml') {
$this->controller 'open';
$this->task 'osDescription';
return;
}

$eng strtolower(str_ireplace('.html'''$this->segments[0]));
$eng filter_var($engFILTER_SANITIZE_STRINGFILTER_FLAG_STRIP_LOW FILTER_FLAG_STRIP_HIGH);
if ($eng != '') { $this->engine $eng; }
}

?>

And here is a sample on how you create buttons in Elxis Nautilus (no special file is required - buttons are generated on runtime)
Code:
<?php 
$toolbar 
$elxis->obj('toolbar');
$toolbar->add($eLang->get('SAVE'), 'save'false'''elxSubmit(\'save\');');
$toolbar->add($eLang->get('APPLY'), 'saveedit'false'''elxSubmit(\'apply\');');
$toolbar->add($eLang->get('CANCEL'), 'cancel'false$elxis->makeAURL('content:categories/'));
?>
« Last Edit: March 21, 2012, 19:31:54 by datahell » Logged

apkoutsou
Sr. Member
****
Offline Offline

Posts: 326


WWW
« Reply #6 on: March 21, 2012, 20:17:58 »

mosMenuBar::save('save_the_planet'); //task = save_the_planet

ROLF!!!!!

Anyway, it is always nice to have a sneak peek to Nautilus' functionallity... As everybody else here, I'm looking forward to the new version..!!
Logged

LawyersVoice.gr - Το forum των νέων δικηγόρων
datahell
Elxis Team
Hero Member
*****
Offline Offline

Posts: 7682



WWW
« Reply #7 on: March 21, 2012, 22:24:43 »

For those interested I publish my work on Elxis 4.0 on my Twitter.
Logged

jmous
Newbie
*
Offline Offline

Posts: 10



« Reply #8 on: March 22, 2012, 10:40:52 »

Thanks! Exactly what i needed to save (my) world!
Logged
Pages: [1]
  Print  
 
Jump to: