node webkit disable autolauncher in year +1 - javascript

I am working on a desktop app, and i need to disable the autolaucher if year is 2018 for exp.
var AutoLaunch = require('auto-launch');
var appLauncher = new AutoLaunch({
name: 'app'
});
appLauncher.isEnabled().then(function (enabled) {
if (enabled)
return;
return appLauncher.enable()
}).then(function (err) {
});
You have any ideas ? :)
Thanks

We can disable the auto-launch at any time using :
appLauncher.disable();
This is the full code :
var today = new Date();
var year = today.getFullYear();
var AutoLaunch = require('auto-launch');
var appLauncher = new AutoLaunch({
name: 'app',
});
appLauncher.isEnabled().then(function (enabled) {
console.log("start ", enabled);
if (enabled && year > "2016") {
return appLauncher.disable();
}
if (enabled) {
return;
}
return appLauncher.enable();
}).then(function (err) {
});
Hope this will help :)

Related

How to disable click in past days fullcalendar

I try to disable clickable past days.
I'm using dateClick but can't pass multiple args and have error:
*Uncaught TypeError: date.format is not a function
My function:
EDIT:
Dateclick function with ajax.
Now don't know how to disable click, when past days
dateClick: function (info, jsEvent, view, date) {
let currDate = info.dateStr;
// if (moment().format('YYYY-MM-DD') === currDate || date.isAfter(moment())) {
// return false;
// } else {
//
// alert('Date: ' + currDate);
// alert('ID: ' + $('#reservation-form #select-service').val());
// }
let selectServiceVal = $('select#select-service').val();
if (!selectServiceVal) {
alert('Najpierw wybierz usługę');
} else {
dateValue.val(currDate);
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: getFreeHorus + selectServiceVal + '/' + currDate,
dataType: 'json',
method: "POST",
data: {
"id": selectServiceVal,
"date": currDate
},
beforeSend: function () {
$(".calendary-loader").css('display', 'block');
},
success: function (data) {
$(".calendary-loader").css('display', 'none');
if (data.message) {
alert('Wybierz poprawną datę')
}
displayHours(data.availableHours);
},
error: function () {
$(".calendary-loader").css('display', 'none');
alert('Błąd serwera, spróbuj później')
}
});
}
}
You can use select. This is how I did mine:
select: this.handleDateClick.bind(this),
//the handleDateClick funtion
handleDateClick(arg: any) {
let todaysDate = new Date();
let formattedDate = moment(todaysDate).format("YYYY-MM-DDTHH:mm:ss"); //formatted version of todays date so a comparison can be made
let s1 = arg.startStr;
let s2 = arg.endStr;
let currentdate = moment().isUTC();
let newDateObj = moment(s1).add(15, "m").format("YYYY-MM-DDTHH:mm:ss");
if (s1 < formattedDate) {
//This checks if time is in the past. If so,
alert("This date is in the past")

no longer working gtag due to ERR_ABORTED 404 (gclidless)

GET https://www.gstatic.com/conversions/gclidless.js net::ERR_ABORTED 404
I got this error, so I was wondering what was wrong, and checked GTM and found this:
<script async src="https://gstatic.com/conversions/gclidless.js"></script>
<script>
(function ($) {
var getParam = function (p) {
var match = new RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
};
function getExpiryRecord(value)
{
var expiryPeriod = 90 * 24 * 60 * 60 * 1000; // 90 day expiry in milliseconds
var expiryDate = new Date().getTime() + expiryPeriod;
return {
value: value,
expiryDate: expiryDate
};
}
var addGclid = function ()
{
var gclidFormFields = ['input[name=gclid_field]']; // all possible gclid form field ids here
var gclidParam = getParam('gclid');
var gclidRecord = null;
var gclsrcParam = getParam('gclsrc');
var isGclsrcValid = !gclsrcParam || gclsrcParam.indexOf('aw') !== -1;
if (gclidParam && isGclsrcValid) {
gclidRecord = getExpiryRecord(gclidParam);
localStorage.setItem('gclid', JSON.stringify(gclidRecord));
}
var gclid = gclidRecord || JSON.parse(localStorage.getItem('gclid'));
var isGclidValid = gclid && new Date().getTime() < gclid.expiryDate;
if (isGclidValid) {
$('input[name=gclid_field]').val(gclid.value);
}
}
$(document).ready(function () {
$('form').prepend('<input type="hidden" name="gclid_field" style="display: none;" data-added-by="tagmanager.google-add-gclid">');
});
$(document).ready(function() {
window.setUpGclidless();
$(document).on('submit-success', 'form', function(event, postdata) {
window.sendData([ postdata['email'] ]);
});
});
$(document).ready(addGclid);
})(jQuery);
</script>
I got on my hands this google tag, but the problem is that it's no longer working, and I am wondering if there's a newer version of this tag I should replace. Maybe replacing the URL will work, because https://gstatic.com/conversions/gclidless.js leads to a 404.

How to open a Calendar in Angular JS

I have implemented Angular JS in my Phonegap Application. Where I wish to open a Calendar in the App. But The application is not allowing me to do so.
Following is the code, where I am using with the plugins.
$scope.reminderTimes.selected = returnDate.getHours();
$scope.reminderMins.selected = returnDate.getMinutes();
var newDate = new Date();
$scope.showDatePicker = function($event) {
//console.log('dfdsfsdfsdfdsfsf sdfdsfs');
var options = {
date: new Date(),
mode: 'date'
};
datePicker.show(options, function(date){
if(date != 'Invalid Date') {
console.log("Date came" + date);
} else {
console.log(date);
}
});
$event.stopPropagation();
};
$scope.toogle = function(){
var options = {date: new Date(), mode: 'date'};
var options = {date: new Date(), mode: 'time'}; for time
$cordovaDatePicker.show(options).then(function(date){
alert(date);
});
};
If there is any other way please tell that as well.

Momentjs alternates between 'a few seconds ago' and 'a minute ago' with a dynamic timestamp

In my web application, I have a status page that gets data from a server sent event every couple seconds. In that data there's a UTC timestamp that I am formatting with moment.js fromNow() so I know how long ago the data was pulled. It works fine until I try to update the timestamp dynamically with a setInterval().
The issue occurs when I switch to another tab for about a minute and the timestamp transition from 'a few seconds ago' to 'a minute ago' or more. The issue is that when I go back to the original tab, the timestamp will alternate between 'a few seconds ago' and 'a minute ago' every second or so.
The code:
$(document).ready(function() {
var source = new EventSource("{{ url_for('status.stream') }}");
source.onmessage = function (event) {
var data = JSON.parse(event.data);
if (data.hasOwnProperty('errors')) {
var errors = data.errors;
console.error(errors)
} else if (data.hasOwnProperty('result')) {
var result = data.result;
$.each(['critical', 'warning', 'unknown'], function(index, key) {
var label = $('#'+key);
if (result[key] > 0) {
label.text(result[key] + ' ' + key.toUpperCase());
} else {
label.text('')
}
});
if (result.hasOwnProperty('timestamp')) {
var datetime = $('#datetime');
var timestamp = result.timestamp;
var update = function () {
var date = moment.utc(timestamp, 'YYYY-MM-DD HH:mm:ss').fromNow();
datetime.text(date)
};
update();
setInterval(update, 1000)
} else {
console.error('Error getting timestamp!')
}
} else {
console.error('Error getting data from the server!')
}
};
})
How can I fix this issue?
Thank you!
Fixed it by moving update() out of source.onmessage as #RobG mentioned.
Working code:
$(document).ready(function() {
var source = new EventSource("{{ url_for('status.stream') }}");
var datetime = $('#datetime');
var timestamp = null;
source.onmessage = function (event) {
var data = JSON.parse(event.data);
if (data.hasOwnProperty('errors')) {
var errors = data.errors;
console.error(errors)
} else if (data.hasOwnProperty('result')) {
var result = data.result;
$.each(['critical', 'warning', 'unknown'], function(index, key) {
var label = $('#'+key);
if (result[key] > 0) {
label.text(result[key] + ' ' + key.toUpperCase())
} else {
label.text('')
}
});
if (result.hasOwnProperty('timestamp')) {
timestamp = result.timestamp
} else {
console.error('Error getting timestamp!')
}
} else {
console.error('Error getting data from the server!')
}
};
var update = function () {
if (!timestamp) {
return false
} else {
var date = moment.utc(timestamp, 'YYYY-MM-DD HH:mm:ss').fromNow();
datetime.text(date)
}
};
update();
setInterval(update, 1000)
})

check if the given date(in string format) has past present date using JS

I have a date range like 12/20/12-12/24/12(start date-end date) in string format .
I need to check if start date has past the present date. Can it be done using JS or j-query?
the date range is in string ?
Use the power of the Date object!
var myString = "12/20/2012-12/24/2012",
parts = myString.split("-");
if (Date.parse(parts[0]) < Date.now()) {
alert("start date has past the present date");
}
You could as well write new Date(parts[0]) < new Date.
using datejs
var today = Date.today();
var yourDay = Date.parse(yourDateTimeString);
var result = Date.compare(today, yourDay);
var isValid= result == -1;
compare returns -1 if today is less than yourDay
thanx evry1 .. i got the answer
here it is ...
function cancel()
{
var eventId=status_ID.substr(0,status_ID.indexOf("-"));
var status=status_ID.substr(status_ID.indexOf("-")+1,status_ID.indexOf(":")-4);
var eventRange=status_ID.substr(status_ID.indexOf(":")+1,status_ID.length);
//alert(status);
//alert(eventRange);
if(status=="OPEN"){
var startDate = eventRange.substr(0,eventRange.indexOf("-"));
//alert(startDate);
// alert("open");
var todayDay = new Date().getDate();
// alert(todayDay);
var todayMonth = new Date().getMonth();
alert(todayMonth);
var todayFullYear = new Date().getFullYear();
var todayYear=todayFullYear.toString().substr(2,4);
// alert(todayYear);
parts = startDate.split("/");
//alert(parts[0]);
//alert(parts[1]);
//alert(parts[2]);
var flag1=false;
if(parts[2]>todayYear){
flag1=true;
}
if(parts[2]==todayYear){
if(parts[1]>todayMonth+1)
{
flag1=true;
}
if(parts[1]==todayMonth+1)
{
if(parts[0]>todayDay)
{
flag1=true;
}
}
}
if(flag1)
{
alert("event can be cancelled");
document.forms[0].submit();
}
else
{
alert("event has already started");
return false;
}
}
else
{
alert("The event has closed");
}
}

Categories

Resources