eZ Community » Forums » Developer » Subitems table content - YUI Ajax...
expandshrink

Subitems table content - YUI Ajax loader customization [SOLVED]

Subitems table content - YUI Ajax loader customization [SOLVED]

Wednesday 20 June 2012 3:18:50 pm - 4 replies

Hi eZ community,

I need your help one more time!

I need to customize the subitems table generated by YUI Loader, in order to display, for the record, some other object's information.

Let's say I have I new class which has an object relation attribute through which I can relate an object of the image class from the media section, in place of the normal image attribute and so in the thumbnail column of the subitems table, instead of the thumbnail which comes by default, I need to show the thumbnail of this related image object.

For what I have been able to see so far, the customization can be done by creating an override of the /admin2/javascript/ezajaxsubitems_datatable.js where I can initialize new keys related to the object's info itself (i.e. here I added a 'class_identifier' key)..

..
        var dataSource = new YAHOO.util.DataSource(confObj.dataSourceURL);
        dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
        dataSource.maxCacheEntries = 20;    // Caches between paginations. Requires a refresh after async updates to priorities
        dataSource.responseSchema = {
            resultsList: "content.list",
            fields: [
                {key:"name"},
                {key:"hidden_status_string"},
                {key:"class_name"},
                {key:"creator", parser:creatorParser},
                {key:"modified_date"},
                {key:"published_date"},
                {key:"section", parser:sectionParser},
                {key:"translations", parser:translationsParser},
                {key:"version"},
                {key:"node_id"},
                {key:"node_remote_id"},
                {key:"contentobject_id"},
                {key:"contentobject_remote_id"},
                {key:"contentobject_state"},
                {key:"priority"},
                {key:"class_icon"},
                {key:"thumbnail_url"},
                {key:"thumbnail_height"},
                {key:"thumbnail_width"},
                {key:"url"},
                {key:"parent_node_id"},
                {key:"can_edit"},
                {key:"class_identifier"}
            ],
            metaFields: {
                totalRecords: "content.total_count" // Access to value in the server response
            }
        };
..

.. which can than be called in the function

..
        var thumbView = function(cell, record, column, data) {
            var url = record.getData('thumbnail_url');
            if (url) {
                var thBack = 'background: url(' + url + ') no-repeat;';
                var thWidth = ' width: ' + record.getData('thumbnail_width') + 'px;';
                var thHeight = ' height: ' + record.getData('thumbnail_height') + 'px;';
                cell.innerHTML = '<div class="thumbview"><div id="thumbfield" class="thumbfield"></div><span><div style="' + thBack + thWidth + thHeight + '"></div></span></div>';
            }
            else if(record.getData('class_identifier') == "immagine") {
                cell.innerHTML = '<img src="' + url + '" />';
            }
            else {
                cell.innerHTML = '';
            }
        }
..

.. here in the else if statement, in place of the thumbnail_url I should pass the url of the file image of the current record/object's related object attribute, something which from a template point of view I can retrieve by $record.data_map.image[content][contentobject_attributes][2][content][original][url] sintax

But even if I initialize a..

{key:"data_map"}

..how can I actually get the object's data_map info in order to display them into the table?

Any help would be really appreciated!

Modified on Sunday 24 June 2012 12:03:09 am by Lo' F.

Thursday 21 June 2012 11:15:31 pm

I'm thinking if you declare a record in JS called "related_thumbnail_url" you can then populate that with the related image url via template code.

Friday 22 June 2012 4:17:08 pm

Quote from Brandon Chambers :

I'm thinking if you declare a record in JS called "related_thumbnail_url" you can then populate that with the related image url via template code.

Brandon, first of all, thanks a lot for your reply happy.gif Emoticon

You mean declare it in this way...

..
fields: [
    ...
    {key:"class_identifier"},
    {key:"related_thumbnail_url"}
],
..

and use the key in the js function variable...

..
var thumbView = function(cell, record, column, data) {
    var url = record.getData('thumbnail_url');
    if (url) {
        ...
    }
    else if(record.getData('class_identifier') == "immagine") {
        cell.innerHTML = '<img src="' + record.getData('related_thumbnail_url') + '" />';
    }
    else {
        cell.innerHTML = ''; 
    }
}
..

..within /admin2/javascript/ezajaxsubitems_datatable.js ?!

But then how can I populate this key via template code?

Modified on Friday 22 June 2012 4:18:39 pm by Lo' F.

Sunday 24 June 2012 12:00:55 am

happy.gif Emoticon

Finally made it! happy.gif Emoticon ..and, of course, happy to share!

The file I was looking for is /extension/ezjscore/classes/ezjscajaxcontent.php

Actually I didn't need to set a new key in the ezajaxsubitems_datatable.js but just pass the path of the related object's image to the thumbnail_url variable by adding a new condition within the main php function

..
if ( isset( $params['fetchThumbPreview'] ) ) {
    $thumbUrl = '';
    $thumbWidth = 0;
    $thumbHeight = 0;
    $thumbDataType = isset( $params['thumbDataType'] ) ? $params['thumbDataType'] : 'ezimage';
    $thumbImageSize = isset( $params['thumbImageSize'] ) ? $params['thumbImageSize'] : 'small';
 
    foreach( $contentObject->attribute( 'data_map' ) as $key => $atr ) {
        if ( $atr->attribute( 'data_type_string' ) == $thumbDataType
            && $atr->attribute( 'has_content' ) ) {
            ...
        }
 
        //If the image is a related object
        if ( $atr->attribute( 'data_type_string' ) == 'ezobjectrelation'
                        && $atr->attribute( 'has_content' ) ) {
            $imageContent = $atr->attribute( 'content' );
            $imageContent = $imageContent->attribute( 'contentobject_attributes' );
            foreach( $imageContent as $i => $arr ) {
                if ($i == 2) {
                    $imageContent = $arr->attribute( 'content' );
                }
            }
 
            if ( $imageContent->hasAttribute( $thumbImageSize ) )
                $imageAlias = $imageContent->attribute( $thumbImageSize );
            else
                eZDebug::writeError( "Image alias does not exist: '{$thumbImageSize}', missing from image.ini?",
                        __METHOD__ );
 
            $thumbUrl = isset( $imageAlias['full_path'] ) ? $imageAlias['full_path'] : '';
            $thumbWidth = isset( $imageAlias['width'] ) ? (int) $imageAlias['width'] : 0;
            $thumbHeight = isset( $imageAlias['height'] ) ? (int) $imageAlias['height'] : 0;
 
            if ( $thumbUrl !== '' )
                eZURI::transformURI( $thumbUrl, true );
 
            break;
        }
 
    }
 
    $ret['thumbnail_url'] = $thumbUrl;
    $ret['thumbnail_width'] = $thumbWidth;
    $ret['thumbnail_height'] = $thumbHeight;
}
...

blunk.gif Emoticon

Friday 29 June 2012 12:54:25 pm

Just a slight adjustment to avoid conflicts while loading the records within the table ...

..
 //If the image is a related object
elseif ( $atr->attribute( 'data_type_string' ) == 'ezobjectrelation'
           && $contentObject->attribute( 'class_identifier' ) == 'immagine'
           && $atr->attribute( 'has_content' ) ) {
...

Cheers!

Modified on Friday 29 June 2012 12:55:01 pm by Lo' F.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu