Changeset 23944


Ignore:
Timestamp:
Jul 14, 2013, 6:43:22 PM (11 years ago)
Author:
mistic100
Message:

bug:2944 Performance issues when creating an album

Location:
trunk/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/photos_add_direct_prepare.inc.php

    r22135 r23944  
    161161// we need to know the category in which the last photo was added
    162162$selected_category = array();
    163 $selected_parent = array();
    164163
    165164$query = '
    166 SELECT
    167     category_id,
    168     id_uppercat
     165SELECT category_id
    169166  FROM '.IMAGES_TABLE.' AS i
    170167    JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id
     
    179176 
    180177  $selected_category = array($row['category_id']);
    181 
    182   if (!empty($row['id_uppercat']))
    183   {
    184     $selected_parent = array($row['id_uppercat']);
    185   }
    186178}
    187179
     
    196188  $selected_category,
    197189  'category_options'
    198   );
    199 
    200 // new category
    201 display_select_cat_wrapper(
    202   $query,
    203   $selected_parent,
    204   'category_parent_options'
    205190  );
    206191
  • trunk/admin/themes/default/template/include/add_album.inc.tpl

    r17007 r23944  
    11{footer_script}{literal}
    22jQuery(document).ready(function(){
    3   function fillCategoryListbox(selectId, selectedValue) {
    4     jQuery.getJSON(
    5       "ws.php?format=json&method=pwg.categories.getList",
    6       {
    7         recursive: true,
    8         fullname: true,
    9         format: "json",
    10       },
    11       function(data) {
    12         jQuery.each(
    13           data.result.categories,
    14           function(i,category) {
    15             var selected = null;
    16             if (category.id == selectedValue) {
    17               selected = "selected";
    18             }
    19            
    20             jQuery("<option/>")
    21               .attr("value", category.id)
    22               .attr("selected", selected)
    23               .text(category.name)
    24               .appendTo("#"+selectId)
    25               ;
    26           }
    27         );
    28       }
    29     );
    30   }
    31 
    323  jQuery(".addAlbumOpen").colorbox({
    33     inline:true,
    34     href:"#addAlbumForm",
    35     onComplete:function(){
     4    inline: true,
     5    href: "#addAlbumForm",
     6    onComplete: function() {
    367      jQuery("input[name=category_name]").focus();
     8     
     9      jQuery("#category_parent").html('<option value="0">------------</option>')
     10        .append(jQuery("#albumSelect").html())
     11        .val(jQuery("#albumSelect").val());
    3712    }
    3813  });
    3914
    40   jQuery("#addAlbumForm form").submit(function(){
     15  jQuery("#addAlbumForm form").submit(function() {
    4116      jQuery("#categoryNameError").text("");
     17     
     18      var parent_id = jQuery("select[name=category_parent] option:selected").val(),
     19          name = jQuery("input[name=category_name]").val();
    4220
    4321      jQuery.ajax({
    44         url: "ws.php?format=json&method=pwg.categories.add",
     22        url: "ws.php",
     23        dataType: 'json',
    4524        data: {
    46           parent: jQuery("select[name=category_parent] option:selected").val(),
    47           name: jQuery("input[name=category_name]").val(),
     25          format: 'json',
     26          method: 'pwg.categories.add',
     27          parent: parent_id,
     28          name: name
    4829        },
    4930        beforeSend: function() {
    5031          jQuery("#albumCreationLoading").show();
    5132        },
    52         success:function(html) {
     33        success: function(data) {
    5334          jQuery("#albumCreationLoading").hide();
    54 
    55           var newAlbum = jQuery.parseJSON(html).result.id;
    5635          jQuery(".addAlbumOpen").colorbox.close();
    5736
    58           jQuery("#albumSelect").find("option").remove();
    59           fillCategoryListbox("albumSelect", newAlbum);
    60 
    61           /* we refresh the album creation form, in case the user wants to create another album */
    62           jQuery("#category_parent").find("option").remove();
    63 
    64           jQuery("<option/>")
    65             .attr("value", 0)
    66             .text("------------")
    67             .appendTo("#category_parent")
    68           ;
    69 
    70           fillCategoryListbox("category_parent", newAlbum);
     37          var newAlbum = data.result.id,
     38              newAlbum_name = '';
     39             
     40          if (parent_id!=0) {
     41            newAlbum_name = jQuery("#category_parent").find("option[value="+ parent_id +"]").text() +' / ';
     42          }
     43          newAlbum_name+= name;
     44         
     45          var new_option = jQuery("<option/>")
     46              .attr("value", newAlbum)
     47              .attr("selected", "selected")
     48              .text(newAlbum_name);
     49             
     50          jQuery("#albumSelect").find("option").removeAttr('selected');
     51         
     52          if (parent_id==0) {
     53            jQuery("#albumSelect").append(new_option);
     54          }
     55          else {
     56            jQuery("#albumSelect").find("option[value="+ parent_id +"]").after(new_option);
     57          }
    7158
    7259          jQuery("#addAlbumForm form input[name=category_name]").val('');
    73 
    7460          jQuery("#albumSelection").show();
    7561
    7662          return true;
    7763        },
    78         error:function(XMLHttpRequest, textStatus, errorThrows) {
     64        error: function(XMLHttpRequest, textStatus, errorThrows) {
    7965            jQuery("#albumCreationLoading").hide();
    8066            jQuery("#categoryNameError").text(errorThrows).css("color", "red");
     
    9177    <form>
    9278      {'Parent album'|@translate}<br>
    93       <select id ="category_parent" name="category_parent">
    94         <option value="0">------------</option>
    95         {html_options options=$category_parent_options selected=$category_parent_options_selected}
     79      <select id="category_parent" name="category_parent">
    9680      </select>
    97 
    98       <br><br>{'Album name'|@translate}<br><input name="category_name" type="text" maxlength="255"> <span id="categoryNameError"></span>
    99       <br><br><br><input type="submit" value="{'Create'|@translate}"> <span id="albumCreationLoading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span>
     81      <br><br>
     82     
     83      {'Album name'|@translate}<br>
     84      <input name="category_name" type="text" maxlength="255"> <span id="categoryNameError"></span>
     85      <br><br><br>
     86     
     87      <input type="submit" value="{'Create'|@translate}">
     88      <span id="albumCreationLoading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span>
    10089    </form>
    10190  </div>
Note: See TracChangeset for help on using the changeset viewer.