Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions api/controllers/ENEmailManagerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ module.exports = {
var currentDate = new Date().toISOString().slice(0,10);

//Find notification based on schedule date
var filterQuery = " SELECT id, emailSubject, fromName, fromEmail, templateDesignId, recipientId FROM en_notification WHERE CURDATE() >= startFROM AND CURDATE()<= repeatUntil AND ( notificationSendDate < CURDATE() OR notificationSendDate IS NULL) AND status='Active' AND setupType='Basic'";

ENNotification.find().where({"repeatUntil":{ ">=":currentDate}, "nextNotificationDate":currentDate,"status":"Active","setupType":"Basic"}).then(function(notifications){
ENNotification.query(filterQuery, function(err,notifications){

if(notifications.length > 0){

notifications.forEach(function(notify){

//ENNotification.update('');
self.updateNotificationSchedule(notify); // update next schedule date


//Find the recipient List for notification

ENRecipient.findOne({id:notify.recipientId}).then(function(recipient){
Expand Down Expand Up @@ -81,19 +79,15 @@ module.exports = {
obj.log = response; // log
//Create notification log
self.createNotificationLog(obj); //set notification log
//console.log('sent email');
self.updateNotificationSchedule(notify); // update next schedule date

});

});

});
});
}else{

console.log('No Email Scheduled');

}
}

});
},
Expand All @@ -113,9 +107,7 @@ module.exports = {
//Create notification log
ENNotificationLog.create(obj).fail(function(err){
console.log(err);
}).then(function(response){
console.log(response);
});
}).then(function(response){ });

},

Expand All @@ -129,31 +121,26 @@ module.exports = {
* @since 15 May 2015
*/

updateNotificationSchedule : function(notification){

var notificationFrequency = notification.emailFrequency;
updateNotificationSchedule : function(notification){
var currentDate = new Date();
var nextSchedule = '';
var notificationFrequency = notification.emailFrequency;
var nextSchedule = currentDate;

if(notificationFrequency == 'Everyday'){

nextSchedule = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1); // New date +1 day ahead
nextSchedule = currentDate;

}else if(notificationFrequency == 'Monthly'){

nextSchedule = new Date(currentDate.getFullYear(), currentDate.getMonth()+1, currentDate.getDate()); // New date +1 month ahead
nextSchedule = new Date(currentDate.getFullYear(), currentDate.getMonth()+1, currentDate.getDate()-1); // New date +1 month ahead

}else if(notificationFrequency == 'Yearly'){

nextSchedule = new Date(currentDate.getFullYear()+1, currentDate.getMonth(), currentDate.getDate()); // New date +1 Year ahead
nextSchedule = new Date(currentDate.getFullYear()+1, currentDate.getMonth(), currentDate.getDate()-1); // New date +1 Year ahead

}

//Update the schedule date
ENNotification.update(notification.id,{'nextNotificationDate': nextSchedule}).then(function(){
console.log('Schedule updated');

});

ENNotification.update(notification.id,{'notificationSendDate': nextSchedule}).then( function(){});

}
};
Expand Down
4 changes: 3 additions & 1 deletion api/models/ENNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ module.exports = {

repeatUntil : { type: 'date' },

nextNotificationDate : { type: 'date' },
notificationSendDate : { type: 'date' },

isForever : {type:'integer', size: 2, defaultsTo:0},

templateDesignId :{

Expand Down
2 changes: 1 addition & 1 deletion assets/opstools/EmailNotifications/EmailNotifications.css
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ button.close {
background-color:#fff;
border:1px solid #ccc;
padding:10px;
overflow: scroll;
overflow-y: scroll;
}

.en-table-recipients tbody .active {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ steal(
CtrlNotification.form.find('#dateStartFrom').val(new Date(self.wizardData.notification.startFrom).toLocaleDateString());
CtrlNotification.form.find('#emailFrequency').val(self.wizardData.notification.emailFrequency);

if(self.wizardData.notification.repeatUntil!='0000-00-00'){
if(self.wizardData.notification.isForever === 0){

CtrlNotification.form.find('#dateRepeatUntil').val(new Date(self.wizardData.notification.repeatUntil).toLocaleDateString());

}else{

CtrlNotification.form.find('#neverEnd').attr('checked',true);
//reset value if selected never end
CtrlNotification.form.find('#neverEnd').prop('checked',true);
CtrlNotification.form.find('#dateRepeatUntil').val(' ');
CtrlNotification.form.find('#dateRepeatUntil').attr('disabled', true);
CtrlNotification.form.find('#dateRepeatUntil').hide();
CtrlNotification.form.find('#no-date').show();
CtrlNotification.form.find('#repeatUntil .input-group-addon').hide();

}

Expand Down
8 changes: 6 additions & 2 deletions assets/opstools/EmailNotifications/controllers/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ steal(
this.controllers.Notifications.form.find('#dateStartFrom').val('');
this.controllers.Notifications.form.find('#emailFrequency').val('Everyday');
this.controllers.Notifications.form.find('#dateRepeatUntil').val('');
this.controllers.Notifications.form.find('#neverEnd').prop('checked',false);
this.controllers.Notifications.form.find('#dateRepeatUntil').show();
this.controllers.Notifications.form.find('#no-date').hide();
this.controllers.Notifications.form.find('#dateRepeatUntil').attr('disabled', false);
this.controllers.Notifications.form.find('#repeatUntil .input-group-addon ').show();
this.controllers.Notifications.form.find('#basic-settings').html('The Notification will be sent <a href="#"> Everyday</a>');

this.controllers.Notifications.element.find('.tabbable ul li:nth-child(2)').removeClass('active');
this.controllers.Notifications.element.find('.tabbable ul li:nth-child(1)').addClass('active');
this.controllers.Notifications.element.find('#basic').addClass('active');
Expand Down Expand Up @@ -355,7 +359,7 @@ steal(
var setupShortDesc = notification.emailFrequency;
setupShortDesc += ' from ';
setupShortDesc += new Date(notification.startFrom).toDateString();
if (notification.repeatUntil != '0000-00-00') {
if (notification.isForever == 0) {
setupShortDesc += ' to ' + new Date(notification.repeatUntil).toDateString();
} else {
setupShortDesc += '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ steal(
if(this.element.find('.tabbable ul li').eq(0).hasClass('active')) {
obj.setupType = 'Basic';
obj.eventTrigger = '';
obj.nextNotificationDate = obj.startFrom;
} else {
obj.setupType = 'System';
obj.startFrom = null;
Expand Down Expand Up @@ -152,18 +151,24 @@ steal(
if (this.validateFormData(obj) && this.validateBasicTab(obj)) {
var Model = AD.Model.get('opstools.EmailNotifications.ENNotification');
obj.recipientId = self.options.wizardData.recipient.id;
// Check for Never end
if(obj.neverEnd=='on'){
obj.repeatUntil = this.getFutureDate();
obj.isForever = '1';
}else{
obj.isForever = '0';
}

if (obj.startFrom != '') {
obj.setupType = 'Basic';
obj.eventTrigger = '';
obj.nextNotificationDate = obj.startFrom;
obj.eventTrigger = '';
obj.notificationSendDate = this.updateNotificationSchedule(obj);

} else {
obj.setupType = 'System';
}

if(obj.neverEnd=='on'){
obj.repeatUntil = '';
}


var notificationId = self.options.wizardData.notification.id;
if (notificationId) {
Model.update(notificationId, obj); //Update notificationId
Expand Down Expand Up @@ -397,24 +402,35 @@ steal(
*
*/
'#neverEnd click': function($el, ev) {
var obj = this.formValues();
var self = this;
if (obj.neverEnd == 'on') {
this.element.find('#dateRepeatUntil').val(' ');
this.element.find('#dateRepeatUntil').attr('disabled', true);
this.element.find('#dateRepeatUntil').hide();
this.element.find('#no-date').show();
this.element.find('#repeatUntil .input-group-addon').hide();
} else {
this.element.find('#dateRepeatUntil').show();
this.element.find('#no-date').hide();
this.element.find('#dateRepeatUntil').attr('disabled', false);
this.element.find('#repeatUntil .input-group-addon ').show();
}
self.updateNotificationBar();
var self = this;
self.clearRepeatUntil(); // clear repeat until field
self.updateNotificationBar(); // update notification bar
},


/**
* @clearRepeatUntil
* @to clear repeat until field
*
*
*/

clearRepeatUntil: function(){
var neverEnd = this.element.find('#neverEnd').is(':checked');
if (neverEnd) {
this.element.find('#dateRepeatUntil').val(' ');
this.element.find('#dateRepeatUntil').attr('disabled', true);
this.element.find('#dateRepeatUntil').hide();
this.element.find('#no-date').show();
this.element.find('#repeatUntil .input-group-addon').hide();
} else {
this.element.find('#dateRepeatUntil').show();
this.element.find('#no-date').hide();
this.element.find('#dateRepeatUntil').attr('disabled', false);
this.element.find('#repeatUntil .input-group-addon ').show();
}

},

/**
* @updateNotificationBar
* @ to update notification bar
Expand Down Expand Up @@ -493,6 +509,18 @@ steal(
},

/**
* @ getFutureDate
* @ to get futuredate if repeatUntil is blank
* @ param $el
* @ param ev
* return void
*/

getFutureDate :function(){
var currentDate = new Date(); //current date
return new Date(currentDate.getFullYear()+100, currentDate.getMonth(), currentDate.getDate());
},
/**
* @ emailFrequency change
* @ to chage the notification bar
* @ param $el
Expand All @@ -502,8 +530,27 @@ steal(
'#emailFrequency change': function($el, ev) {
var self = this;
self.updateNotificationBar();
}

},

/**@ updateNotificationSchedule
*
* @param obj
*
* @return void
*
* @author Edwin
* @since 15 May 2015
*/

updateNotificationSchedule : function(notification){
var self = this;
var notificationDate = new Date(notification.startFrom); //get start from date
var oneDayless = new Date(notificationDate.getFullYear(), notificationDate.getMonth(), notificationDate.getDate()-1);
var notificationSendDate = (self.options.wizardData.notification.notificationSendDate) ? new Date(self.options.wizardData.notification.notificationSendDate) : oneDayless;// schedule date on database

return notificationSendDate;
}


});
});
Loading