Exemplo n.º 1
0
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        // Get shown images
        if ($this->show_pending) {
            // Show pending images
            $images = $this->gallery->find_images_pending($this->can_approve ? null : self::$_user);
            $radios = array();
            if ($this->can_approve) {
                $radios['approve'] = __('Approve');
            }
            $radios['deny'] = $this->can_approve ? __('Deny') : __('Delete');
            $radios['wait'] = __('Wait');
            ?>

	<header class="well sticky">

<?php 
            if ($this->can_approve) {
                echo __('Approve'), ': <var class="approve"">0</var>, ';
                echo __('Deny'), ': <var class="deny"">0</var>, ';
            } else {
                echo __('Delete'), ': <var class="deny"">0</var>, ';
            }
            echo __('Wait'), ': <var class="wait">', count($images), '</var><br />';
            ?>

	</header>

<?php 
        } else {
            // Show approved images
            $images = $this->gallery->images();
        }
        // Add pending images form?
        if ($this->show_pending) {
            echo Form::open(null, array('id' => 'form-image-approval', 'class' => 'form-horizontal'));
        }
        $copyright = $multiple = null;
        foreach ($images as $image) {
            // Add copyright
            if ($image->author_id != $copyright) {
                $copyright = $image->author_id;
                if ($multiple) {
                    // Not first copyright
                    ?>

	</ul>

<?php 
                } else {
                    // First copyright
                    $multiple = true;
                }
                ?>

	<header>&copy; <?php 
                echo HTML::user($copyright);
                ?>
</header>
	<ul class="thumbnails">

<?php 
            }
            // Copyright
            ?>

		<li class="span2">

<?php 
            echo HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($this->gallery), 'id' => $image->id, 'action' => $this->show_pending ? 'approve' : '')), HTML::image($image->get_url('thumbnail', $this->gallery->dir)), $image->description ? array('class' => 'thumbnail', 'title' => HTML::chars($image->description)) : array('class' => 'thumbnail'));
            if (!$this->show_pending) {
                // Info
                echo '<i class="icon-comment icon-white"></i> ' . (int) $image->comment_count;
                echo '<i class="icon-eye-open icon-white"></i> ' . (int) $image->view_count;
            } else {
                // Pending image form
                echo Form::radios_wrap('image_id[' . $image->id . ']', $radios, 'wait');
            }
            ?>

		</li>

<?php 
        }
        // Images
        ?>

	</ul>

<?php 
        // Form controls
        if ($this->show_pending) {
            ?>

	<fieldset class="form-actions">

<?php 
            echo Form::radios_wrap('all', $radios, null, null, __('For all images'), null, null, 'inline');
            echo Form::csrf();
            echo Form::button('approve', __('Save'), array('type' => 'submit', 'class' => 'btn btn-success btn-large')), ' ';
            echo HTML::anchor(Route::url('galleries', array('action' => 'approval')), __('Cancel'), array('class' => 'cancel'));
            ?>

	</fieldset>

<?php 
            echo Form::close();
            ?>

<script>
head.ready('jquery', function() {

	// Calculate totals
	function totals() {
		$.each([ 'approve', 'deny', 'wait' ], function totals() {
			$('var.' + this).text($('input[name!=all][value=' + this + ']:checked').length);
		});
	}

	// Actions for all images
	$('form input[name=all]').change(function onChangeAll() {
		$('form input[value=' + $(this).val() + ']').attr('checked', 'checked');

		totals();
	});

	// Single image actions
	$('form input[name^=image_id]').change(function onChangeOne() {
		$('input[name=all]').removeAttr('checked');

		totals();
	});

});
</script>


<?php 
        }
        return ob_get_clean();
    }