From ad10a97f4ac3ffad5508b90da45b5c5a63db95ff Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sat, 24 May 2014 16:24:52 +0000 Subject: [PATCH] feature 3077 : use selectize on batch_manager_global, cat_modify and photos_add_direct + rewrite "add album" popup (more flexible and working with selectize) git-svn-id: http://piwigo.org/svn/trunk@28533 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/batch_manager_global.php | 19 +-- admin/cat_modify.php | 27 +--- .../include/photos_add_direct_prepare.inc.php | 20 +-- admin/themes/default/js/addAlbum.js | 123 ++++++++++++++++++ .../default/template/batch_manager_global.tpl | 81 ++++++++---- admin/themes/default/template/cat_modify.tpl | 73 ++++++++++- .../template/include/add_album.inc.tpl | 83 +----------- .../default/template/include/colorbox.inc.tpl | 2 +- .../default/template/photos_add_direct.tpl | 71 ++++++++-- .../default/template/picture_modify.tpl | 1 + admin/themes/default/theme.css | 7 + 11 files changed, 345 insertions(+), 162 deletions(-) create mode 100644 admin/themes/default/js/addAlbum.js diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php index 4bec501db..6e65c462d 100644 --- a/admin/batch_manager_global.php +++ b/admin/batch_manager_global.php @@ -474,6 +474,8 @@ $template->assign( ); // tags +$filter_tags = array(); + if (!empty($_SESSION['bulk_manager_filter']['tags'])) { $query = ' @@ -483,20 +485,11 @@ SELECT FROM '.TAGS_TABLE.' WHERE id IN ('.implode(',', $_SESSION['bulk_manager_filter']['tags']).') ;'; - $template->assign('filter_tags', get_taglist($query)); + + $filter_tags = get_taglist($query); } -// Virtualy associate a picture to a category -$query = ' -SELECT id,name,uppercats,global_rank - FROM '.CATEGORIES_TABLE.' -;'; -$categories = array_from_query($query); -usort($categories, 'global_rank_compare'); -display_select_categories($categories, array(), 'category_full_name_options', true); - -$template->assign('category_parent_options', $template->get_template_vars('category_full_name_options')); -$template->assign('category_parent_options_selected', array()); +$template->assign('filter_tags', $filter_tags); // in the filter box, which category to select by default $selected_category = array(); @@ -704,7 +697,7 @@ SELECT id,path,representative_ext,file,filesize,level,name,width,height,rotation $template->assign(array( 'nb_thumbs_page' => $nb_thumbs_page, 'nb_thumbs_set' => count($page['cat_elements_id']), - 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags')) + 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories')), )); trigger_action('loc_end_element_set_global'); diff --git a/admin/cat_modify.php b/admin/cat_modify.php index 4eeeffe42..da7776137 100644 --- a/admin/cat_modify.php +++ b/admin/cat_modify.php @@ -288,12 +288,11 @@ else $intro.= '
'.l10n('Numeric identifier : %d', $category['id']); -$template->assign('INTRO', $intro); - -$template->assign( - 'U_MANAGE_RANKS', - $base_url.'element_set_ranks&cat_id='.$category['id'] - ); +$template->assign(array( + 'INTRO' => $intro, + 'U_MANAGE_RANKS' => $base_url.'element_set_ranks&cat_id='.$category['id'], + 'CACHE_KEYS' => get_admin_client_cache_keys(array('categories')), + )); if ($category['is_virtual']) { @@ -366,21 +365,7 @@ SELECT id,representative_ext,path if ($category['is_virtual']) { - // the category can be moved in any category but in itself, in any - // sub-category - $unmovables = get_subcat_ids(array($category['id'])); - - $query = ' -SELECT id,name,uppercats,global_rank - FROM '.CATEGORIES_TABLE.' - WHERE id NOT IN ('.implode(',', $unmovables).') -;'; - - display_select_cat_wrapper( - $query, - empty($category['id_uppercat']) ? array() : array($category['id_uppercat']), - 'move_cat_options' - ); + $template->assign('parent_category', empty($category['id_uppercat']) ? array() : array($category['id_uppercat'])); } trigger_action('loc_end_cat_modify'); diff --git a/admin/include/photos_add_direct_prepare.inc.php b/admin/include/photos_add_direct_prepare.inc.php index 117abb802..44b63082d 100644 --- a/admin/include/photos_add_direct_prepare.inc.php +++ b/admin/include/photos_add_direct_prepare.inc.php @@ -217,16 +217,7 @@ SELECT category_id } // existing album -$query = ' -SELECT id,name,uppercats,global_rank - FROM '.CATEGORIES_TABLE.' -;'; - -display_select_cat_wrapper( - $query, - $selected_category, - 'category_options' - ); +$template->assign('selected_category', $selected_category); // image level options @@ -256,11 +247,10 @@ if (!function_exists('gd_info')) $setup_errors[] = l10n('GD library is missing'); } -$template->assign( - array( - 'setup_errors'=> $setup_errors, - ) - ); +$template->assign(array( + 'setup_errors'=> $setup_errors, + 'CACHE_KEYS' => get_admin_client_cache_keys(array('categories')), + )); // Warnings if (isset($_GET['hide_warnings'])) diff --git a/admin/themes/default/js/addAlbum.js b/admin/themes/default/js/addAlbum.js new file mode 100644 index 000000000..60942d8a7 --- /dev/null +++ b/admin/themes/default/js/addAlbum.js @@ -0,0 +1,123 @@ +jQuery.fn.pwgAddAlbum = function(options) { + if (!options.cache) { + jQuery.error('pwgAddAlbum: missing categories cache'); + } + + var $popup = jQuery('#addAlbumForm'); + if (!$popup.data('init')) { + $popup.find('[name="category_parent"]').selectize({ + valueField: 'id', + labelField: 'fullname', + sortField: 'fullname', + searchField: ['fullname'], + plugins: ['remove_button'], + onInitialize: function() { + this.on('dropdown_close', function() { + if (this.getValue() == '') { + this.setValue(0); + } + }); + } + }); + + $popup.find('form').on('submit', function(e) { + e.preventDefault(); + + jQuery('#categoryNameError').text(''); + + var albumParent = $popup.find('[name="category_parent"]'), + parent_id = albumParent.val(), + name = $popup.find('[name=category_name]').val(), + target = $popup.data('target'); + + jQuery.ajax({ + url: 'ws.php?format=json', + type: 'POST', + dataType: 'json', + data: { + method: 'pwg.categories.add', + parent: parent_id, + name: name + }, + beforeSend: function() { + jQuery('#albumCreationLoading').show(); + }, + success: function(data) { + jQuery('#albumCreationLoading').hide(); + jQuery('[data-add-album="'+ target +'"]').colorbox.close(); + + var newAlbum = data.result.id, + newAlbum_name = ''; + + if (parent_id != 0) { + newAlbum_name = albumParent[0].selectize.options[parent_id].fullname +' / '; + } + newAlbum_name+= name; + + var $albumSelect = jQuery('[name="'+ target +'"]'); + + // target is a normal select + if (!$albumSelect[0].selectize) { + var new_option = jQuery('') - .append($albumSelect.html()) - .val($albumSelect.val() || 0); - } - }); +{combine_script id='jquery.selectize' load='footer' path='themes/default/js/plugins/selectize.min.js'} +{combine_css id='jquery.selectize' path="themes/default/js/plugins/selectize.default.css"} - jQuery("#addAlbumForm form").submit(function() { - jQuery("#categoryNameError").text(""); - - var parent_id = jQuery("select[name=category_parent] option:selected").val(), - name = jQuery("input[name=category_name]").val(); - - jQuery.ajax({ - url: "ws.php", - dataType: 'json', - data: { - format: 'json', - method: 'pwg.categories.add', - parent: parent_id, - name: name - }, - beforeSend: function() { - jQuery("#albumCreationLoading").show(); - }, - success: function(data) { - jQuery("#albumCreationLoading").hide(); - jQuery(".addAlbumOpen").colorbox.close(); - - var newAlbum = data.result.id, - newAlbum_name = ''; - - if (parent_id!=0) { - newAlbum_name = jQuery("#category_parent").find("option[value="+ parent_id +"]").text() +' / '; - } - newAlbum_name+= name; - - var new_option = jQuery("