Subversion Repositories SmartDukaan

Rev

Rev 26731 | Rev 26744 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
26738 amit.gupta 1
$(".web-listing").live('click', function() {
2
	loadWebListing("main-content");
3
});
4
$("a.listing-details").live('click', function() {
5
	var webListingId = $(this).data("id");
6
	doAjaxRequestHandler(`${context}/web-listing/${webListingId}`, "GET", function(response) {
7
		$('.web-products-container').html(response);
26731 amit.gupta 8
	});
26738 amit.gupta 9
 
10
})
11
 
12
$("#update-rank").live('click', function(){
13
	if(confirm("Are you sure you want to update ranks?")) {
14
		var webListingId=$(this).data("id");
15
		var webProductIds=[];
16
		$("#web-product-listing-tbody").find("tr").each(function(){
17
			console.log(this);
18
			webProductIds.push($(this).data("id"));
19
		});
20
		doPostAjaxRequestWithJsonHandler(`${context}/web-listing/order/${webListingId}`, JSON.stringify(webProductIds), function(response) {
21
			$('.web-products-container').html(response);
22
		});
23
	}
26731 amit.gupta 24
});
26738 amit.gupta 25
$("#add-listing").live('click', function() {
26
	var webListingId=$(this).data("id");
27
	var entityIds = [entityId];
26731 amit.gupta 28
 
26738 amit.gupta 29
	var entityIdTxt=$("#entityData").val();
30
	if(entityIdTxt.length > 0) {
31
		if(entityIdTxt.indexOf(",") > 0) {
32
			entityIds = entityIdTxt.split(",");
33
		}
34
	} else {
35
		alert("Please enter items");
36
		return;
37
	}
38
	json = [];
39
	for(var e of entityIds) {
40
		json.push({webListingId:webListingId, entityId: e});
41
	}
42
	console.log(json);
43
	console.log(JSON.stringify(json))
44
	doPostAjaxRequestWithJsonHandler(`${context}/web-product-listing/add`, JSON.stringify(json), function(response) {
45
		$('.web-products-container').html(response);
46
	});
47
 
48
});
49
 
26731 amit.gupta 50
function loadWebListing(domId) {
51
	doAjaxRequestHandler(context + "/web-listing", "GET", function(response) {
52
		$('#' + domId).html(response);
53
	});
54
}
26738 amit.gupta 55
function addWebListing() {
56
	webListingTitle = $("#web-listing-title").val();
57
	webListingUrl = $("#web-listing-url").val();
26731 amit.gupta 58
	json = {title:webListingTitle, url : webListingUrl};
26738 amit.gupta 59
	doPostAjaxRequestWithJsonHandler(context + "/web-listing/add", JSON.stringify(json), function(response) {
60
		$('#main-content').html(response);
26731 amit.gupta 61
	});
62
	return false;
63
}
64
 
65
 
26738 amit.gupta 66
$(".grab").live('mousedown', function (e) {
67
    var tr = $(e.target).closest("TR"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
68
    b.addClass("grabCursor").css("userSelect", "none");
69
    tr.addClass("grabbed");
70
    function move (e) {
71
    	console.log(Math.abs(e.pageY - sy));
72
        if (!drag && Math.abs(e.pageY - sy) < 10) return;
73
        drag = true;
74
        tr.siblings().each(function() {
75
            var s = $(this), i = s.index(), y = s.offset().top;
76
            if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
77
                if (e.pageY <= y + (s.outerHeight()/2))
78
                    tr.insertBefore(s);
79
                else
80
                    tr.insertAfter(s);
81
                return false;
82
            }
83
        });
84
    }
85
    function up (e) {
86
        if (drag && si != tr.index()) {
87
            drag = false;
88
            $("#update-rank").prop('disabled', false);
89
        }
90
        $(document).unbind("mousemove", move).unbind("mouseup", up);
91
        b.removeClass("grabCursor").css("userSelect", "none");
92
        tr.removeClass("grabbed");
93
    }
94
    $(document).mousemove(move).mouseup(up);
95
});
26731 amit.gupta 96
 
97
 
26738 amit.gupta 98
 
99