Change the priority in the list valid of block manual

Author Message

Bin LIU

Friday 18 April 2008 6:31:56 am

In the version now, When we published the bloc manual, i can't change the priority of articles in the block list.

So, if you want change the priority, do like this :

a. In the end of extension/ezflow/design/ezflow/templates/content/datatype/edit/ezpage.tpl
add :

<script type="text/javascript"><!--
{literal}
YAHOO.namespace( "liubin" );
(function() {

var Dom = YAHOO.util.Dom;
var Event = YAHOO.util.Event;
var DDM = YAHOO.util.DragDropMgr;

{/literal}
// app

YAHOO.liubin.DDApp = {ldelim}
    init: function() {ldelim}
{foreach $attribute.content.zones as $zone_id => $zone}
    {if and( is_set( $zone.blocks ), $zone.blocks|count() )}
    {foreach $zone.blocks as $block_id => $block}
      
         new YAHOO.util.DDTarget("z:{$zone_id}_b:{$block_id}_o");
        {foreach $block.valid as $item}
            dd{$zone_id}{$block_id}{$item.object_id} = new YAHOO.liubin.DDList("z:{$zone_id}_b:{$block_id}_i:{$item.object_id}");

            dd{$zone_id}{$block_id}{$item.object_id}.setHandleElId("z:{$zone_id}_b:{$block_id}_i:{$item.object_id}_h");
        {/foreach}
        
    {/foreach}
    {/if}
{/foreach}

    {rdelim}

{rdelim};
{literal}
// custom drag and drop implementation

YAHOO.liubin.DDList = function(id, sGroup, config) {

    YAHOO.liubin.DDList.superclass.constructor.call(this, id, sGroup, config);

    this.logger = this.logger || YAHOO;
    var el = this.getDragEl();
    Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent

    this.goingUp = false;
    this.lastY = 0;
};

YAHOO.extend(YAHOO.liubin.DDList, YAHOO.util.DDProxy, {

    startDrag: function(x, y) {
        this.logger.log(this.id + " startDrag");

        // make the proxy look like the source element
        var dragEl = this.getDragEl();
        var clickEl = this.getEl();
        Dom.setStyle(clickEl, "visibility", "hidden");

        dragEl.innerHTML = clickEl.innerHTML;

        Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));
        Dom.setStyle(dragEl, "backgroundColor", Dom.getStyle(clickEl, "backgroundColor"));
        Dom.setStyle(dragEl, "border", "2px solid gray");
    },

    endDrag: function(e) {

        var srcEl = this.getEl();
        var proxy = this.getDragEl();

        // Show the proxy element and animate it to the src element's location
        Dom.setStyle(proxy, "visibility", "");
        var a = new YAHOO.util.Motion( 
            proxy, { 
                points: { 
                    to: Dom.getXY(srcEl)
                }
            }, 
            0.2, 
            YAHOO.util.Easing.easeOut 
        )
        var proxyid = proxy.id;
        var thisid = this.id;

        // Hide the proxy and show the source element when finished with the animation
        a.onComplete.subscribe(function() {
                Dom.setStyle(proxyid, "visibility", "hidden");
                Dom.setStyle(thisid, "visibility", "");
            });
        a.animate();

        var url;
        var tableBody = srcEl.parentNode;
        var postData = "";
        var items = tableBody.getElementsByTagName("tr");
        for (i=0;i<items.length;i=i+1) {
            postData += "Items%5B%5D=" + items[i].id + "&";
        }

        var tableID = tableBody.parentNode.id;
{/literal}
alert(tableID);
        postData += 'Block=' + tableID + '&ContentObjectAttributeID=' + {$attribute.id} + '&Version=' + {$attribute.version};
        url = "{'/ezflow/request'|ezurl(no)}";
        YAHOO.util.Connect.asyncRequest( 'POST', url, false, postData );
{literal}

    },

    onDragDrop: function(e, id) {

        // If there is one drop interaction, the li was dropped either on the list,
        // or it was dropped on the current location of the source element.
        if (DDM.interactionInfo.drop.length === 1) {

            // The position of the cursor at the time of the drop (YAHOO.util.Point)
            var pt = DDM.interactionInfo.point; 

            // The region occupied by the source element at the time of the drop
            var region = DDM.interactionInfo.sourceRegion; 

            // Check to see if we are over the source element's location.  We will
            // append to the bottom of the list once we are sure it was a drop in
            // the negative space (the area of the list without any list items)
            if (!region.intersect(pt)) {
                var destEl = Dom.get(id);
                var destDD = DDM.getDDById(id);
                destEl.appendChild(this.getEl());
                destDD.isEmpty = false;
                DDM.refreshCache();
            }

        }
    },

    onDrag: function(e) {

        // Keep track of the direction of the drag for use during onDragOver
        var y = Event.getPageY(e);

        if (y < this.lastY) {
            this.goingUp = true;
        } else if (y > this.lastY) {
            this.goingUp = false;
        }

        this.lastY = y;
    },

    onDragOver: function(e, id) {
    
        var srcEl = this.getEl();
        var destEl = Dom.get(id);

        // We are only concerned with list items, we ignore the dragover
        // notifications for the list.
        if (destEl.nodeName.toLowerCase() == "tr") {
            var orig_p = srcEl.parentNode;
            var p = destEl.parentNode;

            if (this.goingUp) {
                p.insertBefore(srcEl, destEl); // insert above
            } else {
                p.insertBefore(srcEl, destEl.nextSibling); // insert below
            }

            DDM.refreshCache();
        }
    }
});

Event.onDOMReady(YAHOO.liubin.DDApp.init, YAHOO.liubin.DDApp, true);

})();



{/literal}
--></script>

b. in the extension/ezflow/modules/ezflow/request.php line 49

change

	    foreach( $block->getWaitingItems() as $blockItem )
	    {
	        if( $blockItem->attribute( 'object_id' ) == $itemParams['i'] )
	        {
	                if( $blockItem->toBeAdded() )
		            {
		                $blockItem->setAttribute( 'priority', $key + 1 );
		                $items[] = $blockItem;
		            }
		            else
		            {
		                $tmpItem =& $block->addItem( new eZPageBlockItem() );
		                $tmpItem->setAttribute( 'priority', $key + 1 );
		                $tmpItem->setAttribute( 'object_id', $blockItem->attribute( 'object_id' ) );
		                $tmpItem->setAttribute( 'ts_publication', $blockItem->attribute( 'ts_publication' ) );
		                $tmpItem->setAttribute( 'action', 'modify' );
		                $items[] = $tmpItem;
		            }
	        }
	    }

by

    /************added by LIU Bin for move the bloc valid begin****/
    if(array_key_exists("o",$blockParams))
    {
        foreach( $block->getValidItems() as $blockItem )
    	{
	        if( $blockItem->attribute( 'object_id' ) == $itemParams['i'] )
	        {
	
	                $tmpItem =& $block->addItem( new eZPageBlockItem() );
	                $tmpItem->setAttribute( 'priority', $key + 1 );
	                $tmpItem->setAttribute( 'object_id', $blockItem->attribute( 'object_id' ) );
	                $tmpItem->setAttribute( 'action', 'modify' );
	                $items[] = $tmpItem;
	
	        }
    	}
    }
    else
    {
    	 /************added by LIU Bin for move the bloc valid end****/
	    foreach( $block->getWaitingItems() as $blockItem )
	    {
	        if( $blockItem->attribute( 'object_id' ) == $itemParams['i'] )
	        {
	                if( $blockItem->toBeAdded() )
		            {
		                $blockItem->setAttribute( 'priority', $key + 1 );
		                $items[] = $blockItem;
		            }
		            else
		            {
		                $tmpItem =& $block->addItem( new eZPageBlockItem() );
		                $tmpItem->setAttribute( 'priority', $key + 1 );
		                $tmpItem->setAttribute( 'object_id', $blockItem->attribute( 'object_id' ) );
		                $tmpItem->setAttribute( 'ts_publication', $blockItem->attribute( 'ts_publication' ) );
		                $tmpItem->setAttribute( 'action', 'modify' );
		                $items[] = $tmpItem;
		            }
	        }
	    }
 /************added by LIU Bin for move the bloc valid begin****/
    }
 /************added by LIU Bin for move the bloc valid end****/

c. the line 777 in extension/ezflow/datatypes/ezpage/ezpagetype.php

after :

 $db->query( "UPDATE ezm_pool SET ts_publication='" . $item->attribute( 'ts_publication' ) . "'
                                                               WHERE object_id='" . $item->attribute( 'object_id' ) . "'" );

add code :

 /************added by LIU Bin for move the bloc valid****/
                                        	$sql =  "UPDATE ezm_pool SET priority='" . $item->attribute( 'priority' ) . "'
                                                WHERE object_id='" . $item->attribute( 'object_id' ) . "' and  block_id='$blockID'" ;
                                        	$db->query($sql);

Then, we can drag and drop in the block valid list.

And By a way, for the block manual. the order of the list in ezflow edition is contrary order in the front. it's a bug. i reverse the array $block.valid in the template front

I think it will be fixed in the futur version

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Łukasz Serwatka

Wednesday 09 July 2008 11:32:14 pm

Implemented in ezflow 1.0-1 and ezflow 1.1-0 (next version).

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.