Here is sortable_row.php:

<?php

class SortableRowHelper Extends AppHelper {

        var $rowNum = 1;

        var $tags = array(
                'tablebodystart'                => '<tbody id="%s" %s>%s',
                'tablebodyend'                  => '</tbody>',
                'tablerowstart'                 => '<tr id="%sRow_%s" 
class="%s">%s',
                'tablerowend'                   => '</tr>'
        );

        function insert($name, $text = null, $options = array()) {
                $alt = null;
                if (is_array($options) && isset($options['escape']) &&
$options['escape']) {
                        $text = h($text);
                        unset($options['escape']);
                }
                if (is_array($options) && isset($options['altrows']) &&
$options['altrows']) {
                        if ($this->rowNum % 2 != 0)
                                $alt = null;
                        else
                                $alt = $options['altrows'];
                        unset($options['altrows']);
                }

                $options['escape'] = false;

                return sprintf($this->tags['tablerowstart'], $name, 
$this->rowNum,
$alt, $this->_parseAttributes($options, null, ' ', ''), $text);
        }

        function containerStart($name, $text = null, $options = array()) {
                $alt = null;
                if (is_array($options) && isset($options['escape']) &&
$options['escape']) {
                        $text = h($text);
                        unset($options['escape']);
                }

                if (!is_array($options))
                        $options = array('class' => $options);

                return sprintf($this->tags['tablebodystart'], $name, $this-
>_parseAttributes($options, null, ' ', ''), $text);
        }

        function containerEnd() {
                $this->rowNum = 1;
                return $this->tags['tablebodyend'];
        }

        function close() {
                $this->rowNum++;
                return $this->tags['tablerowend'];
        }

        function handle($name, $containerId, $options = array()) {
                if (is_array($options) && isset($options['escape']) &&
$options['escape']) {
                        $text = h($text);
                        unset($options['escape']);
                }

                $options['class'] = $containerId . "Handle" . $this->rowNum;
                return $this->Html->image($name, $options);
        }

        function create($name, $id, $path, $action) {
                $path = $this->Html->url('/' . $path, true);
                return ($this->Html->scriptBlock("createSortables(\"" . $name . 
"\",
" . $id . ", \"" . $path . "\", \"" . $action . "\");"));
        }
}

On Jul 25, 1:56 pm, Andrew Senner <drewdiddy...@gmail.com> wrote:
> BTW, I know sortables are kind of flaky with tables.  But using
> <tbody><tr> seems to work.  Normally I would stick with divide, but as
> im just implementing this feature to a work in progress, I can't edit
> the base code.
>
> Alrighty thanks for the quick replies.  basically the helper is as
> follows (name: sortable_row.php)
>
> the Helper contains six methods:
>
> containerStart($name), containerEnd(), insert($containerName, ) [for
> row insertion], close() [for row ending], handle(), and create() [The
> actual call to the JS function];
>
> Layout is as follows:
> <table>
>
> containerStart/End methods print out my <tbody id=$name> </tbody>
> tags.  In the example: the first call is
> containerStart("uriSortableContainer"); the second is
> containerStart("analSortableContainer") [anal means Analyzer to avoid
> confusion :P]
>
> insert/close methods print out my <tr id=$containerName . "Row_#">
> (correct format for sequencing... looks like
> "uriSortableContainerRow_1/2/3/etc...");
>
> handle method creates an image handle and gives it a unique ID for the
> onMouseDown/OnMouseUp events: highlights the row when you "click it".
> I used my own method because the onHover option for the Sortable
> object didn't remove the class that was currently on the affected row,
> if there was one. (e.g. A list with alternating row colors for
> visibility.)
>
> and finally:
> create method takes all the info from the other methods and calls the
> javascript function I have written in sortable.js. this creates all
> the right arguments to call the javascript functions..
>
> I don't believe there are issues with the html, as because the helpers
> are reproducing the same code, just with different id names.
>
> function sortableListHoverToggle(name, rowId, status, hclass, nhclass)
> {
>         var hoverClass = "";
>         if (status == 1)
>                 hoverClass = hclass;
>         else {
>                 if ((rowId % 2) == 0)
>                         hoverClass = nhclass;
>                 else
>                         hoverclass = "";
>         }
>         document.getElementById(name + "Row_" + rowId).className =
> hoverClass;
>
>         return;
>
> }
>
> function changeListOrder(name, assetId, dirPath, actionName) {
>         var a                   = 1;
>         var arrayList   = "";
>         arrayList = Sortable.sequence(name);
>         arrayList = arrayList.toString();
>         arrayList = arrayList.replace(/,/g, "/");
>         path = dirPath + "/" + actionName + "/" + assetId + "/" + arrayList;
>
>         document.location = path;
>
>         return;
>
> }
>
> // The create sortables function.
> function createSortables(name, assetId, dirPath, actionName) {
>                 return Sortable.create(name , { tag:'tr', containment: name,
> handles: $$('#' + name + ' img'), onUpdate: function ()
> { changeListOrder(name, assetId, dirPath, actionName) } } );
>
> }
>
> So as you can see each sortable is being created identically with
> unique container and row ids.... Please let me know what you think..
> and if you need more information or not.
>
> Once again thanks for the quick replies!
>
> On Jul 25, 1:34 pm, Tom Gregory <tagreg...@gmail.com> wrote:
>
>
>
>
>
>
>
> > For problems like this, a minimal example page also helps.
>
> > Of course, I'm a bit selfish in asking for one, as I find that often
> > when trying to create a minimal reproducible case I find the problem
> > in my own code ... =)
>
> > TAG
>
> > On Jul 25, 12:10 pm, Andrew Senner <drewdiddy...@gmail.com> wrote:
>
> > > I have a script that creates sortable lists on the fly embedded in a
> > > cakephp helper.  I'm running across an issue when creating a second
> > > sortable list.  Everything works perfectly on the first call to
> > > 'Sortable.create()', and everything works perfectly on the second call
> > > as well.. except:  When trying to actually move an item in the second
> > > list (with or without a handle)  The item will not move until the
> > > mouse cursor is about 100-150px below the list item.... so if my
> > > pointer is approximately 1.5 inch underneath the item it moves up and
> > > down like normal, and saves the list accordingly.
>
> > > Just curious if anyone had any information involving this.. Thanks
> > > ahead of time for your help.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to