Fixing Galley Script Code To Show Icon A or Icon B According to Previous User Selection In Different Pages

Fixing Galley Script Code To Show Icon A or Icon B According to Previous User Selection In Different Pages

Closed - This job posting has been filled.

Job Description

We are in need of a very urgent simple fix to an existing project.

The script is an images gallery with zipping and downloading cart. Each thumb on each gallery has a checkmark button. When the button is checked, the big picture related to the thumb is sent to a zipping and downloading cart; if unchecked, it is deleted from the zipping and downloading cart. When the user is done with his selections, he can zip and download the content of the zipping and downloading cart. When a gallery initially loads, each checkmark button is greyed; when selected it becomes red. The user can select pictures on a gallery and then load another gallery and select more pictures on that one, before zipping and downloading.


Imagine this case scenario:

user checks 3 thumbs on gallery A; so now 3 images are sent to cart via $session and $post; user loads gallery B and checks 2 thumbs on gallery B sending them to the cart; now the cart has 5 images ready to be zipped and downloaded; however, the user decides to return to gallery A and see if he wants to select some more thumbs from there;

when it goes back to gallery A, the previously selected thumbs should have a selected checkmark icon, while instead right now the script shows all thumbs unselected any time a gallery is loaded, although some images have been selected and sent to cart.

So basically, when a gallery is loaded we need to read the cart, see if any image from that gallery is in the cart and show the selected checkmark on the related thumb.

The script is a mix of js, ajax and php and we can address to the right part of code which needs to be modified.

Right now the above is coded, but there seems to be a sync problem for which when the user go back to a previous gallery where they selected some images, some images are not red checked anymore, especially when these images are on the bottom of the gallery; it seems like while the code checks if an image was selected, it does it faster than the page load and therefore it cannot match all selected images paths correctly returning undefined paths for images on the bottom of the loading list.

This is part of the code where the magic should happen, so maybe it can help you better to figure out what the problem is and how to fix it:

--------------------------------------------
boxes = $("#myDiv>div>div").children('div');

boxes.each(function(i){
if(i<(boxes.length-2)) {
my_a = $("<a href='#'></a>");
check_me_div = $("<div class='check_me' rel='-1'></div>");

check_me_div.append (my_a);
var thumb_parent = $(this).children();
thumb_parent.append(check_me_div);


var $datenumber = selected_images;
$.each($datenumber, function(idx, val) {
if (val == thumb_parent.children().find("img").attr("src")) {
var tick_icon = thumb_parent.find("div.check_me")
tick_icon.attr("rel", i);
tick_icon.addClass("clicked ");
return false;
}
});

my_a.bind ("click", function(e){
e.preventDefault();
current_index = $(this).parent().parent().parent().index();
if ($(this).parent().attr("class").indexOf ("clicked") > -1){
$(this).parent().attr ("rel",-1);
$(this).parent().removeClass("clicked");
var lastItem = $(this).parent().parent().find("img").attr("src");
var index = selected_images.indexOf(lastItem);
selected_images.splice(index, 1);
$("#images_index_array").val(selected_images);
storeCart(selected_images);

}
else {
$(this).parent().attr ("rel",current_index);
$(this).parent().addClass("clicked ");
selected_images[selected_images.length] = $(this).parent().parent().find("img").attr("src");
$("#images_index_array").val(selected_images);
storeCart(selected_images);
}

$("a.select_none").addClass("disabled");
if (selected_images.length == 0)
$(".download_link").html("Select Images for donwloading");
else {
$(".download_link").html("Download <b>" + selected_images.length + "</b> image" +

((selected_images.length == 1) ? "" : "s" ) );
$("a.select_none").removeClass("disabled");
}

});

-------------------------------------------------------

We have three full, larger projects assignments ready for the person who will fix this by quick and smartly and we can offer ongoing work on a weekly basis.