var emailassign_template = (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(email_type_id, email_type){
app.modal.focusout_solution("on");
var _form = $("form#emailAssignTemplateForm");
_form.data("email_assign_template", {"email_type_id" :email_type_id});
bootbox.dialog({
"title": app.get_vars().email.title.assign_template + " "+email_type,
"className" : "my-modal-with-sm",
"message": _form,
"show": false,
"buttons" : [
{
"label": app.get_vars()._app.btn._close,
"class": "btn btn-default",
"callback": function () {
}
}, {
"label": app.get_vars().email.btn.assign_template,
"class": "btn btn-success",
"callback": function () {
emailassign_template._validate._init('add');
return false;
}
}
]
}).on('shown.bs.modal', function() {
_form.show();
app._form._reset(this);
//submit form on keypress or enter
app._form._form_submit_on_keypress("emailAssignTemplateForm", function(){
emailassign_template._validate._init('add');
});
//reinstialize typeahead
emailassign_template._typeheadjs._load({
location : "list_email_events/",
id : "event_id",
name : "name",
store : "event_id"
});
emailassign_template._typeheadjs._load({
location : "list_email_templates/",
id : "email_tpl_id",
name : "name",
store : "email_tpl_id"
});
$(this).off('shown.bs.modal');
}).on('hide.bs.modal', function(e) {
$(this).data('bs.modal', null);
app._form._resetFormValidation("#emailAssignTemplateForm");
app._form._reset(this);
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+"assign_email_template",
"type" : "POST",
"dataType": "json",
"data" : emailassign_template._prepare._data_to_server("add"),
"success" : function(result){
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
bootbox.hideAll();
(emailassign_template.get_vars()._emailassign_template).ajax.reload( null, false );
}
}
}
});
}
},
"_update" : {
"modal" : function(row){
app.modal.focusout_solution("on");
var rowData = (emailassign_template.get_vars()._emailassign_template).row(row).data();
var _form = $("#emailAssignTemplateForm");
_form.data("email_assign_template", {"email_map_id" : rowData.action.email_map_id,
"email_type_id" : rowData.action.email_type_id,
"email_tpl_id" : rowData.action.email_tpl_id,
"events_ids" : rowData.action.events_ids});
bootbox.dialog({
"title": app.get_vars().email.title.edit_default_email_setting + " "+rowData.email_type,
"className" : "my-modal-with-sm",
"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 () {
emailassign_template._validate._init('edit');
return false;
}
}
]
}).on('shown.bs.modal', function() {
_form.show();
//submit form on keypress or enter
app._form._form_submit_on_keypress("emailAssignTemplateForm", function(){
emailassign_template._validate._init('edit');
});
//set tinymce content
emailassign_template._prepare._set_data(rowData);
$(this).off('shown.bs.modal');
}).on('hide.bs.modal', function(e) {
try {
//tinymce.EditorManager.execCommand('mceRemoveEditor',false, 'email_tpl_detail');
// tinymce.remove();
} catch (e) {}
app._form._resetFormValidation("#emailAssignTemplateForm");
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){
var _form = $("#emailAssignTemplateForm").data("email_assign_template");
$.ajax({
"url" : app.get_vars().baseurl+"update_assign_email_template/"+_form.email_map_id,
type : "POST",
dataType : "json",
data : emailassign_template._prepare._data_to_server("edit"),
success : function(result){
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
bootbox.hideAll();
(emailassign_template.get_vars()._emailassign_template).ajax.reload( null, false );
}
}
}
});
}
},
"_delete" : {
"confirm" : function(email_map_id){
app.modal.confirm_box({
"message" : app.get_vars().email.cmsg.delete_assign_template+"
"+app.get_vars()._app.cma_msg.note+"",
"_continue" : function() {
emailassign_template._delete.save(email_map_id);
},
"id" : "delete_confirm_box",
"className" : "delete_confirm_box"
});
},
"save" : function(email_map_id){
$.ajax({
"url" : app.get_vars().baseurl+"delete_assign_email_template/"+email_map_id,
"type" : "POST",
"dataType" : "json",
"success" : function(result){
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
//reload grid
bootbox.hideAll();
(emailassign_template.get_vars()._emailassign_template).ajax.reload(null, false);
}
}
}
});
}
},
"_grid" : {
"load" : function(){
var table = $('#emailassign_template_list').DataTable({
"dom" : '<"top"l><"toolbar">rt<"bottom"ip><"clear">',
//"dom": '<"toolbar"><"top"lf>rt',
"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_assign_template_list",
"type": "POST" ,
"data" : function(d){}
},
"columns": [
{ "data": "email_tpl_order" },
{ "data": "email_type"},
{ "data": "email_tpl_name"},
{ "data": "events_title", render : function(data, type, full, meta){
var events_ = (full.events_title).split(", "),
_list = "", len = events_.length;
$.map(events_, function(value, i){
_list += "➭ "+value;
if(i>1 || (i+1) != len){
_list +="
";
}
});
return _list;
}},
{ "data": "email_map_status" },
{ "data": "action" , render : function(data, type, full, meta){
var action_btns = "";
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._edit, "pencil", "success", "emailassign_template._update.modal("+meta.row+")");
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", "emailassign_template._delete.confirm("+full.action.email_map_id +")");
return '
Loading...
'); }, load_email_type : function(){ $.get(app.get_vars().baseurl+"load_email_type/tpl_list/", function(data) { var datalen = data.length, options = ""; if(datalen > 0) { $.map(data, function(val, i){ options += "