// '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+"
"+app.get_vars()._app.cma_msg.note+"",
"_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 ''+data+'';
}},
{ "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 '