Hi Jeremy!
Also NL of BE ? ;-)
Anyhow. Great help!
I implemented your code. But I faced another problem:
Because of $ajax->submit() my dhtmlTree isn't draggable anymore. It's
just printed out link the HTML tree.
If I push the "save" button it does nothing (maybe because of the
dhtmlTree problem).
Maybe you had this problem too?
Thanks in advance!
Grtz,
Tim
On Jun 21, 4:59 pm, Jeremy David Pointer <[EMAIL PROTECTED]> wrote:
> I'm not sure I'm getting to where your problem actually is because you
> haven't told us what is or is not happening.
> But.......
> 0. I'm using Cake 1.2 so some things might be different
> 1. I don't see why you would want to redraw the tree, when I do this I
> set up a div below the tree that's a simple 'Updated' view rendered into
> it after the save completes. i.e. don't update the div with the tree in
> it but rather another div to indicate whether the save was successful or
> not.
> 1a. If you really want to redraw the tree the place to do it would be in
> the 'save' view (which you haven't included)
>
> 2. I see the ajax is supposed to submit with an interval which could
> work but you seem to be missing a 'before' option in the $ajax->submit
> that would call your saveMyTree_byForm(), it's just my preference but I
> tend to use a combination of onkeypress/onmouseout of the tree div to
> update the hidden field and only submit the form when a save button is
> pressed since the save button is outside the div the hidden field will
> be updated before the button is clicked, the onkeypress is in case the
> keyboard is used to submit i.e. the enter key. In this way I'm not
> unecessarily repeatedly posting to the server.
>
> So in the view:
> <div ......
> onmouseout="document.getElementById('ModuleSavestring').value=treeObj<?=$uniq;?>.getSaveString();"
> onkeypress=(same as above)..... >The tree</div>
> <div id="updateTree"></div>
> <input type="hidden" value="" id="ModuleSavestring"
> name="data[Savestring]" />
> <?php echo $ajax->submit('Save
> Tree',array("update"=>"updateTree".$uniq,"url"=>"updateTree")); ?>
>
> 3. Maybe I'm being dof (Afrikaans word for dim) but in my controller
> side save method I parse the variable containing the hidden field and
> save the items one by one ala
> (this example only works to two levels of the menu):
>
> 4. For interest sake my initial menu is populated by
> model->findAllThreaded()
>
> function updateTree() {
> if (!empty($this->data)) {
> $nodes=split(',',$this->data['Savestring']);
> $vals=array();
> foreach($nodes as $val) {
> $vals[]=split('-',$val);
> }
> $modids=$this->data['Module'];
> $modids[0]=0;
> $modules=array();
> foreach($vals as $order=>$record) {
> $modules[$order]['Module']['id']=$modids[$record[0]];
> $modules[$order]['Module']['parent_id']=$modids[$record[1]];
> $modules[$order]['Module']['order']=$order;
> }
> $this->data['Module']=$modules;
> foreach($modules as $module) $this->Module->save($module);
> $this->render('updatetree');
> }
> }
>
> HTH
> Jeremy
>
> nosowrote:
> > Hi everybody!
>
> > I have a problem with posting a form.
> > I use the tree Ajax component of DhtmlGoodies (http://
> >www.dhtmlgoodies.com/scripts/drag-drop-folder-tree/drag-drop-folder-t...)
> > and I want to save it's structureString to the database. The problem
> > is that it uses a javascript code to fill the hidden field in the
> > form.
>
> > ================================================================
> > <!-- edit.thtml -->
> > ================================================================
> > <div id="menuTree_edit">
> > <ul id="menuTreeContainer" class="DHTMLSuite_tree">
> > <li id="node_10000" noDrag="true"><a href="#">MenuBar</a>
> > <ul>
> > #### TREE STRUCTURE ####
> > </ul>
> > </li>
> > </ul>
> > </div>
>
> > <?= $ajax->form(array('action'=>$html->url('save')));?>
> > <?= $html->hidden('menu_builder/saveString', array('id' =>
> > 'saveString', 'value' => 'none', 'size' => '40')) ?>
> > <?= $ajax->submit('save tree',array('url'=>'save',
> > 'update'=>'menuTree_edit', 'frequency'=>'2')); ?>
>
> > function saveMyTree_byForm()
> > {
> > document.myForm.elements['saveString'].value =
> > treeObj.getSaveString();
> > document.myForm.submit();
> > }
>
> > ================================================================
>
> > ok then I have my controllerclass
>
> > ================================================================
> > <!-- menu_builder_controller.php -->
> > ================================================================
> > class MenuBuilderController extends AppController {
> > var $name = 'MenuBuilder';
> > var $helpers = array('Html', 'Javascript', 'Ajax');
> > //var $components = array('RequestHandler');
>
> > var $myMenuItems = array();
> > var $TreeData=array();
>
> > function index()
> > {
> > $this->myMenuItems = $this->MenuBuilder->findAll();
>
> > $this->set('menubuilder', $this->myMenuItems);
> > if(isset($this->params['requested'])) {
> > return $this->myMenuItems;
> > }
> > }
>
> > function edit(){
> > $this->myMenuItems = $this->MenuBuilder->findAll();
> > $this->set('menubuilder', $this->myMenuItems);
> > }
>
> > function save(){
> > $success = true;
> > $succesMessage = 'Menu update successfully';
> > if (empty($this->data)){
> > $success = false;
> > $errorMessage = "Error in menu updating - no
> > data";
> > }else{
> > ### some building code ##
> > $this->MenuBuilder-
>
> >> save(array('MenuBuilder' => $this->params['data']['item']
>
> > ['MenuBuilder']));
>
> > }
> > $this->render('save', 'ajax');
> > }
>
> > ================================================================
>
> > Can somebody tell me how I post my form with the saveString with Ajax
> > and refresh the result in the edit.thtml menuTree_edit-div. So if I
> > click save the data is saved and my tree-view updates in the right
> > region of the screen.
>
> > Thanks in advance!
> > Greetings to you all!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---