Skip to content

Commit

Permalink
Fixed issue where a gallery had to be saved before a thumbnail could …
Browse files Browse the repository at this point in the history
…be selected.
  • Loading branch information
jerel committed Jan 13, 2012
1 parent 62313e6 commit 646d7f6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
7 changes: 7 additions & 0 deletions controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Admin extends Admin_Controller
'label' => 'lang:galleries.thumbnail_label',
'rules' => 'trim'
),
array(
'field' => 'thumbnail_id',
'rules' => 'trim'
),
array(
'field' => 'css',
'label' => 'lang:galleries.css_label',
Expand Down Expand Up @@ -185,6 +189,7 @@ public function create()
->append_metadata( $this->load->view('fragments/wysiwyg', $this->data, TRUE) )
->set('gallery', $gallery)
->set('folders_tree', $folders_tree)
->set('thumbnails', array())
->build('admin/form');
}

Expand Down Expand Up @@ -217,6 +222,7 @@ public function manage($id)
$galleries = $this->gallery_m->get_all();
$gallery = $this->gallery_m->get($id);
$gallery_images = $this->gallery_image_m->get_images_by_gallery($id);
$thumbnails = $this->gallery_image_m->where('gallery_images.gallery_id', $id)->dropdown('files.id', 'files.name');

if (empty($gallery))
{
Expand Down Expand Up @@ -261,6 +267,7 @@ public function manage($id)
->set('gallery', $gallery)
->set('galleries', $galleries)
->set('gallery_images', $gallery_images)
->set('thumbnails', $thumbnails)
->set('folders_tree', $folders_tree)
->build('admin/form');
}
Expand Down
11 changes: 6 additions & 5 deletions js/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ jQuery(function($){
if (data.images) {

$('#gallery_thumbnail').append(
'<optgroup label="Thumbnails">'+
'<option selected value="0">No Thumbnail</option>'+
'</optgroup>'
'<option value="">No Thumbnail</option>'
);

$.each(data.images, function(i, image){
Expand All @@ -80,11 +78,14 @@ jQuery(function($){
'</li>'
);

$('#gallery_thumbnail optgroup[label="Thumbnails"]').append(
'<option value="' + image.id + '">' + image.name + '</option>'
$('#gallery_thumbnail').append(
'<option value="' + image.id + '">' + image.name + '</option>'
);
});
$('.images-placeholder').slideDown();

// update chosen after adding the thumbnails in
$('#gallery_thumbnail').trigger('liszt:updated');
}
}
else {
Expand Down
32 changes: 32 additions & 0 deletions models/gallery_image_m.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,36 @@ public function get($id)
}
}

/**
* Dropdown
*
* @param string $key
* @param string $value
* @return mixed
*/
public function dropdown($key, $value)
{
$dropdown = array();

$query = $this->select(array($key, $value))
->join('files', 'files.id = gallery_images.file_id', 'left')
->get_all();

if ( count($query) > 0 )
{
if (strpos($key, '.')) $key = substr($key, (strpos($key, '.') + 1));
if (strpos($value, '.')) $value = substr($value, (strpos($value, '.') + 1));

foreach ($query AS $thumbnail)
{
$dropdown[$thumbnail->{$key}] = $thumbnail->{$value};
}

return $dropdown;
}
else
{
return FALSE;
}
}
}
27 changes: 3 additions & 24 deletions views/admin/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,9 @@

<li class="thumbnail-manage <?php echo alternator('', 'even'); ?>">
<label for="gallery_thumbnail"><?php echo lang('galleries.thumbnail_label'); ?></label>
<div class="input"><select name="gallery_thumbnail" id="gallery_thumbnail">

<?php if ( ! empty($gallery->thumbnail_id) ): ?>
<!-- Current thumbnail -->
<optgroup label="Current">
<?php foreach ( $gallery_images as $image ): if ( $image->file_id == $gallery->thumbnail_id ): ?>
<option value="<?php echo $gallery->thumbnail_id; ?>">
<?php echo $image->name; ?>
</option>
<?php break; endif; endforeach; ?>
</optgroup>
<?php endif; ?>

<!-- Available thumbnails -->
<optgroup label="Thumbnails">
<option value="0"><?php echo lang('galleries.no_thumb_label'); ?></option>
<?php foreach ( $gallery_images as $image ): ?>
<option value="<?php echo $image->file_id; ?>">
<?php echo $image->name; ?>
</option>
<?php endforeach; ?>
</optgroup>

</select></div>
<div class="input">
<?php echo form_dropdown('gallery_thumbnail', array(0 => lang('galleries.no_thumb_label')) + $thumbnails, $gallery->thumbnail_id, 'id="gallery_thumbnail"'); ?>
</div>
</li>

<?php if (isset($gallery_images) && $gallery_images): ?>
Expand Down

0 comments on commit 646d7f6

Please sign in to comment.