I want to get the values of stop events in two conditions :
1. Wanted to get the default values after page load.
2. Wanted to get the values after the user has stopped sliding to angularjs.
angular.module('myApp').
controller('efficiencyController', function ($scope, $http, $sessionStorage, $window, $location, useragent, $timeout, $interval) {
//range slider in months
function formatDate(date) {
debugger;
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var monthIndex = date.getMonth();
var year = date.getFullYear();
return monthNames[monthIndex] + ' ' + year;
}
function formatDateTime(dateTime) {
var date = "01";
var month = ("00" + (dateTime.getMonth() + 1)).slice(-2);
var year = dateTime.getFullYear();
var hour = ("00" + dateTime.getHours()).slice(-2);
var minutes = ("00" + dateTime.getMinutes()).slice(-2);
var seconds = ("00" + dateTime.getSeconds()).slice(-2);
return date + "-" + month + "-" + year + " " + hour + ":" + minutes + ":" + seconds;
}
debugger;
$scope.values = [new Date('2019-04-01').getTime(), new Date(new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-01').getTime()]
$scope.start = formatDateTime(new Date($scope.values[0]));
$scope.end = formatDateTime(new Date($scope.values[1]));
$(function () {
$scope.range = {};
$("#slider-range").slider({
range: true,
min: new Date('2019-01-01').getTime() + 86400000,
max: new Date('2019-12-01').getTime() + 86400000,
step: 86400000,
values: [new Date('2019-04-01').getTime(), new Date(new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-01').getTime()],
slide: function (event, ui) {
$("#amount").val(formatDate(new Date(ui.values[0])) + '-' + formatDate(new Date(ui.values[1])));
},
stop: function (event, ui) {
debugger;
var start = formatDateTime(new Date(ui.values[0]));
var end = formatDateTime(new Date(ui.values[1]));
$('#lblStartDateTime').html(start);
$('#lblEndDateTime').html(end);
//$("#amount").val(formatDate(new Date(ui.values[0])) + '-' + formatDate(new Date(ui.values[1])));
$.ajax({
data: { MinValue: start, MaxValue: end },
type: "post",
url: apiUrl + "/api/Warehouse/addMinMaxValues",
success: function (data) {
//alert("Data Save: " + data);
}
});
}
});
$("#amount").val(formatDate((new Date($("#slider-range").slider("values", 0)))) +
" - " + formatDate((new Date($("#slider-range").slider("values", 1)))));
});
});