diff --git a/controllers/admin.php b/controllers/admin.php index 825eafa..204e151 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -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', @@ -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'); } @@ -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)) { @@ -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'); } diff --git a/js/manage.js b/js/manage.js index 894e124..067e3ce 100644 --- a/js/manage.js +++ b/js/manage.js @@ -68,9 +68,7 @@ jQuery(function($){ if (data.images) { $('#gallery_thumbnail').append( - '' + '' ); $.each(data.images, function(i, image){ @@ -80,11 +78,14 @@ jQuery(function($){ '' ); - $('#gallery_thumbnail optgroup[label="Thumbnails"]').append( - '' + $('#gallery_thumbnail').append( + '' ); }); $('.images-placeholder').slideDown(); + + // update chosen after adding the thumbnails in + $('#gallery_thumbnail').trigger('liszt:updated'); } } else { diff --git a/models/gallery_image_m.php b/models/gallery_image_m.php index e106901..2a93894 100644 --- a/models/gallery_image_m.php +++ b/models/gallery_image_m.php @@ -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; + } + } } \ No newline at end of file diff --git a/views/admin/form.php b/views/admin/form.php index c0f8a7c..bcfbfb3 100644 --- a/views/admin/form.php +++ b/views/admin/form.php @@ -56,30 +56,9 @@