Ignore:
Timestamp:
Jun 19, 2013, 2:43:41 PM (11 years ago)
Author:
mistic100
Message:

all collections are "active", display a menu when adding to a collection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserCollections/template/thumbnails_css_js.tpl

    r21382 r23361  
    1 {html_style}
    2 #thumbnails li {ldelim} position:relative !important;display:inline-block; }
    3 li .addCollection {ldelim} width:100%;height:16px;display:none;position:absolute;top:0;background:rgba(0,0,0,0.8);padding:2px;border-radius:2px;font-size:10px;z-index:100 !important;color:#eee;white-space:nowrap; }
    4 li:hover .addCollection {ldelim} display:block !important; }
    5 {/html_style}
    6 
    7 {if not $NO_AJAX}
     1{combine_css path=$USER_COLLEC_PATH|@cat:"template/style_thumbnails.css"}
     2
     3{* <!-- all pages but collection edit page --> *}
     4{if not $UC_IN_EDIT}
    85{footer_script require='jquery'}
    9 jQuery(".addCollection").click(function() {ldelim}
    10   var $trigger = jQuery(this);
    11   var toggle_id = $trigger.data("id");
    12   var method = $trigger.data("stat");
    13  
    14   if (method != "add" && method != "remove") {ldelim}
    15     $trigger.html("{'Un unknown error occured'|@translate}");
     6var $cdm = jQuery("#collectionsDropdown");
     7
     8{if not $IN_PICTURE}
     9$cdm.on("mouseleave", function() {ldelim}
     10  $cdm.hide();
     11});
     12{/if}
     13
     14// click on "create collection" button
     15$cdm.find("a.new").on("click", function(event) {ldelim}
     16  jQuery(this).hide().next().show().focus();
     17  event.stopPropagation();
     18  return false;
     19});
     20
     21// events on "new collection" input
     22$cdm.find("input.new").on({ldelim}
     23  // ENTER pressed
     24  "keyup": function(event) {ldelim}
     25    if (event.which != 13) return;
     26   
     27    jQuery(this).hide().prev().show();
     28    var name = jQuery(this).val();
     29    jQuery(this).val("{'Name'|@translate}");
     30   
     31    if (name == "") return;
     32   
     33    jQuery.ajax({ldelim}
     34      type: "GET",
     35      dataType: "json",
     36      url: "{$ROOT_URL}ws.php",
     37      data: {ldelim}
     38        format: "json",
     39        method: "pwg.collections.create",
     40        name: name,
     41        active: 1,
     42      },
     43      success: function(data) {ldelim}
     44        if (data.stat == 'ok') {ldelim}
     45          var col = data.result;
     46          var html = '<span>&#9733;</span> <a class="add" data-id="'+ col.id +'">'+ col.name +'</a> '
     47            +'<span class="menuInfoCat">[<span class="nbImagesCollec-'+ col.id +'">'+ col.nb_images +'</span>]</span> '
     48            +'<a class="remove" data-id="'+ col.id +'">{'(remove)'|@translate}</a>'
     49            +'<br>';
     50         
     51          $cdm.children(".switchBoxFooter").before(html);
     52          $cdm.children(".noCollecMsg").remove();
     53        }
     54        else {ldelim}
     55          alert(data.message);
     56        }
     57      },
     58      error: function() {ldelim}
     59        alert("{'Un unknown error occured'|@translate}");
     60      }
     61    });
     62   
    1663    return false;
     64  },
     65  // prevent click propagation
     66  "click": function(event) {ldelim}
     67    event.stopPropagation();
     68  },
     69  // remove help on focus
     70  "focus": function() {ldelim}
     71    if (jQuery(this).val() == "{'Name'|@translate}") jQuery(this).val("");
     72  },
     73  // restore help on blur
     74  "blur" : function() {ldelim}
     75    if (jQuery(this).val() == "") jQuery(this).val("{'Name'|@translate}");
    1776  }
     77});
     78
     79// add and remove links (delegate for new collections)
     80$cdm.on("click", ".add, .remove", function() {ldelim}
     81  var img_id = $cdm.data("img_id");
     82  var col_id = jQuery(this).data("id");
     83  var method = jQuery(this).hasClass("add") ? "pwg.collections.addImages" : "pwg.collections.removeImages";
    1884 
    1985  jQuery.ajax({ldelim}
     
    2187    dataType: "json",
    2288    url: "{$ROOT_URL}ws.php",
    23     data: {ldelim} "format": "json", "method": "pwg.collections."+method+"Images", "col_id": {$AJAX_COL_ID}, "image_ids": toggle_id },
     89    data: {ldelim}
     90      format: "json",
     91      method: method,
     92      col_id: col_id,
     93      image_ids: img_id
     94    },
    2495    success: function(data) {ldelim}
    25       if (data['stat'] == 'ok') {ldelim}
    26         if (method == "add") {ldelim}
    27           $trigger.children(".uc_remove").show();
    28           $trigger.children(".uc_add").hide();
    29           $trigger.data("stat", "remove");
    30         }
    31         else if (method == "remove") {ldelim}
    32         {if $UC_IN_EDIT}
    33           $trigger.parent("li").hide("fast", function() {ldelim} $(this).remove() });
    34           if (typeof batchdown_count != 'undefined') batchdown_count-=1;
    35         {else}
    36           $trigger.children(".uc_remove").hide();
    37           $trigger.children(".uc_add").show();
    38           $trigger.data("stat", "add");
    39         {/if}
    40         }
     96      if (data.stat == 'ok') {ldelim}
     97        // update col counters
     98        jQuery(".nbImagesCollec-"+col_id).html(data.result.nb_images);
    4199       
    42         jQuery(".nbImagesCollec").html(data['result']['nb_images']);
     100        // update item datas
     101        var $target = jQuery(".addCollection[data-id='"+ img_id +"']");
     102        var col_ids = $target.data("cols");
     103        if (method == "pwg.collections.addImages" && col_ids.indexOf(col_id) == -1)
     104          col_ids[ col_ids.length ] = col_id;
     105        else
     106          col_ids.splice(col_ids.indexOf(col_id), 1);
     107        $target.data("col", col_ids);
    43108      }
    44109      else {ldelim}
    45         $trigger.html("{'Un unknown error occured'|@translate}");
     110        alert(data.message);
    46111      }
    47112    },
    48113    error: function() {ldelim}
    49       $trigger.html("{'Un unknown error occured'|@translate}");
    50     }
    51   });
    52  
     114      alert("{'Un unknown error occured'|@translate}");
     115    }
     116  });
     117 
     118  $cdm.hide();
     119  return false;
     120});
     121
     122// main button, open the menu
     123jQuery(".addCollection").on("click", function(event) {ldelim}
     124  var img_id = jQuery(this).data("id");
     125  var col_ids = jQuery(this).data("cols");
     126 
     127  $cdm.data("img_id", img_id);
     128 
     129  $cdm.children(".add").each(function() {ldelim}   
     130    if (col_ids.indexOf($(this).data("id")) != -1) {ldelim}
     131      $(this).css("font-weight", "bold").next().next().show();
     132    }
     133    else {ldelim}
     134      $(this).css("font-weight", "normal").next().next().hide();
     135    }
     136  });
     137 
     138  {if not $IN_PICTURE}
     139  $cdm.css({ldelim}
     140    "top": event.pageY-5-$(window).scrollTop(),
     141    "left": Math.min(event.pageX-jQuery(window).scrollLeft()-20, jQuery(window).width()-$cdm.outerWidth(true)-5)
     142  });
     143  $cdm.show();
     144  {/if}
     145 
     146  return false;
     147});
     148
     149// try to respect theme colors
     150$cdm.children(".switchBoxFooter").css("border-top-color", $cdm.children(".switchBoxTitle").css("border-bottom-color"));
     151{/footer_script}
     152
     153<div id="collectionsDropdown" class="switchBox">
     154  <div class="switchBoxTitle">{'Collections'|@translate}</div>
     155 
     156  {foreach from=$COLLECTIONS item=col}
     157    <span>&#9733;</span> <a class="add" data-id="{$col.id}">{$col.name}</a>
     158    <span class="menuInfoCat">[<span class="nbImagesCollec-{$col.id}">{$col.nb_images}</span>]</span>
     159    <a class="remove" data-id="{$col.id}">{'(remove)'|@translate}</a>
     160    <br>
     161  {foreachelse}
     162    <span class="noCollecMsg">{'You have no collection'|@translate}</span>
     163  {/foreach}
     164 
     165  <div class="switchBoxFooter">
     166  <span>&#10010;</span> <a class="new">{'Create a new collection'|@translate}</a>
     167  <input class="new" value="{'Name'|@translate}" size="25"/>
     168  </div>
     169</div>
     170
     171{* <!-- collection edit page --> *}
     172{else}
     173{footer_script require='jquery'}
     174jQuery(".addCollection").on("click", function(event) {ldelim}
     175  var $trigger = jQuery(this);
     176  var img_id = jQuery(this).data("id");
     177  var col_id = {$collection.ID};
     178 
     179  jQuery.ajax({ldelim}
     180    type: "GET",
     181    dataType: "json",
     182    url: "{$ROOT_URL}ws.php",
     183    data: {ldelim}
     184      format: "json",
     185      method: "pwg.collections.removeImages",
     186      col_id: col_id,
     187      image_ids: img_id
     188    },
     189    success: function(data) {ldelim}
     190      if (data.stat == 'ok') {ldelim}
     191        $trigger.parent("li").hide("fast", function() {ldelim}
     192          jQuery(this).remove();
     193          if (typeof GThumb != "undefined") GThumb.build();
     194        });
     195       
     196        jQuery(".nbImagesCollec-"+col_id).html(data.result.nb_images);
     197        if (typeof batchdown_count != 'undefined') batchdown_count = data.result.nb_images;
     198      }
     199      else {ldelim}
     200        alert(data.message);
     201      }
     202    },
     203    error: function() {ldelim}
     204      alert("{'Un unknown error occured'|@translate}");
     205    }
     206  });
     207 
     208  // not working, the event is fired twice
     209  event.stopPropagation();
     210  event.preventDefault();
    53211  return false;
    54212});
Note: See TracChangeset for help on using the changeset viewer.