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.
 
 
 
 
 
 

567 lines
28 KiB

var email_reminder = (function ($, window, jQuery) {
var _vars_ = {"event_attachment": {attachment: 123}};
return {
"set_vars": function (options) {
$.extend(_vars_, options || {});
},
"get_vars": function () {
return _vars_;
},
"_create" : {
"modal" : function(){
app.modal.focusout_solution("on");
var _form = $("#emailReminderForm");
_form.removeData("email_reminder");
bootbox.dialog({
"title": app.get_vars().email.title.add_email_reminder,
"className" : "my-modal-with-small",
"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": app.get_vars().email.btn.add_email_reminder,
"class": "btn btn-success",
"callback": function () {
email_reminder._validate._init('add');
return false;
}
}
]
}).on('shown.bs.modal', function() {
_form.show();
app._form._reset(this);
//reset first
$("#title").val("").removeData("event");
email_reminder._typeheadjs._load();
//reset date_picker
email_reminder._dtimepicker.config("now");
//submit form on keypress or enter
app._form._form_submit_on_keypress("emailReminderForm", function(){
email_reminder._validate._init('add');
});
$(this).off('shown.bs.modal');
}).on('hide.bs.modal', function(e) {
app._form._resetFormValidation("#emailReminderForm");
app._form._reset(this);
$(this).data('bs.modal', null);
app.modal.focusout_solution("off");
_form.hide().appendTo('body');
$(this).off('hidden.bs.modal');
})
.modal('show');
},
"save" : function(form){
$.ajax({
"url" : app.get_vars().baseurl+"add_email_reminder",
"type" : "POST",
"dataType": "json",
"data" : email_reminder._prepare._data_to_server("add"),
"success" : function(result){
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
//reload grid
bootbox.hideAll();
(email_reminder.get_vars()._email_reminder).ajax.reload( null, false );
//location.reload();
//window.setTimeout(function(){window.location.href = app.get_vars().baseurl+"email_reminder";},1000);
}
}
}
});
}
},
"_update" : {
"modal" : function(row){
app.modal.focusout_solution("on");
var rowData = (email_reminder.get_vars()._email_reminder).row(row).data();
var _form = $("#emailReminderForm");
_form.data("email_reminder", {"email_schedule_id" : rowData.action.email_schedule_id, "event_id" : rowData.action.event_id});
bootbox.dialog({
"title": app.get_vars().email.title.edit_email_reminder,
"className" : "my-modal-with-small",
"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": app.get_vars().email.btn.save_changes,
"class": "btn btn-success",
"callback": function () {
email_reminder._validate._init('edit');
return false;
}
}
]
}).on('shown.bs.modal', function() {
_form.show();
app._form._reset(this);
email_reminder._prepare._set_data(rowData);
//submit form on keypress or enter
app._form._form_submit_on_keypress("emailReminderForm", function(){
email_reminder._validate._init('edit');
});
$(this).off('shown.bs.modal');
}).on('hide.bs.modal', function(e) {
app._form._resetFormValidation("#emailReminderForm");
app._form._reset(this);
$(this).data('bs.modal', null);
app.modal.focusout_solution("off");
_form.hide().appendTo('body');
$(this).off('hidden.bs.modal');
})
.modal('show');
},
"save" : function(form){
$.ajax({
"url" : app.get_vars().baseurl+"update_email_reminder",
type : "POST",
dataType : "json",
data : email_reminder._prepare._data_to_server("edit"),
success : function(result){
//hide loder modal
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
//reload grid
bootbox.hideAll();
(email_reminder.get_vars()._email_reminder).ajax.reload( null, false );
//window.setTimeout(function(){window.location.href = app.get_vars().baseurl+"email_reminder";},1000);
//location.reload();
}
}
}
});
}
},
"_delete" : {
"confirm" : function(email_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);
},
"id" : "delete_confirm_box",
"className" : "delete_confirm_box"
});
},
"save" : function(email_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
bootbox.hideAll();
(email_reminder.get_vars()._email_reminder).ajax.reload(null, false);
//window.setTimeout(function(){window.location.href = app.get_vars().baseurl+"email_reminder";},1000);
}
}
}
});
}
},
"_typeheadjs" : {
"_load" : function() {
$('#event_id').typeahead({
source: function (query, process) {
var $url = app.get_vars().baseurl + "list_email_reminder";
var $items = new Array;
$items = [""];
$.ajax({
url: $url,
data: {
"search": query
},
dataType: "json",
type: "POST",
success: function (data) {
if(app.isalive(data)) {
$.map(data, function (data) {
var group;
group = {
id: data.event_id,
name: data.name,
reservation_start_date: data.reservation_start_date,
date_now: data.date_now,
start_date_time: data.start_date_time,
event_status: data.event_status,
//email_sched_overwrite_default : data.email_sched_overwrite_default,
toString: function () {
return JSON.stringify(this);
//return this.app;
},
toLowerCase: function () {
return this.name.toLowerCase();
},
indexOf: function (string) {
return String.prototype.indexOf.apply(this.name, arguments);
},
replace: function (string) {
var value = '';
value += this.name;
if (typeof(this.level) != 'undefined') {
value += ' <span class="pull-right muted">';
value += this.level;
value += '</span>';
}
return String.prototype.replace.apply('<div style="padding: 10px; font-size: 1.5em;">' + value + '</div>', arguments);
}
};
$items.push(group);
});
process($items);
}
}
});
},
property: 'name',
items: 10,
minLength: 0,
showHintOnFocus: true,
updater: function (item) {
var item = JSON.parse(item);
$("#event_id").data("event", item);
//if(item.email_sched_overwrite_default != "" || item.email_sched_overwrite_default != null) {
// $("input[name='email_sched_overwrite_default'][value='" + item.email_sched_overwrite_default+ "']").prop("checked", true);
//}
return item.name;
}
});
}
},
"_grid" : {
"load" : function(){
var table = $('#email_reminder_list').DataTable({
"dom" : '<"top"l><"toolbar">rt<"bottom"ip><"clear">',
"autoWidth": true,
"responsive": true,
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [[ 1, "desc" ]], //Initial no order.
"oLanguage": fr_onload_lang.oLanguage,
// Load data for the table's content from an Ajax source
"ajax": {
"url": app.get_vars().baseurl+"get_email_reminder_list/",
"type": "POST" ,
"data" : function(d){
var da_ta = $("#custom_filter_search_form").serializeArray();
if(da_ta.length > 0) {
var x=0;
$.map(da_ta, function(val, index){
if(val.name != "custom_filter_search" && x==0){
d.keyname = val.name;
x++;
}
d[val.name] = val.value;
});
}
}
},
"columns": [
{ "data": "event_order" },
{ "data": "event_title"},
{ "data": "start_date_time"},
{ "data": "email_schedule_date"},
//{ "data": "email_sched_overwrite_default"},
{ "data": "email_schedule_status"},
{ "data": "email_schedule_author"},
{ "data": "action" , render : function(data, type, full, meta){
console.log(full.email_schedule_status);
var action_btns = "";
if(full.email_schedule_status == "Active") {
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._edit, "pencil", "success", "email_reminder._update.modal("+meta.row+")");
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", "email_reminder._delete.confirm("+full.action.email_schedule_id +")");
} else {
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", "email_reminder._delete.confirm("+full.action.email_schedule_id +")");
// return "Fermé";
}
return '<div class="row-fluid" align="center"><div class="row" align="center">'+action_btns+'</div></div>';
}},
{ "data": "email_schedule_date_added"}
],
"fnDrawCallback": function() {
app._tooltip._hide();
$('#email_reminder_list tbody tr td').each( function(x, y) {
var _this = $(this);
if(_this.hasClass('truncate-content-text')){
_this.css('max-width', '180px');
this.setAttribute( 'title', _this.text());
this.setAttribute( 'data-toggle',"tooltip");
}
});
app._tooltip._pop();
},
//Set column definition initialisation properties.
"columnDefs": [
{ "targets": [5], "orderable": true},
{ "targets": [0], "orderable": false},
{ "targets": [3], "orderable": true},
{ "targets": [7], "orderable": true},
{ "targets": [6], "orderable": false},
//{ "targets": [4], "orderable": true},
{ "targets": [1], className : "truncate-content-text custom-popover-tooltip"}
],
"initComplete": function(settings, json) {
//run tooltip
app._tooltip._hide();
app._tooltip._pop();
$("div#email_reminder_list_length").css({"width" : "20%", "float":"left"});
$("select[name='email_reminder_list_length']").css({"width" : "70px"});
//$('.dataTables_filter').css({"width" : "85%", "float":"right"}).html('').each(function () {
// $(this).html('<div class="col-sm-9">' +
// '<form class="" role="form" name="custom_filter_search_form" id="custom_filter_search_form" action="javascript:;">'+
// event_mail._grid.create_custom_filter() +
// '</form></div><div class="col-sm-3.0"><button onclick="event_mail._create.modal();" ' +
// 'class="btn btn-primary btn-sm mr-xs">' +
// '<span class="glyphicon glyphicon-plus"></span> '+app.get_vars().events.btn.add_event+'</button></div>');
//});
//add custom button beside searchbox
$("div.toolbar").html('<div class="col-sm-3.0 pull-right"><button onclick="email_reminder._create.modal();" ' +
'class="btn btn-primary btn-sm mr-xs create">' +
'<i class="fa fa-fw fa-thumb-tack"></i> '+app.get_vars().email.btn.add_email_reminder+'</button></div>');
//fire search filter event
}
});
email_reminder.set_vars({_email_reminder : table});
}
},
"_prepare" : {
"_data_to_server" : function(action){
var _form = $("form#emailReminderForm"),
form_data = _form.serializeArray(),
datetime = ["email_schedule_date"];
$.map(form_data, function(x, t){
if(datetime.indexOf(x.name) != -1){
form_data[t].value = app._form.format_inputs("datetime", x.value);
} else if(x.name == "event_id"){
var get_hdata = $("input#"+ x.name).data("event");
if(typeof get_hdata!= "undefined") {
form_data[t].value = get_hdata.id;
} else {
form_data[t].value = "";
}
}
});
if(action == "edit"){
var _get_data = _form.data("email_reminder");
form_data.push({"name" : "email_schedule_id", "value" : _get_data.email_schedule_id});
}
return form_data;
},
"_set_data" : function(data){
//event_id
$("#event_id")
.val(data.event_title)
.data("event", {
"id" : data.action.event_id,
"name" : data.event_title,
"reservation_start_date" : data.action.reservation_start_date,
"start_date_time" : data.action.start_date_time,
"event_status" : data.action.event_status
});
//$("input[name='email_sched_overwrite_default'][value='" + data.action.email_sched_overwrite_default+ "']").prop("checked", true);
try {
email_reminder._typeheadjs._load();
//reset date_picker
if(moment(data.action.reservation_start_date, "DD/MM/YYYY HH:mm", false) < moment((data.email_schedule_date).replace("h", ":"), "DD/MM/YYYY HH:mm", false)) {
email_reminder._dtimepicker.config(data.action.reservation_start_date);
} else {
email_reminder._dtimepicker.config((data.email_schedule_date).replace("h", ":"));
}
$("#email_schedule_date").val(data.email_schedule_date);
} catch (e) {}
}
},
"_validate" : {
"_init": function (action) {
var options = {
boot_box: {
"message": (action == "add")
? app.get_vars().email.cmsg.add_email_reminder
: app.get_vars().email.cmsg.save_changes
,
"_continue": function () {
var _form_ = $("form#emailReminderForm");
(action == "add")
? email_reminder._create.save(_form_)
: email_reminder._update.save(_form_)
}
},
"validation": {
"custom" : {
"rules": {
"invalid_date": {
"_fnc": function (value, element, options) {
if(value.trim() != "") {
var new_date = value.replace("h", ":");
if (!moment(new_date, "DD/MM/YYYY HH: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() != "") {
var t = $("#event_id").data("event");
if (typeof t != "undefined") {
if(t.event_status >= 1 && t.reservation_start_date != null) {
if (moment(value.replace("h", ":"), "DD/MM/YYYY HH:mm") <= moment(t.reservation_start_date, "DD/MM/YYYY HH: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() != "") {
var t = $("#event_id").data("event");
if (typeof t != "undefined") {
if(t.event_status >= 1 && t.start_date_time != null) {
if (moment(value.replace("h", ":"), "DD/MM/YYYY HH:mm") >= moment(t.start_date_time, "DD/MM/YYYY HH:mm")) {
return false;
}
}
return true;
}
return false;
} else {
return true;
}
},
msg: "Schedule date must not greater than or equal event start date."
},
"event_required": {
"_fnc": function (value, element, options) {
var t = $("#event_id").data("event");
if(typeof t != "undefined"){
if(typeof t.id != "undefined") {
return true;
}
}
return false;
},
msg: app.get_vars().email.val.event_first
}
}
},
"form_id": "form#emailReminderForm",
"ignore": "",
"rules": {
//"email_sched_overwrite_default": {
// "required": true
//},
"event_id": {
"required": true,
"event_required" : true
},
"email_schedule_date": {
"invalid_sched_date_1" : true,
"invalid_sched_date_2" : true,
"invalid_date" : true,
"event_required" : 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);
} else if (action == "max") {
picker.data("DateTimePicker").maxDate(false);
}
} catch (e) {
}
}
}
};//end of return
// Pass in jQuery.
})(jQuery, this);
$(function() {
//inintialize datetimepicker
$("#email_schedule_date").datetimepicker({
"locale": 'fr',
"sideBySide": true,
"useCurrent" : false,
"ignoreReadonly": true,
"format": "DD/MM/YYYY HH"+"[h]"+"mm",
"minDate" : moment().millisecond(0).second(0).minute(0).hour(0)
});
//load datatable
email_reminder._grid.load();
});