source: extensions/UserCollections/template/thumbnails_css_js.tpl @ 23361

Last change on this file since 23361 was 23361, checked in by mistic100, 11 years ago

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

File size: 6.2 KB
Line 
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}
5{footer_script require='jquery'}
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   
63    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}");
76  }
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";
84 
85  jQuery.ajax({ldelim}
86    type: "GET",
87    dataType: "json",
88    url: "{$ROOT_URL}ws.php",
89    data: {ldelim}
90      format: "json",
91      method: method,
92      col_id: col_id,
93      image_ids: img_id
94    },
95    success: function(data) {ldelim}
96      if (data.stat == 'ok') {ldelim}
97        // update col counters
98        jQuery(".nbImagesCollec-"+col_id).html(data.result.nb_images);
99       
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);
108      }
109      else {ldelim}
110        alert(data.message);
111      }
112    },
113    error: function() {ldelim}
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();
211  return false;
212});
213{/footer_script}
214{/if}
Note: See TracBrowser for help on using the repository browser.