/*******************************************************************************
 * Playlist Editor
 * -----------------------------------------------------------------------------
 * Copyright (C) 2007,2008 FOR INTERNET a.s.
 * $Id$
 *
 *
 */



/**
 *   Controller to manage filtering of playlist input
 */
function PlaylistInputController()
{
}
PlaylistInputController.prototype = new PlaylistController();


/**
 * Switcher to show different classes for odd and even rows
 */
PlaylistInputController.prototype.tr = ['odd','even'];


/**
 *   Initializator method of PlaylistController aka constructor
 *
 * @param DOMDocument model
 * @param DOMElement  viewElement
 * @return PlaylistController
 */
PlaylistInputController.prototype.PlaylistInputControllerInitializer = function PlaylistInputControllerInitializer(playlistModel, viewElement)
{
        this.row   = 0;
        return this.PlaylistControllerInitializer(playlistModel, viewElement);
}



/**
 *   Atomic view for a single song.
 *
 * @param DOMElement songModel
 * @return DOMElement

   <tr class="<?= $iter % 2 ? 'odd' : 'even'; ?>">
        <td><strong><?= $item['band_name']; ?></strong> - <?= $item['name']; ?></td>
        <td class="btn"><a href="javascript:player('play/<?= $item['id'] ?>/')"><img src="/hudebni-kanal/on-line-radio/_clip/btn_play.gif" alt="&lquo;" title="Přehrát skladbu" /></a></td>
        <td class="btn"><a href="javascript:noop();" onclick="playlist.append({id: <?= $item['id'] ?>, name: '<?= $item['name']; ?>', band: '<?= $item['band_name']; ?>', year: '<?= $item['year']; ?>'})"><img src="/hudebni-kanal/on-line-radio/_clip/btn_add.gif" alt="&lquo;&lquo;" title="Přidat do playlistu" /></a></td>
   </tr>


 */
PlaylistInputController.prototype.songView = function songView(songModel)
{
        var view;
        var r = this.tr[this.row = 1 - this.row];
        return view = tr([
                td([
                        strong([songModel.getAttribute('ar')]),
                        ' - ' + songModel.getAttribute('n')
                ]),
                td([
                        a([
                                img({
                                        'src': '/hudebni-kanal/on-line-radio/_clip/btn_play.gif',
                                        'alt': 'Přehrát',
                                        'title': 'Přehrát skladbu'
                                })
                        ],{
                                href: 'javascript:player("play/' + songModel.getAttribute('id') + '/")'
                        }/*,{
                                onclick: function(e) {player('play/' + songModel.getAttribute('id') + '/');}
                        }*/)
                ],{
                        'class': 'btn'
                },{
                        'className': 'btn'
                }),
                td([
                        a([
                                img({
                                        'src': '/hudebni-kanal/on-line-radio/_clip/btn_add.gif',
                                        'alt': 'Přidat',
                                        'title': 'Přidat do playlistu'
                                })
                        ],{
                                href: 'javascript:noop();'
                        },{
                                onclick: function(e) {playlist.append(songModel);}
                        })
                ],{
                        'class': 'btn'
                },{
                        'className': 'btn'
                })
        ], {
                'class': r
        }, {
                'className': r
        });
}


PlaylistInputController.prototype.buttonAll = function buttonAll()
{
        var instance = this;
        return tr([
                td([
                        a([
                                img({
                                        'src': '/hudebni-kanal/on-line-radio/_clip/btn_add_all.gif',
                                        'alt': 'Přidat vse',
                                        'title': 'Přidat vše do playlistu'
                                })
                        ],{
                                href: 'javascript:inputPlaylist.appendAll()'
                        }/*,{
                                onclick: function(e) {instance.appendAll();}
                        }*/)
                ],{
                        'colspan': '3',
                        'class': 'textRight'
                }, {
                        'colSpan': '3',
                        'className': 'textRight'
                })
        ])
}



/**
 * @return DOMElement element
 
        <table class="playlist">

                <tr>
                        <th colspan="3" id="title">NADPIS...</th>
                </tr>

                <tr>
                        <td colspan="3" class="textRight"><a href=""><img src="/hudebni-kanal/on-line-radio/_clip/btn_add_all.gif" alt="&lquo;&lquo;" title="Přidat vše do playlistu" /></a></td>
                </tr>
                <?php foreach($this->list as $iter => $item): ?>
                ...
                <?php endforeach; ?>
                <tr>
                        <td colspan="3" class="textRight"><a href=""><img src="/hudebni-kanal/on-line-radio/_clip/btn_add_all.gif" alt="&lquo;&lquo;" title="Přidat vše do playlistu" /></a></td>

                </tr>

        </table>

 
 */
PlaylistInputController.prototype.playlistViewElement = function playlistViewElement()
{
        var title = this.model.documentElement.getAttribute('title') ? this.model.documentElement.getAttribute('title').toString() : '';
        var instance = this;
        return table([
                tbody([
                        tr([
                                th([
                                        title
                                ],{
                                        'colspan': '3'
                                },{
                                        'colSpan': '3'
                                })
                        ]),
                        this.buttonAll()
                ])
        ],{
                'class': 'playlist'
        },{
                'className': 'playlist'
        });
}


/**
 * @return DOMElement element
 */
PlaylistInputController.prototype.playlistViewEnd = function playlistViewEnd(view)
{
        var instance = this;
        view.appendChild(this.buttonAll());
        return view;
}


/**
 * Method to append all items in input playlist into user's playlist
 */
PlaylistInputController.prototype.appendAll = function appendAll()
{
        with(this.songs()) for(var i = 0; i < length; i++) playlist.append(item(i));

}

