Changeset 28494


Ignore:
Timestamp:
May 17, 2014, 2:11:47 PM (10 years ago)
Author:
mistic100
Message:

feature 3077 : use Selectize with AJAX load/cache on picture_modify

Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/picture_modify.php

    r27896 r28494  
    4343  WHERE representative_picture_id = '.$_GET['image_id'].'
    4444;';
    45 $represent_options_selected = array_from_query($query, 'id');
     45$represent_options_selected = query2array($query, null, 'id');
    4646
    4747// +-----------------------------------------------------------------------+
     
    128128{
    129129  $data = array();
    130   $data{'id'} = $_GET['image_id'];
    131   $data{'name'} = $_POST['name'];
    132   $data{'author'} = $_POST['author'];
     130  $data['id'] = $_GET['image_id'];
     131  $data['name'] = $_POST['name'];
     132  $data['author'] = $_POST['author'];
    133133  $data['level'] = $_POST['level'];
    134134
    135135  if ($conf['allow_html_descriptions'])
    136136  {
    137     $data{'comment'} = @$_POST['description'];
     137    $data['comment'] = @$_POST['description'];
    138138  }
    139139  else
    140140  {
    141     $data{'comment'} = strip_tags(@$_POST['description']);
     141    $data['comment'] = strip_tags(@$_POST['description']);
    142142  }
    143143
    144144  if (!empty($_POST['date_creation_year']))
    145145  {
    146     $data{'date_creation'} =
     146    $data['date_creation'] =
    147147      $_POST['date_creation_year']
    148148      .'-'.$_POST['date_creation_month']
     
    152152  else
    153153  {
    154     $data{'date_creation'} = null;
     154    $data['date_creation'] = null;
    155155  }
    156156
     
    470470  WHERE image_id = '.$_GET['image_id'].'
    471471;';
    472 $associate_options_selected = array_from_query($query, 'id');
    473 
    474 $query = '
    475 SELECT id,name,uppercats,global_rank
    476   FROM '.CATEGORIES_TABLE.'
    477 ;';
    478 display_select_cat_wrapper($query, $associate_options_selected, 'associate_options');
    479 display_select_cat_wrapper($query, $represent_options_selected, 'represent_options');
     472$associate_options_selected = query2array($query, null, 'id');
     473
     474$template->assign(compact('associate_options_selected', 'represent_options_selected'));
    480475
    481476trigger_action('loc_end_picture_modify');
  • trunk/admin/themes/default/template/picture_modify.tpl

    r25748 r28494  
    33{include file='include/datepicker.inc.tpl'}
    44
    5 {combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'}
    6 {combine_css path="themes/default/js/plugins/chosen.css"}
    7 
    8 {footer_script}{literal}
    9 jQuery(document).ready(function() {
    10   jQuery(".chzn-select").chosen();
    11 });
    12 {/literal}{/footer_script}
    13 
    14 {combine_css path='themes/default/js/plugins/jquery.tokeninput.css'}
    15 {combine_script id='jquery.tokeninput' load='async' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'}
    16 {footer_script require='jquery.tokeninput'}
    17 jQuery(document).ready(function() {ldelim}
    18   jQuery("#tags").tokenInput(
    19     [{foreach from=$tags item=tag name=tags}{ldelim}"name":"{$tag.name|@escape:'javascript'}","id":"{$tag.id}"{rdelim}{if !$smarty.foreach.tags.last},{/if}{/foreach}],
    20     {ldelim}
    21       hintText: '{'Type in a search term'|@translate}',
    22       noResultsText: '{'No results'|@translate}',
    23       searchingText: '{'Searching...'|@translate}',
    24       newText: ' ({'new'|@translate})',
    25       animateDropdown: false,
    26       preventDuplicates: true,
    27       allowFreeTagging: true
     5{combine_script id='LocalStorageCache' load='footer' path='admin/themes/default/js/LocalStorageCache.js'}
     6
     7{combine_script id='jquery.selectize' load='footer' path='themes/default/js/plugins/selectize.min.js'}
     8{combine_css id='jquery.selectize' path="themes/default/js/plugins/selectize.default.css"}
     9
     10{footer_script}
     11(function(){
     12{* <!-- CATEGORIES --> *}
     13var categoriesCache = new LocalStorageCache('categoriesAdminList', 60, function(callback) {
     14  jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) {
     15    callback(data.result.categories);
     16  });
     17});
     18
     19jQuery('[data-selectize=categories]').selectize({
     20  valueField: 'id',
     21  labelField: 'fullname',
     22  searchField: ['fullname'],
     23  plugins: ['remove_button']
     24});
     25
     26categoriesCache.get(function(categories) {
     27  var selects = jQuery('[data-selectize=categories]');
     28
     29  jQuery.each(categories, function(i, category) {
     30    selects.each(function() {
     31      this.selectize.addOption(category);
     32    });
     33  });
     34 
     35  selects.each(function() {
     36    var that = this;
     37
     38    jQuery.each(jQuery(this).data('value'), function(i, id) {
     39      that.selectize.addItem(id);
     40    });
     41  });
     42});
     43
     44{* <!-- TAGS --> *}
     45var tagsCache = new LocalStorageCache('tagsAdminList', 60, function(callback) {
     46  jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.tags.getAdminList', function(data) {
     47    var tags = data.result.tags;
     48   
     49    for (var i=0, l=tags.length; i<l; i++) {
     50      tags[i].id = '~~' + tags[i].id + '~~';
    2851    }
    29   );
    30 });
    31 {/footer_script}
    32 
    33 {footer_script}
     52   
     53    callback(tags);
     54  });
     55});
     56
     57jQuery('[data-selectize=tags]').selectize({
     58  valueField: 'id',
     59  labelField: 'name',
     60  searchField: ['name'],
     61  plugins: ['remove_button'],
     62  create: function(input, callback) {
     63    tagsCache.clear();
     64   
     65    callback({
     66      id: input,
     67      name: input
     68    });
     69  }
     70});
     71
     72tagsCache.get(function(tags) {
     73  var selects = jQuery('[data-selectize=tags]');
     74
     75  jQuery.each(tags, function(i, tag) {
     76    selects.each(function() {
     77      this.selectize.addOption(tag);
     78    });
     79  });
     80 
     81  selects.each(function() {
     82    var that = this;
     83
     84    jQuery.each(jQuery(this).data('value'), function(i, tag) {
     85      that.selectize.addItem(tag.id);
     86    });
     87  });
     88});
     89
     90{* <!-- DATEPICKER --> *}
    3491pwg_initialization_datepicker("#date_creation_day", "#date_creation_month", "#date_creation_year", "#date_creation_linked_date", "#date_creation_action_set");
     92}());
    3593{/footer_script}
    3694
     
    113171      <strong>{'Linked albums'|@translate}</strong>
    114172      <br>
    115       <select data-placeholder="Select albums..." class="chzn-select" multiple style="width:700px;" name="associate[]">
    116         {html_options options=$associate_options selected=$associate_options_selected}
    117       </select>
     173      <select data-selectize="categories" data-value="{$associate_options_selected|@json_encode|escape:html}"
     174        name="associate[]" multiple style="width:600px;" ></select>
    118175    </p>
    119176
     
    121178      <strong>{'Representation of albums'|@translate}</strong>
    122179      <br>
    123       <select data-placeholder="Select albums..." class="chzn-select" multiple style="width:700px;" name="represent[]">
    124         {html_options options=$represent_options selected=$represent_options_selected}
    125       </select>
     180      <select data-selectize="categories" data-value="{$represent_options_selected|@json_encode|escape:html}"
     181        name="represent[]" multiple style="width:600px;" ></select>
    126182    </p>
    127183
     
    129185      <strong>{'Tags'|@translate}</strong>
    130186      <br>
    131 <select id="tags" name="tags">
    132 {foreach from=$tag_selection item=tag}
    133   <option value="{$tag.id}" class="selected">{$tag.name}</option>
    134 {/foreach}
    135 </select>
     187      <select data-selectize="tags" data-value="{$tag_selection|@json_encode|escape:html}"
     188        name="tags[]" multiple style="width:600px;" ></select>
    136189    </p>
    137190
  • trunk/include/ws_functions/pwg.categories.php

    r26953 r28494  
    487487  GROUP BY category_id
    488488;';
    489   $nb_images_of = simple_hash_from_query($query, 'category_id', 'counter');
     489  $nb_images_of = query2array($query, 'category_id', 'counter');
    490490
    491491  $query = '
     
    506506        $row['name'],
    507507        'ws_categories_getAdminList'
     508        )
     509      );
     510    $row['fullname'] = strip_tags(
     511      get_cat_display_name_cache(
     512        $row['uppercats'],
     513        null
    508514        )
    509515      );
Note: See TracChangeset for help on using the changeset viewer.