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+"
"+app.get_vars()._app.cma_msg.note+"",
"_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 += ' ';
value += this.level;
value += '';
}
return String.prototype.replace.apply('