You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
439 lines
22 KiB
439 lines
22 KiB
// 'use strict';
|
|
const email_reminder = (function ($, window, jQuery) {
|
|
var _vars_ = {};
|
|
|
|
return {
|
|
"set_vars": function (options) {
|
|
$.extend(_vars_, options || {});
|
|
},
|
|
|
|
"get_vars": function () {
|
|
return _vars_;
|
|
},
|
|
|
|
"init" : function(event_schedule_id, row){
|
|
|
|
var explode = row.split("_");
|
|
var event = $("#events_list").DataTable().row(explode[0]).data();
|
|
|
|
if(typeof event.action.event_schedule[explode[1]] != "undefined"){
|
|
app.modal.focusout_solution("on");
|
|
bootbox.dialog({
|
|
"title": "Email Configuration",
|
|
"className" : "my-modal-with-medium",
|
|
"message": $("#email-configuration"),
|
|
"show": false, /* We will show it manually later */
|
|
"buttons" : [
|
|
{
|
|
"label": app.get_vars()._app.btn._close,
|
|
"class": "btn"
|
|
}
|
|
]
|
|
}).on('shown.bs.modal', function(){
|
|
//displayHack : recalculate the dimensions of email_reminder_list table/grid
|
|
$("#email_reminder_list").DataTable().columns.adjust();
|
|
})
|
|
.on('hide.bs.modal', function(e) {
|
|
//destroy event table
|
|
var email_reminder_list = $("#email_reminder_list");
|
|
email_reminder_list.DataTable().clear();
|
|
//destroy table
|
|
email_reminder_list.dataTable().fnDestroy();
|
|
$("#email_reminder_config_btn").prop("disabled", false);
|
|
app.modal.focusout_solution("off");
|
|
$(this).data('bs.modal', null);
|
|
$(this).off('hidden.bs.modal');
|
|
})
|
|
.modal('show')
|
|
.init(function(){
|
|
$("#emailReminderForm").data("email_reminder", event.action.event_schedule[explode[1]]);
|
|
email_reminder._grid.load(event_schedule_id);
|
|
});
|
|
} else {
|
|
app._notify("error", "Something went wrong!");
|
|
}
|
|
},
|
|
|
|
"_create" : {
|
|
"modal" : function(){
|
|
app.modal.focusout_solution("on");
|
|
var emailReminderForm = $("#emailReminderForm").data("email_reminder");
|
|
|
|
bootbox.dialog({
|
|
"title": app.get_vars().email.title.add_email_reminder,
|
|
"className" : "my-modal-with-xsm addEmailReminder",
|
|
"message": $("#emailReminderForm"),
|
|
"show": false /* We will show it manually later */,
|
|
"buttons" : [
|
|
{
|
|
"label": app.get_vars()._app.btn._close,
|
|
"class": "btn btn-default",
|
|
"callback": function () {
|
|
}
|
|
}, {
|
|
"label": app.get_vars().email.btn.add_email_reminder,
|
|
"class": "btn btn-success",
|
|
"callback": function () {
|
|
email_reminder._validate._init('add',emailReminderForm.event_schedule_id);
|
|
return false;
|
|
}
|
|
}
|
|
]
|
|
}).on('shown.bs.modal', function() {
|
|
try {
|
|
var email_schedule_date = $("#email_schedule_date");
|
|
//reset date_picker
|
|
email_reminder._dtimepicker.reset_dpicker(email_schedule_date, "min", emailReminderForm.reservation_start_date);
|
|
email_reminder._dtimepicker.reset_dpicker(email_schedule_date, "max", emailReminderForm.start_date_time);
|
|
} catch (e) {}
|
|
}).on('hide.bs.modal', function(e) {
|
|
app._form._resetFormValidation("#emailReminderForm");
|
|
app._form._reset(this);
|
|
app.modal.focusout_solution("off");
|
|
$(this).data('bs.modal', null);
|
|
$(this).off('hidden.bs.modal');
|
|
})
|
|
.modal('show')
|
|
.init(function(){
|
|
//reset date_picker
|
|
email_reminder._dtimepicker.config("now");
|
|
});
|
|
},
|
|
|
|
"save" : function(event_schedule_id){
|
|
$.ajax({
|
|
"url" : app.get_vars().baseurl+"add_email_reminder",
|
|
"type" : "POST",
|
|
"data" : {
|
|
"event_schedule_id" : event_schedule_id,
|
|
"email_schedule_date" : app._form.format_inputs("datetime", $("#email_schedule_date").val().trim())
|
|
},
|
|
"success" : function(result){
|
|
if(app.isalive(result)) {
|
|
app._notify(result.mtype, result.message);
|
|
if (result.mtype == "success") {
|
|
//reload grid
|
|
$(".addEmailReminder").modal("hide");
|
|
$("#email_reminder_list").DataTable().ajax.url(app.get_vars().baseurl+"get_email_reminder_list/"+event_schedule_id).load();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
"_update" : {
|
|
"modal" : function(row){
|
|
app.modal.focusout_solution("on");
|
|
var rowData = (email_reminder.get_vars()._email_reminder).row(row).data();
|
|
var _form = $("#emailReminderForm");
|
|
var emailReminderForm = _form.data("email_reminder");
|
|
bootbox.dialog({
|
|
"title": app.get_vars().email.title.edit_email_reminder,
|
|
"className" : "my-modal-with-xsm editEmailReminder",
|
|
"message": _form,
|
|
"show": false /* We will show it manually later */,
|
|
"buttons" : [
|
|
{
|
|
"label": app.get_vars()._app.btn._close,
|
|
"class": "btn btn-default",
|
|
"callback": function () {
|
|
}
|
|
}, {
|
|
"label": "Save",
|
|
"class": "btn btn-success",
|
|
"callback": function () {
|
|
email_reminder._validate._init('edit', rowData.action.event_schedule_id, rowData.action.email_schedule_id);
|
|
return false;
|
|
}
|
|
}
|
|
]
|
|
}).on('shown.bs.modal', function() {
|
|
}).on('hide.bs.modal', function(e) {
|
|
app._form._resetFormValidation("#emailReminderForm");
|
|
app._form._reset(this);
|
|
$(this).data('bs.modal', null);
|
|
app.modal.focusout_solution("off");
|
|
$(this).off('hidden.bs.modal');
|
|
})
|
|
.modal('show')
|
|
.init(function(){
|
|
app._form._reset(this);
|
|
try {
|
|
var email_schedule_date = $("#email_schedule_date");
|
|
//reset date_picker
|
|
email_reminder._dtimepicker.reset_dpicker(email_schedule_date, "min", emailReminderForm.reservation_start_date);
|
|
email_reminder._dtimepicker.reset_dpicker(email_schedule_date, "max", emailReminderForm.start_date_time);
|
|
email_schedule_date.data("DateTimePicker").date(rowData.email_schedule_date);
|
|
} catch (e) {}
|
|
});
|
|
},
|
|
|
|
"save" : function(event_schedule_id, email_schedule_id){
|
|
$.ajax({
|
|
"url" : app.get_vars().baseurl+"update_email_reminder",
|
|
"type" : "POST",
|
|
"data" : {
|
|
"event_schedule_id" : event_schedule_id,
|
|
"email_schedule_id" : email_schedule_id,
|
|
"email_schedule_date" : app._form.format_inputs("datetime", $("#email_schedule_date").val().trim())
|
|
},
|
|
success : function(result){
|
|
//hide loder modal
|
|
if(app.isalive(result)) {
|
|
app._notify(result.mtype, result.message);
|
|
if (result.mtype == "success") {
|
|
//reload grid
|
|
$(".editEmailReminder").modal("hide");
|
|
$("#email_reminder_list").DataTable().ajax.url(app.get_vars().baseurl+"get_email_reminder_list/"+event_schedule_id).load();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
"_delete" : {
|
|
"confirm" : function(email_schedule_id, event_schedule_id){
|
|
app.modal.confirm_box({
|
|
"message" : app.get_vars().email.cmsg.delete_email_reminder+" <br/><br><span class='label label-danger' style='font-size: 12px;'>"+app.get_vars()._app.cma_msg.note+"</span>",
|
|
"_continue" : function() {
|
|
email_reminder._delete.save(email_schedule_id, event_schedule_id);
|
|
},
|
|
"id" : "delete_confirm_box",
|
|
"className" : "delete_confirm_box"
|
|
});
|
|
},
|
|
|
|
"save" : function(email_schedule_id, event_schedule_id){
|
|
$.ajax({
|
|
"url" : app.get_vars().baseurl+"delete_email_reminder/",
|
|
"type" : "POST",
|
|
"data" : {
|
|
"email_schedule_id" : email_schedule_id
|
|
},
|
|
"dataType" : "json",
|
|
"success" : function(result){
|
|
if(app.isalive(result)) {
|
|
app._notify(result.mtype, result.message);
|
|
if (result.mtype == "success") {
|
|
//reload grid
|
|
$(".addEmailReminder").modal("hide");
|
|
var eventReminderTbl = $("#email_reminder_list");
|
|
eventReminderTbl.DataTable().ajax.url(app.get_vars().baseurl+"get_email_reminder_list/"+event_schedule_id).load();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
"_grid" : {
|
|
"load" : function(event_schedule_id){
|
|
var table = $('#email_reminder_list').DataTable({
|
|
"sDom": '<"toolbar">p',
|
|
"autoWidth": false,
|
|
"pageLength": 5,
|
|
"destroy" : true,
|
|
"responsive": true,
|
|
"processing": true, //Feature control the processing indicator.
|
|
"serverSide": true, //Feature control DataTables' server-side processing mode.
|
|
"oLanguage": fr_onload_lang.oLanguage,
|
|
"order" : [2, "asc"],
|
|
// Load data for the table's content from an Ajax source
|
|
"ajax": {
|
|
"url": app.get_vars().baseurl+"get_email_reminder_list/"+event_schedule_id,
|
|
"type": "POST"
|
|
},
|
|
"columns": [
|
|
{ "data": "event_order", orderable: false },
|
|
{ "data": "start_date_time"},
|
|
{ "data": "email_schedule_date"},
|
|
{ "data": "email_schedule_status", render : function(data, type, full, meta){
|
|
return '<span class="'+((full.email_schedule_status == "Active")?"active-sched":"passed-sched")+'">'+data+'</span>';
|
|
}},
|
|
{ "data": "email_schedule_author", orderable: false},
|
|
{ "data": "action", orderable: false, className : "custom-popover-tooltip", render : function(data, type, full, meta){
|
|
var action_btns = "";
|
|
if(full.email_schedule_status == "Active") {
|
|
$("#email_reminder_config_btn").prop("disabled", true);
|
|
if (authorize(PAGE_CODE['events'], PRIVS[PAGE_CODE['events']]['sched_email_reminder_edit'])) {
|
|
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._edit, "pencil", "success", "email_reminder._update.modal("+meta.row+")");
|
|
}
|
|
if (authorize(PAGE_CODE['events'], PRIVS[PAGE_CODE['events']]['sched_email_reminder_delete'])) {
|
|
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", "email_reminder._delete.confirm("+full.action.email_schedule_id +", "+full.action.event_schedule_id+")");
|
|
}
|
|
} else {
|
|
if (authorize(PAGE_CODE['events'], PRIVS[PAGE_CODE['events']]['sched_email_reminder_delete'])) {
|
|
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", "email_reminder._delete.confirm("+full.action.email_schedule_id +", "+full.action.event_schedule_id+")");
|
|
}
|
|
}
|
|
return '<div class="row-fluid" align="center"><div class="row" align="center">'+action_btns+'</div></div>';
|
|
}},
|
|
{ "data": "email_schedule_date_added"}
|
|
],
|
|
"fnDrawCallback": function() {
|
|
var eventReminderTbl = $("#email_reminder_list");
|
|
email_reminder._grid.config_reminder_btn();
|
|
|
|
//displayHack : recalculate the dimensions of email_reminder_list table/grid
|
|
eventReminderTbl.DataTable().columns.adjust();
|
|
},
|
|
//Set column definition initialisation properties.
|
|
"columnDefs": [
|
|
{ "targets": [5], "orderable": true},
|
|
{ "targets": [0], "orderable": false},
|
|
{ "targets": [3], "orderable": true},
|
|
{ "targets": [4], "width": "10%"},
|
|
{ "targets": [6], "orderable": false}
|
|
],
|
|
"initComplete": function(settings, json) {
|
|
//add custom button beside searchbox
|
|
if (authorize(PAGE_CODE['events'], PRIVS[PAGE_CODE['events']]['sched_email_reminder_create'])) {
|
|
$("#email_reminder_list_wrapper div.toolbar")
|
|
.html('<button class="btn btn-primary btn-sm" id="email_reminder_config_btn" onclick="email_reminder._create.modal();">'
|
|
+app.get_vars().email.btn.add_email_reminder+'</button>');
|
|
}
|
|
email_reminder._grid.config_reminder_btn();
|
|
}
|
|
});
|
|
email_reminder.set_vars({_email_reminder : table});
|
|
},
|
|
|
|
"config_reminder_btn" : function(){
|
|
var eventReminderTbl = $("#email_reminder_list");
|
|
if(eventReminderTbl.find("span.active-sched").length > 0){
|
|
$("#email_reminder_config_btn").prop("disabled", true);
|
|
}else {
|
|
$("#email_reminder_config_btn").prop("disabled", false);
|
|
}
|
|
}
|
|
},
|
|
|
|
"_validate" : {
|
|
"_init": function (action, event_schedule_id, email_schedule_id) {
|
|
//setup date
|
|
var event_schedule_list = $("form#emailReminderForm").data("email_reminder");
|
|
|
|
var options = {
|
|
boot_box: {
|
|
"message": (action == "add")
|
|
? app.get_vars().email.cmsg.add_email_reminder
|
|
: app.get_vars().email.cmsg.save_changes
|
|
,
|
|
"_continue": function () {
|
|
(action == "add")
|
|
? email_reminder._create.save(event_schedule_id)
|
|
: email_reminder._update.save(event_schedule_id, email_schedule_id)
|
|
}
|
|
},
|
|
"validation": {
|
|
"custom" : {
|
|
"rules": {
|
|
"invalid_date": {
|
|
"_fnc": function (value, element, options) {
|
|
if(value.trim() != "") {
|
|
if (!moment(value, "DD/MM/YYYY HH[h]mm", true).isValid()) {
|
|
return false;
|
|
}
|
|
return true;
|
|
} else {
|
|
return true;
|
|
}
|
|
},
|
|
msg: app.get_vars().email.val.invlaid_date
|
|
},
|
|
"invalid_sched_date_1": {
|
|
"_fnc": function (value, element, options) {
|
|
if(value.trim() != "") {
|
|
if (typeof event_schedule_list != "undefined") {
|
|
if(event_schedule_list.reservation_start_date != null) {
|
|
if (moment(value, "DD/MM/YYYY HH[h]mm") <= moment(event_schedule_list.reservation_start_date, "DD/MM/YYYY HH[h]mm")) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
},
|
|
msg: "Schedule date must not less than the event reservation date."
|
|
},
|
|
"invalid_sched_date_2": {
|
|
"_fnc": function (value, element, options) {
|
|
if(value.trim() != "") {
|
|
if (typeof event_schedule_list != "undefined") {
|
|
if(event_schedule_list.start_date_time != null) {
|
|
if (moment(value, "DD/MM/YYYY HH[h]mm") >= moment(event_schedule_list.start_date_time, "DD/MM/YYYY HH[h]mm")) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
},
|
|
msg: "Schedule date must not greater than or equal event start date."
|
|
}
|
|
}
|
|
},
|
|
"form_id": "form#emailReminderForm",
|
|
"ignore": ".ignore",
|
|
"rules": {
|
|
"email_schedule_date": {
|
|
"invalid_sched_date_1" : true,
|
|
"invalid_sched_date_2" : true,
|
|
"invalid_date" : true,
|
|
"required" : true
|
|
}
|
|
}
|
|
}
|
|
};
|
|
app._form._validate(options);
|
|
}
|
|
},
|
|
"_dtimepicker" : {
|
|
config: function (date_now) {
|
|
var schedule = $("#email_schedule_date");
|
|
if(date_now == "now") {
|
|
date_now = moment().millisecond(0).second(0).minute(0).hour(0);
|
|
} else { date_now = moment(date_now, "DD/MM/YYYY HH:mm"); }
|
|
|
|
email_reminder._dtimepicker.reset_dpicker(schedule, "max", false);
|
|
email_reminder._dtimepicker.reset_dpicker(schedule, "min", date_now);
|
|
schedule.data("DateTimePicker").date(date_now).date(null);
|
|
},
|
|
reset_dpicker : function(picker, action, newvalue) {
|
|
try {
|
|
if (action == "min") {
|
|
picker.data("DateTimePicker").minDate(false);
|
|
picker.data("DateTimePicker").minDate(((newvalue!=null && newvalue!="")?newvalue:false));
|
|
} else if (action == "max") {
|
|
picker.data("DateTimePicker").maxDate(((newvalue!=null && newvalue!="")?newvalue:false));
|
|
}
|
|
} catch (e) {
|
|
}
|
|
}
|
|
}
|
|
|
|
};//end of return
|
|
// Pass in jQuery.
|
|
})(jQuery, this);
|
|
|
|
$(function() {
|
|
|
|
//inintialize datetimepicker
|
|
$("#email_schedule_date").datetimepicker({
|
|
"locale": 'fr',
|
|
"sideBySide": false,
|
|
"useCurrent" : false,
|
|
"ignoreReadonly": true,
|
|
"format": "DD/MM/YYYY HH"+"[h]"+"mm",
|
|
"minDate" : moment().millisecond(0).second(0).minute(0).hour(0)
|
|
});
|
|
});
|
|
|
|
|