From ce8a29810abe6f7fdf82043b32ca87ba0f14220c Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sat, 17 May 2014 15:33:37 +0000 Subject: feature 3077 : use Selectize with AJAX load/cache on cat_perm and batch_manager_unit git-svn-id: http://piwigo.org/svn/trunk@28496 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/picture_modify.php | 9 -- .../themes/default/template/batch_manager_unit.tpl | 69 ++++++++----- admin/themes/default/template/cat_perm.tpl | 108 ++++++++++++++------- admin/themes/default/template/picture_modify.tpl | 40 +++----- 4 files changed, 131 insertions(+), 95 deletions(-) diff --git a/admin/picture_modify.php b/admin/picture_modify.php index 0eccae136..dc7d56211 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -218,14 +218,6 @@ SELECT ;'; $tag_selection = get_taglist($query); -$query = ' -SELECT - id, - name - FROM '.TAGS_TABLE.' -;'; -$tags = get_taglist($query, false); - // retrieving direct information about picture $query = ' SELECT * @@ -258,7 +250,6 @@ $admin_url_start.= isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : ''; $template->assign( array( 'tag_selection' => $tag_selection, - 'tags' => $tags, 'U_SYNC' => $admin_url_start.'&sync_metadata=1', 'U_DELETE' => $admin_url_start.'&delete=1&pwg_token='.get_pwg_token(), diff --git a/admin/themes/default/template/batch_manager_unit.tpl b/admin/themes/default/template/batch_manager_unit.tpl index 859a9b6a0..c2137bead 100644 --- a/admin/themes/default/template/batch_manager_unit.tpl +++ b/admin/themes/default/template/batch_manager_unit.tpl @@ -2,25 +2,53 @@ {include file='include/datepicker.inc.tpl'} {include file='include/colorbox.inc.tpl'} -{combine_css path='themes/default/js/plugins/jquery.tokeninput.css'} -{combine_script id='jquery.tokeninput' load='async' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'} -{footer_script require='jquery.tokeninput'} -jQuery(document).ready(function() {ldelim} - jQuery('select[name|="tags"]').tokenInput( - [{foreach from=$tags item=tag name=tags}{ldelim}name:"{$tag.name|@escape:'javascript'}",id:"{$tag.id}"{rdelim}{if !$smarty.foreach.tags.last},{/if}{/foreach}], - {ldelim} - hintText: '{'Type in a search term'|@translate}', - noResultsText: '{'No results'|@translate}', - searchingText: '{'Searching...'|@translate}', - newText: ' ({'new'|@translate})', - animateDropdown: false, - preventDuplicates: true, - allowFreeTagging: true +{combine_script id='LocalStorageCache' load='footer' path='admin/themes/default/js/LocalStorageCache.js'} + +{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"} + +{footer_script} +(function(){ +{* *} +var tagsCache = new LocalStorageCache('tagsAdminList', 5*60, function(callback) { + jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.tags.getAdminList', function(data) { + var tags = data.result.tags; + + for (var i=0, l=tags.length; i{'Batch Manager'|@translate} @@ -102,13 +130,8 @@ jQuery(document).ready(function() {ldelim} {'Tags'|@translate} - - - + diff --git a/admin/themes/default/template/cat_perm.tpl b/admin/themes/default/template/cat_perm.tpl index 0415c87a4..ba0813014 100644 --- a/admin/themes/default/template/cat_perm.tpl +++ b/admin/themes/default/template/cat_perm.tpl @@ -1,39 +1,75 @@ -{combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'} -{combine_css path="themes/default/js/plugins/chosen.css"} - -{footer_script}{literal} -jQuery(document).ready(function() { - jQuery(".chzn-select").chosen(); - - function checkStatusOptions() { - if (jQuery("input[name=status]:checked").val() == "private") { - jQuery("#privateOptions, #applytoSubAction").show(); - } - else { - jQuery("#privateOptions, #applytoSubAction").hide(); - } - } - - checkStatusOptions(); - jQuery("#selectStatus").change(function() { - checkStatusOptions(); +{combine_script id='LocalStorageCache' load='footer' path='admin/themes/default/js/LocalStorageCache.js'} + +{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"} + +{footer_script} +(function(){ +{* *} +var groupsCache = new LocalStorageCache('groupsAdminList', 5*60, function(callback) { + jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.groups.getList&per_page=99999', function(data) { + callback(data.result.groups); }); +}); + +jQuery('[data-selectize=groups]').selectize({ + valueField: 'id', + labelField: 'name', + searchField: ['name'], + plugins: ['remove_button'] +}); + +groupsCache.get(function(groups) { + jQuery('[data-selectize=groups]').each(function() { + this.selectize.load(function(callback) { + callback(groups); + }); - jQuery("#indirectPermissionsDetailsShow").click(function(){ - jQuery("#indirectPermissionsDetailsShow").hide(); - jQuery("#indirectPermissionsDetailsHide").show(); - jQuery("#indirectPermissionsDetails").show(); - return false; + jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) { + this.selectize.addItem(id); + }, this)); }); +}); + +{* *} +var usersCache = new LocalStorageCache('usersAdminList', 5*60, function(callback) { + var page = 0, + users = []; + + (function load(page){ + jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.users.getList&display=username&per_page=99999&page='+ page, function(data) { + users = users.concat(data.result.users); + + if (data.result.paging.count == data.result.paging.per_page) { + load(++page); + } + else { + callback(users); + } + }); + }(page)); +}); + +jQuery('[data-selectize=users]').selectize({ + valueField: 'id', + labelField: 'username', + searchField: ['username'], + plugins: ['remove_button'] +}); + +usersCache.get(function(users) { + jQuery('[data-selectize=users]').each(function() { + this.selectize.load(function(callback) { + callback(users); + }); - jQuery("#indirectPermissionsDetailsHide").click(function(){ - jQuery("#indirectPermissionsDetailsShow").show(); - jQuery("#indirectPermissionsDetailsHide").hide(); - jQuery("#indirectPermissionsDetails").hide(); - return false; + jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) { + this.selectize.addItem(id); + }, this)); }); }); -{/literal}{/footer_script} +}()); +{/footer_script}

{$CATEGORIES_NAV} › {'Edit album'|@translate} {$TABSHEET_TITLE}

@@ -58,9 +94,8 @@ jQuery(document).ready(function() { {if count($groups) > 0} {'Permission granted for groups'|@translate}
- + {else} {'There is no group in this gallery.'|@translate} {'Group management'|@translate} {/if} @@ -69,12 +104,11 @@ jQuery(document).ready(function() {

{'Permission granted for users'|@translate}
- +

-{if isset($nb_users_granted_indirect)} +{if isset($nb_users_granted_indirect) && $nb_users_granted_indirect>0}

{'%u users have automatic permission because they belong to a granted group.'|@translate:$nb_users_granted_indirect} diff --git a/admin/themes/default/template/picture_modify.tpl b/admin/themes/default/template/picture_modify.tpl index dd49fbd86..50392f7ab 100644 --- a/admin/themes/default/template/picture_modify.tpl +++ b/admin/themes/default/template/picture_modify.tpl @@ -10,7 +10,7 @@ {footer_script} (function(){ {* *} -var categoriesCache = new LocalStorageCache('categoriesAdminList', 60, function(callback) { +var categoriesCache = new LocalStorageCache('categoriesAdminList', 5*60, function(callback) { jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { callback(data.result.categories); }); @@ -24,25 +24,19 @@ jQuery('[data-selectize=categories]').selectize({ }); categoriesCache.get(function(categories) { - var selects = jQuery('[data-selectize=categories]'); - - jQuery.each(categories, function(i, category) { - selects.each(function() { - this.selectize.addOption(category); + jQuery('[data-selectize=categories]').each(function() { + this.selectize.load(function(callback) { + callback(categories); }); - }); - - selects.each(function() { - var that = this; - jQuery.each(jQuery(this).data('value'), function(i, id) { - that.selectize.addItem(id); - }); + jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) { + this.selectize.addItem(id); + }, this)); }); }); {* *} -var tagsCache = new LocalStorageCache('tagsAdminList', 60, function(callback) { +var tagsCache = new LocalStorageCache('tagsAdminList', 5*60, function(callback) { jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.tags.getAdminList', function(data) { var tags = data.result.tags; @@ -70,20 +64,14 @@ jQuery('[data-selectize=tags]').selectize({ }); tagsCache.get(function(tags) { - var selects = jQuery('[data-selectize=tags]'); - - jQuery.each(tags, function(i, tag) { - selects.each(function() { - this.selectize.addOption(tag); + jQuery('[data-selectize=tags]').each(function() { + this.selectize.load(function(callback) { + callback(tags); }); - }); - - selects.each(function() { - var that = this; - jQuery.each(jQuery(this).data('value'), function(i, tag) { - that.selectize.addItem(tag.id); - }); + jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, tag) { + this.selectize.addItem(tag.id); + }, this)); }); }); -- cgit v1.2.3