Ignore:
Timestamp:
Mar 6, 2010, 11:10:23 PM (14 years ago)
Author:
plg
Message:

feature 724: improved "add tags" form. Instead of a big list of checkboxes,
displays a dynamic list of tags with jQuery, with suggestions based on
existing tags and the ability to create new tags on the fly.

The change was applied only on admin/picture_modify.php for test purpose.

Note : FCBKcomplete 2.7 had a bug on "remote tag" click, and the bug was fixed
on 2.7.1. But the suggestions were not working with 2.7.1. So I took the 2.7
and applied the tiny change to make the "remove tag" click work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/picture_modify.php

    r5021 r5067  
    107107    );
    108108
     109  // In $_POST[tags] we receive something like array('~~6~~', '~~59~~', 'New
     110  // tag', 'Another new tag') The ~~34~~ means that it is an existing
     111  // tag. I've added the surrounding ~~ to permit creation of tags like "10"
     112  // or "1234" (numeric characters only)
     113  $tag_ids = array();
     114  if (isset($_POST['tags']))
     115  {
     116    foreach ($_POST['tags'] as $raw_tag)
     117    {
     118      if (preg_match('/^~~(\d+)~~$/', $raw_tag, $matches))
     119      {
     120        array_push($tag_ids, $matches[1]);
     121      }
     122      else
     123      {
     124        // we have to create a new tag
     125        array_push(
     126          $tag_ids,
     127          tag_id_from_tag_name($raw_tag)
     128          );
     129      }
     130    }
     131  }
     132 
    109133  set_tags(
    110     isset($_POST['tags']) ? $_POST['tags'] : array(),
     134    $tag_ids,
    111135    $_GET['image_id']
    112136    );
     
    170194}
    171195
     196// tags
     197$tags = array();
     198
     199$query = '
     200SELECT
     201    tag_id,
     202    name
     203  FROM '.IMAGE_TAG_TABLE.' AS it
     204    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
     205  WHERE image_id = '.$_GET['image_id'].'
     206;';
     207$result = pwg_query($query);
     208while ($row = pwg_db_fetch_assoc($result))
     209{
     210  array_push(
     211    $tags,
     212    array(
     213      'value' => '~~'.$row['tag_id'].'~~',
     214      'caption' => $row['name'],
     215      )
     216    );
     217}
     218
    172219// retrieving direct information about picture
    173220$query = '
     
    185232
    186233$image_file = $row['file'];
    187 
    188 // tags
    189 $query = '
    190 SELECT tag_id
    191   FROM '.IMAGE_TAG_TABLE.'
    192   WHERE image_id = '.$_GET['image_id'].'
    193 ;';
    194 $selected_tags = array_from_query($query, 'tag_id');
    195234
    196235// +-----------------------------------------------------------------------+
     
    204243  );
    205244
    206 $all_tags = get_all_tags();
    207 
    208 if (count($all_tags) > 0)
    209 {
    210   $tag_selection = get_html_tag_selection(
    211     $all_tags,
    212     'tags',
    213     $selected_tags
    214     );
    215 }
    216 else
    217 {
    218   $tag_selection =
    219     '<p>'.
    220     l10n('No tag defined. Use Administration>Pictures>Tags').
    221     '</p>';
    222 }
    223 
    224245$template->assign(
    225246  array(
     247    'tags' => $tags,
    226248    'U_SYNC' =>
    227249        get_root_url().'admin.php?page=picture_modify'.
     
    245267
    246268    'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'],
    247 
    248     'TAG_SELECTION' => $tag_selection,
    249269
    250270    'DESCRIPTION' =>
Note: See TracChangeset for help on using the changeset viewer.