Skip to content

Commit

Permalink
feature 724: FCBKcomplete propagated to element_set_global and
Browse files Browse the repository at this point in the history
element_set_unit to manage tags.

Note: multiple instances of FCBKcomplete on the same page does not work as
good as a single instance.

git-svn-id: http://piwigo.org/svn/trunk@5188 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Mar 19, 2010
1 parent b7fee65 commit 3a076f4
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 79 deletions.
17 changes: 2 additions & 15 deletions admin/element_set_global.php
Expand Up @@ -148,7 +148,8 @@

if (isset($_POST['add_tags']) and count($collection) > 0)
{
add_tags($_POST['add_tags'], $collection);
$tag_ids = get_fckb_tag_ids($_POST['add_tags']);
add_tags($tag_ids, $collection);
}

if (isset($_POST['del_tags']) and count($collection) > 0)
Expand Down Expand Up @@ -367,20 +368,6 @@
display_select_cat_wrapper($query, array(), 'dissociate_options', true);
}

$all_tags = get_all_tags();

if (count($all_tags) > 0)
{// add tags
$template->assign(
array(
'ADD_TAG_SELECTION' => get_html_tag_selection(
$all_tags,
'add_tags'
),
)
);
}

if (count($page['cat_elements_id']) > 0)
{
// remove tags
Expand Down
36 changes: 12 additions & 24 deletions admin/element_set_unit.php
Expand Up @@ -105,7 +105,8 @@
// tags management
if (isset($_POST[ 'tags-'.$row['id'] ]))
{
set_tags($_POST[ 'tags-'.$row['id'] ], $row['id']);
$tag_ids = get_fckb_tag_ids($_POST[ 'tags-'.$row['id'] ]);
set_tags($tag_ids, $row['id']);
}
}

Expand Down Expand Up @@ -207,13 +208,6 @@

$src = get_thumbnail_url($row);

$query = '
SELECT tag_id
FROM '.IMAGE_TAG_TABLE.'
WHERE image_id = '.$row['id'].'
;';
$selected_tags = array_from_query($query, 'tag_id');

// creation date
if (!empty($row['date_creation']))
{
Expand All @@ -224,21 +218,15 @@
list($year,$month,$day) = array('',0,0);
}

if (count($all_tags) > 0)
{
$tag_selection = get_html_tag_selection(
$all_tags,
'tags-'.$row['id'],
$selected_tags
);
}
else
{
$tag_selection =
'<p>'.
l10n('No tag defined. Use Administration>Pictures>Tags').
'</p>';
}
$query = '
SELECT
tag_id,
name AS tag_name
FROM '.IMAGE_TAG_TABLE.' AS it
JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
WHERE image_id = '.$row['id'].'
;';
$tag_selection = get_fckb_taglist($query);

$template->append(
'elements',
Expand All @@ -258,7 +246,7 @@
'DATE_CREATION_MONTH' => (int)$month,
'DATE_CREATION_DAY' => (int)$day,

'TAG_SELECTION' => $tag_selection,
'TAGS' => $tag_selection,
)
);
}
Expand Down
46 changes: 46 additions & 0 deletions admin/include/functions.php
Expand Up @@ -1981,4 +1981,50 @@ function get_active_menu($menu_page)
}
return 0;
}

function get_fckb_taglist($query)
{
$result = pwg_query($query);
$taglist = array();
while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$taglist,
array(
'caption' => $row['tag_name'],
'value' => '~~'.$row['tag_id'].'~~',
)
);
}

return $taglist;
}

function get_fckb_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
// tag. I've added the surrounding ~~ to permit creation of tags like "10"
// or "1234" (numeric characters only)

$tag_ids = array();

foreach ($raw_tags as $raw_tag)
{
if (preg_match('/^~~(\d+)~~$/', $raw_tag, $matches))
{
array_push($tag_ids, $matches[1]);
}
else
{
// we have to create a new tag
array_push(
$tag_ids,
tag_id_from_tag_name($raw_tag)
);
}
}

return $tag_ids;
}
?>
43 changes: 5 additions & 38 deletions admin/picture_modify.php
Expand Up @@ -106,34 +106,13 @@
array($data)
);

// In $_POST[tags] we receive something like array('~~6~~', '~~59~~', 'New
// tag', 'Another new tag') The ~~34~~ means that it is an existing
// tag. I've added the surrounding ~~ to permit creation of tags like "10"
// or "1234" (numeric characters only)
// time to deal with tags
$tag_ids = array();
if (isset($_POST['tags']))
{
foreach ($_POST['tags'] as $raw_tag)
{
if (preg_match('/^~~(\d+)~~$/', $raw_tag, $matches))
{
array_push($tag_ids, $matches[1]);
}
else
{
// we have to create a new tag
array_push(
$tag_ids,
tag_id_from_tag_name($raw_tag)
);
}
}
$tag_ids = get_fckb_tag_ids($_POST['tags']);
}

set_tags(
$tag_ids,
$_GET['image_id']
);
set_tags($tag_ids, $_GET['image_id']);

array_push($page['infos'], l10n('Picture informations updated'));
}
Expand Down Expand Up @@ -194,27 +173,15 @@
}

// tags
$tags = array();

$query = '
SELECT
tag_id,
name
name AS tag_name
FROM '.IMAGE_TAG_TABLE.' AS it
JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
WHERE image_id = '.$_GET['image_id'].'
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$tags,
array(
'value' => '~~'.$row['tag_id'].'~~',
'caption' => $row['name'],
)
);
}
$tags = get_fckb_taglist($query);

// retrieving direct information about picture
$query = '
Expand Down
26 changes: 25 additions & 1 deletion admin/themes/default/template/element_set_global.tpl
Expand Up @@ -7,6 +7,24 @@
</script>
{/literal}

{known_script id="jquery.fcbkcomplete" src=$ROOT_URL|@cat:"themes/default/js/plugins/jquery.fcbkcomplete.js"}
{literal}
<script type="text/javascript">
$(document).ready(function() {
$("#tags").fcbkcomplete({
json_url: "admin.php?fckb_tags=1",
cache: false,
filter_case: true,
filter_hide: true,
firstselected: true,
filter_selected: true,
maxitems: 10,
newel: true
});
});
</script>
{/literal}

<h2>{'Batch management'|@translate}</h2>

<h3>{$CATEGORIES_NAV}</h3>
Expand Down Expand Up @@ -108,7 +126,13 @@

<tr>
<td>{'add tags'|@translate}</td>
<td>{if !empty($ADD_TAG_SELECTION)}{$ADD_TAG_SELECTION}{else}<p>{'No tag defined. Use Administration>Pictures>Tags'|@translate}</p>{/if}</td>
<td>
<select id="tags" name="add_tags">
{foreach from=$tags item=tag}
<option value="{$tag.value}" class="selected">{$tag.caption}</option>
{/foreach}
</select>
</td>
</tr>

{if !empty($DEL_TAG_SELECTION)}
Expand Down
29 changes: 28 additions & 1 deletion admin/themes/default/template/element_set_unit.tpl
Expand Up @@ -2,6 +2,25 @@
{include file='include/autosize.inc.tpl'}
{include file='include/datepicker.inc.tpl'}

{known_script id="jquery.fcbkcomplete" src=$ROOT_URL|@cat:"themes/default/js/plugins/jquery.fcbkcomplete.js"}
{literal}
<script type="text/javascript">
$(document).ready(function() {
$(".tags").fcbkcomplete({
json_url: "admin.php?fckb_tags=1",
cache: false,
filter_case: true,
filter_hide: true,
firstselected: true,
filter_selected: true,
maxitems: 10,
newel: true
});
});
</script>
{/literal}


<h2>{'Batch management'|@translate}</h2>

<h3>{$CATEGORIES_NAV}</h3>
Expand Down Expand Up @@ -75,7 +94,15 @@

<tr>
<td><strong>{'Tags'|@translate}</strong></td>
<td>{$element.TAG_SELECTION}</td>
<td>

<select class="tags" name="tags-{$element.ID}">
{foreach from=$element.TAGS item=tag}
<option value="{$tag.value}" class="selected">{$tag.caption}</option>
{/foreach}
</select>

</td>
</tr>

<tr>
Expand Down

0 comments on commit 3a076f4

Please sign in to comment.