Changeset 5188


Ignore:
Timestamp:
Mar 19, 2010, 1:50:19 PM (14 years ago)
Author:
plg
Message:

feature 724: FCBKcomplete propagated to element_set_global and
element_set_unit to manage tags.

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

Location:
trunk/admin
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/element_set_global.php

    r4731 r5188  
    149149  if (isset($_POST['add_tags']) and count($collection) > 0)
    150150  {
    151     add_tags($_POST['add_tags'], $collection);
     151    $tag_ids = get_fckb_tag_ids($_POST['add_tags']);
     152    add_tags($tag_ids, $collection);
    152153  }
    153154
     
    368369}
    369370
    370 $all_tags = get_all_tags();
    371 
    372 if (count($all_tags) > 0)
    373 {// add tags
    374   $template->assign(
    375     array(
    376       'ADD_TAG_SELECTION' => get_html_tag_selection(
    377                               $all_tags,
    378                               'add_tags'
    379                               ),
    380       )
    381     );
    382 }
    383 
    384371if (count($page['cat_elements_id']) > 0)
    385372{
  • trunk/admin/element_set_unit.php

    r4334 r5188  
    106106    if (isset($_POST[ 'tags-'.$row['id'] ]))
    107107    {
    108       set_tags($_POST[ 'tags-'.$row['id'] ], $row['id']);
     108      $tag_ids = get_fckb_tag_ids($_POST[ 'tags-'.$row['id'] ]);
     109      set_tags($tag_ids, $row['id']);
    109110    }
    110111  }
     
    208209    $src = get_thumbnail_url($row);
    209210
     211    // creation date
     212    if (!empty($row['date_creation']))
     213    {
     214      list($year,$month,$day) = explode('-', $row['date_creation']);
     215    }
     216    else
     217    {
     218      list($year,$month,$day) = array('',0,0);
     219    }
     220
    210221    $query = '
    211 SELECT tag_id
    212   FROM '.IMAGE_TAG_TABLE.'
     222SELECT
     223    tag_id,
     224    name AS tag_name
     225  FROM '.IMAGE_TAG_TABLE.' AS it
     226    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
    213227  WHERE image_id = '.$row['id'].'
    214228;';
    215     $selected_tags = array_from_query($query, 'tag_id');
    216 
    217     // creation date
    218     if (!empty($row['date_creation']))
    219     {
    220       list($year,$month,$day) = explode('-', $row['date_creation']);
    221     }
    222     else
    223     {
    224       list($year,$month,$day) = array('',0,0);
    225     }
    226 
    227     if (count($all_tags) > 0)
    228     {
    229       $tag_selection = get_html_tag_selection(
    230         $all_tags,
    231         'tags-'.$row['id'],
    232         $selected_tags
    233         );
    234     }
    235     else
    236     {
    237       $tag_selection =
    238         '<p>'.
    239         l10n('No tag defined. Use Administration>Pictures>Tags').
    240         '</p>';
    241     }
     229    $tag_selection = get_fckb_taglist($query);
    242230
    243231    $template->append(
     
    259247        'DATE_CREATION_DAY' => (int)$day,
    260248
    261         'TAG_SELECTION' => $tag_selection,
     249        'TAGS' => $tag_selection,
    262250        )
    263251      );
  • trunk/admin/include/functions.php

    r5173 r5188  
    19821982  return 0;
    19831983}
     1984
     1985function get_fckb_taglist($query)
     1986{
     1987  $result = pwg_query($query);
     1988  $taglist = array();
     1989  while ($row = pwg_db_fetch_assoc($result))
     1990  {
     1991    array_push(
     1992      $taglist,
     1993      array(
     1994        'caption' => $row['tag_name'],
     1995        'value' => '~~'.$row['tag_id'].'~~',
     1996        )
     1997      );
     1998  }
     1999 
     2000  return $taglist;
     2001}
     2002
     2003function get_fckb_tag_ids($raw_tags)
     2004{
     2005  // In $raw_tags we receive something like array('~~6~~', '~~59~~', 'New
     2006  // tag', 'Another new tag') The ~~34~~ means that it is an existing
     2007  // tag. I've added the surrounding ~~ to permit creation of tags like "10"
     2008  // or "1234" (numeric characters only)
     2009
     2010  $tag_ids = array();
     2011 
     2012  foreach ($raw_tags as $raw_tag)
     2013  {
     2014    if (preg_match('/^~~(\d+)~~$/', $raw_tag, $matches))
     2015    {
     2016      array_push($tag_ids, $matches[1]);
     2017    }
     2018    else
     2019    {
     2020      // we have to create a new tag
     2021      array_push(
     2022        $tag_ids,
     2023        tag_id_from_tag_name($raw_tag)
     2024        );
     2025    }
     2026  }
     2027
     2028  return $tag_ids;
     2029}
    19842030?>
  • trunk/admin/picture_modify.php

    r5067 r5188  
    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)
     109  // time to deal with tags
    113110  $tag_ids = array();
    114111  if (isset($_POST['tags']))
    115112  {
    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  
    133   set_tags(
    134     $tag_ids,
    135     $_GET['image_id']
    136     );
     113    $tag_ids = get_fckb_tag_ids($_POST['tags']);
     114  }
     115  set_tags($tag_ids, $_GET['image_id']);
    137116
    138117  array_push($page['infos'], l10n('Picture informations updated'));
     
    195174
    196175// tags
    197 $tags = array();
    198 
    199176$query = '
    200177SELECT
    201178    tag_id,
    202     name
     179    name AS tag_name
    203180  FROM '.IMAGE_TAG_TABLE.' AS it
    204181    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
    205182  WHERE image_id = '.$_GET['image_id'].'
    206183;';
    207 $result = pwg_query($query);
    208 while ($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 }
     184$tags = get_fckb_taglist($query);
    218185
    219186// retrieving direct information about picture
  • trunk/admin/themes/default/template/element_set_global.tpl

    r5123 r5188  
    55<script type="text/javascript">
    66  pwg_initialization_datepicker("#date_creation_day", "#date_creation_month", "#date_creation_year", "#date_creation_linked_date", "#date_creation_action_set");
     7</script>
     8{/literal}
     9
     10{known_script id="jquery.fcbkcomplete" src=$ROOT_URL|@cat:"themes/default/js/plugins/jquery.fcbkcomplete.js"}
     11{literal}
     12<script type="text/javascript">
     13  $(document).ready(function() {
     14    $("#tags").fcbkcomplete({
     15      json_url: "admin.php?fckb_tags=1",
     16      cache: false,
     17      filter_case: true,
     18      filter_hide: true,
     19      firstselected: true,
     20      filter_selected: true,
     21      maxitems: 10,
     22      newel: true
     23    });
     24  });
    725</script>
    826{/literal}
     
    109127      <tr>
    110128        <td>{'add tags'|@translate}</td>
    111         <td>{if !empty($ADD_TAG_SELECTION)}{$ADD_TAG_SELECTION}{else}<p>{'No tag defined. Use Administration>Pictures>Tags'|@translate}</p>{/if}</td>
     129        <td>
     130<select id="tags" name="add_tags">
     131{foreach from=$tags item=tag}
     132  <option value="{$tag.value}" class="selected">{$tag.caption}</option>
     133{/foreach}
     134</select>
     135        </td>
    112136      </tr>
    113137
  • trunk/admin/themes/default/template/element_set_unit.tpl

    r5123 r5188  
    22{include file='include/autosize.inc.tpl'}
    33{include file='include/datepicker.inc.tpl'}
     4
     5{known_script id="jquery.fcbkcomplete" src=$ROOT_URL|@cat:"themes/default/js/plugins/jquery.fcbkcomplete.js"}
     6{literal}
     7<script type="text/javascript">
     8  $(document).ready(function() {
     9    $(".tags").fcbkcomplete({
     10      json_url: "admin.php?fckb_tags=1",
     11      cache: false,
     12      filter_case: true,
     13      filter_hide: true,
     14      firstselected: true,
     15      filter_selected: true,
     16      maxitems: 10,
     17      newel: true
     18    });
     19  });
     20</script>
     21{/literal}
     22
    423
    524<h2>{'Batch management'|@translate}</h2>
     
    7695    <tr>
    7796      <td><strong>{'Tags'|@translate}</strong></td>
    78       <td>{$element.TAG_SELECTION}</td>
     97      <td>
     98
     99<select class="tags" name="tags-{$element.ID}">
     100{foreach from=$element.TAGS item=tag}
     101  <option value="{$tag.value}" class="selected">{$tag.caption}</option>
     102{/foreach}
     103</select>
     104
     105      </td>
    79106    </tr>
    80107
Note: See TracChangeset for help on using the changeset viewer.