Subversion Repositories SmartDukaan

Rev

Rev 26731 | Rev 26744 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26731 Rev 26738
Line 1... Line -...
1
$(function() {
-
 
2
	$(".web-listing").live('click', function() {
1
$(".web-listing").live('click', function() {
3
		loadWebListing("main-content");
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);
-
 
8
	});
-
 
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
	}
-
 
24
});
-
 
25
$("#add-listing").live('click', function() {
-
 
26
	var webListingId=$(this).data("id");
-
 
27
	var entityIds = [entityId];
-
 
28
 
-
 
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);
4
	});
46
	});
-
 
47
	
5
});
48
});
6
 
49
 
7
function loadWebListing(domId) {
50
function loadWebListing(domId) {
8
	doAjaxRequestHandler(context + "/web-listing", "GET", function(response) {
51
	doAjaxRequestHandler(context + "/web-listing", "GET", function(response) {
9
		$('#' + domId).html(response);
52
		$('#' + domId).html(response);
10
	});
53
	});
11
}
54
}
12
function addWebLisiting() {
55
function addWebListing() {
13
	webListingTitle = $("#web-listing-title");
56
	webListingTitle = $("#web-listing-title").val();
14
	webListingUrl = $("#web-listing-url");
57
	webListingUrl = $("#web-listing-url").val();
15
	json = {title:webListingTitle, url : webListingUrl};
58
	json = {title:webListingTitle, url : webListingUrl};
16
	doPostAjaxRequestWithJsonHandler(context + "/web-listing/add", json, function(response) {
59
	doPostAjaxRequestWithJsonHandler(context + "/web-listing/add", JSON.stringify(json), function(response) {
17
		$('#' + domId).html(response);
60
		$('#main-content').html(response);
18
	});
61
	});
19
	return false;
62
	return false;
20
}
63
}
21
 
64
 
22
 
65
 
-
 
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
});
-
 
96
 
-
 
97
 
23
 
98
 
24
 
99