Load tags for tokeninput directly in html page. Ajax is too slow.

git-svn-id: http://piwigo.org/svn/trunk@11039 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
patdenice 2011-05-25 09:00:46 +00:00
commit c9b7beb12f
9 changed files with 76 additions and 80 deletions

View file

@ -44,19 +44,6 @@ check_status(ACCESS_ADMINISTRATOR);
// | Direct actions |
// +-----------------------------------------------------------------------+
// tags
if (isset($_GET['fckb_tags']))
{
$query = '
SELECT
id AS tag_id,
name AS tag_name
FROM '.TAGS_TABLE.'
;';
echo json_encode(get_fckb_taglist($query));
exit();
}
// theme changer
if (isset($_GET['change_theme']))
{

View file

@ -360,6 +360,18 @@ if (in_array($page['tab'], $tab_codes))
$tabsheet->select($page['tab']);
$tabsheet->assign();
// +-----------------------------------------------------------------------+
// | tags |
// +-----------------------------------------------------------------------+
$query = '
SELECT
id AS tag_id,
name AS tag_name
FROM '.TAGS_TABLE.'
;';
$template->assign('tags', get_taglist($query));
// +-----------------------------------------------------------------------+
// | open specific mode |
// +-----------------------------------------------------------------------+

View file

@ -137,7 +137,7 @@ DELETE
}
else
{
$tag_ids = get_fckb_tag_ids($_POST['add_tags']);
$tag_ids = get_tag_ids($_POST['add_tags']);
add_tags($tag_ids, $collection);
if ('with no tag' == $page['prefilter'])

View file

@ -108,7 +108,7 @@ SELECT id, date_creation
// tags management
if (isset($_POST[ 'tags-'.$row['id'] ]))
{
$tag_ids = get_fckb_tag_ids($_POST[ 'tags-'.$row['id'] ]);
$tag_ids = get_tag_ids($_POST[ 'tags-'.$row['id'] ]);
set_tags($tag_ids, $row['id']);
}
}
@ -256,7 +256,7 @@ SELECT
JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
WHERE image_id = '.$row['id'].'
;';
$tag_selection = get_fckb_taglist($query);
$tag_selection = get_taglist($query);
$template->append(
'elements',

View file

@ -2097,7 +2097,7 @@ function get_active_menu($menu_page)
return 0;
}
function get_fckb_taglist($query)
function get_taglist($query)
{
$result = pwg_query($query);
@ -2119,7 +2119,7 @@ function get_fckb_taglist($query)
return $taglist;
}
function get_fckb_tag_ids($raw_tags)
function get_tag_ids($raw_tags)
{
// In $raw_tags we receive something like array('~~6~~', '~~59~~', 'New
// tag', 'Another new tag') The ~~34~~ means that it is an existing

View file

@ -166,7 +166,7 @@ if (isset($_POST['submit']) and count($page['errors']) == 0)
$tag_ids = array();
if (isset($_POST['tags']))
{
$tag_ids = get_fckb_tag_ids($_POST['tags']);
$tag_ids = get_tag_ids($_POST['tags']);
}
set_tags($tag_ids, $_GET['image_id']);
@ -233,7 +233,15 @@ SELECT
JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
WHERE image_id = '.$_GET['image_id'].'
;';
$tags = get_fckb_taglist($query);
$tag_selection = get_taglist($query);
$query = '
SELECT
id AS tag_id,
name AS tag_name
FROM '.TAGS_TABLE.'
;';
$tags = get_taglist($query);
// retrieving direct information about picture
$query = '
@ -267,6 +275,7 @@ $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(),

View file

@ -9,26 +9,22 @@
{combine_script id='jquery.progressBar' load='footer' path='themes/default/js/plugins/jquery.progressbar.min.js'}
{combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
{footer_script require='jquery.tokeninput'}{literal}
jQuery(document).ready(function() {
jQuery.getJSON('admin.php?fckb_tags=1', function(data) {
jQuery("#tags").tokenInput(
data,
{
{/literal}
hintText: '{'Type in a search term'|@translate}',
noResultsText: '{'No results'|@translate}',
searchingText: '{'Searching...'|@translate}',
newText: ' ({'new'|@translate})',
animateDropdown: false,
preventDuplicates: true,
allowCreation: true
{literal}
}
);
});
{footer_script require='jquery.tokeninput'}
jQuery(document).ready(function() {ldelim}
jQuery("#tags").tokenInput(
[{foreach from=$tags item=tag name=tags}{ldelim}"name":"{$tag.name}","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,
allowCreation: true
}
);
});
{/literal}{/footer_script}
{/footer_script}
{footer_script}
var nb_thumbs_page = {$nb_thumbs_page};

View file

@ -13,28 +13,24 @@ prefix = ", ";
{/if}
tag_boxes_selector = tag_boxes_selector + prefix + "#tags-" + {$element.ID};
{/foreach}
{literal}
jQuery(document).ready(function() {
jQuery.getJSON('admin.php?fckb_tags=1', function(data) {
jQuery(tag_boxes_selector).tokenInput(
data,
{
{/literal}
hintText: '{'Type in a search term'|@translate}',
noResultsText: '{'No results'|@translate}',
searchingText: '{'Searching...'|@translate}',
newText: ' ({'new'|@translate})',
animateDropdown: false,
preventDuplicates: true,
allowCreation: true
{literal}
}
);
});
$("a.preview-box").colorbox();
jQuery(document).ready(function() {ldelim}
jQuery(tag_boxes_selector).tokenInput(
[{foreach from=$tags item=tag name=tags}{ldelim}"name":"{$tag.name}","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,
allowCreation: true
}
);
jQuery("a.preview-box").colorbox();
});
{/literal}{/footer_script}
{/footer_script}
<h2>{'Batch Manager'|@translate}</h2>

View file

@ -3,26 +3,22 @@
{include file='include/datepicker.inc.tpl'}
{combine_script id='jquery.tokeninput' load='async' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'}
{footer_script require='jquery.tokeninput'}{literal}
jQuery(document).ready(function() {
jQuery.getJSON('admin.php?fckb_tags=1', function(data) {
jQuery("#tags").tokenInput(
data,
{
{/literal}
hintText: '{'Type in a search term'|@translate}',
noResultsText: '{'No results'|@translate}',
searchingText: '{'Searching...'|@translate}',
newText: ' ({'new'|@translate})',
animateDropdown: false,
preventDuplicates: true,
allowCreation: true
{literal}
}
);
});
{footer_script require='jquery.tokeninput'}
jQuery(document).ready(function() {ldelim}
jQuery("#tags").tokenInput(
[{foreach from=$tags item=tag name=tags}{ldelim}"name":"{$tag.name}","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,
allowCreation: true
}
);
});
{/literal}{/footer_script}
{/footer_script}
{footer_script}
pwg_initialization_datepicker("#date_creation_day", "#date_creation_month", "#date_creation_year", "#date_creation_linked_date", "#date_creation_action_set");
@ -142,7 +138,7 @@ pwg_initialization_datepicker("#date_creation_day", "#date_creation_month", "#da
<td><strong>{'Tags'|@translate}</strong></td>
<td>
<select id="tags" name="tags">
{foreach from=$tags item=tag}
{foreach from=$tag_selection item=tag}
<option value="{$tag.id}" class="selected">{$tag.name}</option>
{/foreach}
</select>