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.
401 lines
20 KiB
401 lines
20 KiB
var emaildef_setting = (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#emailDefaultSettingsForm");
|
|
_form.data("email_default_setting", {"email_type_id" : email_type_id});
|
|
if(parseInt(email_type_id) == 1) {
|
|
$("#number_of_recipients").hide();
|
|
} else {
|
|
$("#number_of_recipients").show();
|
|
}
|
|
|
|
bootbox.dialog({
|
|
"title": app.get_vars().email.title.set_default_email_setting + " <i class='fa fa-chevron-right fa-1'></i> "+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.save_configuration,
|
|
"class": "btn btn-success",
|
|
"callback": function () {
|
|
emaildef_setting._validate._init('add');
|
|
return false;
|
|
}
|
|
}
|
|
]
|
|
}).on('shown.bs.modal', function() {
|
|
// emaildef_setting._prepare._modal_labels();
|
|
$(this).off('shown.bs.modal');
|
|
}).on('hide.bs.modal', function(e) {
|
|
$(this).data('bs.modal', null);
|
|
app._form._resetFormValidation("#emailDefaultSettingsForm");
|
|
app._form._reset(this);
|
|
app.modal.focusout_solution("off");
|
|
$(this).off('hidden.bs.modal');
|
|
}).modal('show')
|
|
.init(function(){
|
|
app._form._reset(this);
|
|
//submit form on keypress or enter
|
|
app._form._form_submit_on_keypress("emailDefaultSettingsForm", function(){
|
|
emaildef_setting._validate._init('add');
|
|
});
|
|
});
|
|
},
|
|
|
|
"save" : function(form){
|
|
$.ajax({
|
|
"url" : app.get_vars().baseurl+"save_default_configuration",
|
|
"type" : "POST",
|
|
"dataType": "json",
|
|
"data" : emaildef_setting._prepare._data_to_server("add"),
|
|
"success" : function(result){
|
|
if(app.isalive(result)) {
|
|
app._notify(result.mtype, result.message);
|
|
if (result.mtype == "success") {
|
|
bootbox.hideAll();
|
|
(emaildef_setting.get_vars()._emaildef_setting).ajax.reload( null, false );
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
"_update" : {
|
|
"modal" : function(row){
|
|
app.modal.focusout_solution("on");
|
|
|
|
var rowData = (emaildef_setting.get_vars()._emaildef_setting).row(row).data();
|
|
var _form = $("#emailDefaultSettingsForm");
|
|
_form.data("email_default_setting", {"email_tpl_setting_id" : rowData.action.email_tpl_setting_id, "email_type_id" : rowData.action.email_type_id});
|
|
|
|
if(parseInt(rowData.action.email_type_id) == 1) {
|
|
$("#number_of_recipients").hide();
|
|
} else {
|
|
$("#number_of_recipients").show();
|
|
}
|
|
|
|
bootbox.dialog({
|
|
"title": app.get_vars().email.title.edit_default_email_setting + " <i class='fa fa-chevron-right fa-1'></i> "+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 () {
|
|
emaildef_setting._validate._init('edit');
|
|
return false;
|
|
}
|
|
}
|
|
]
|
|
}).on('shown.bs.modal', function() {
|
|
// emaildef_setting._prepare._modal_labels();
|
|
$(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("#emailDefaultSettingsForm");
|
|
app._form._reset(this);
|
|
$(this).data('bs.modal', null);
|
|
app.modal.focusout_solution("off");
|
|
$(this).off('hidden.bs.modal');
|
|
})
|
|
.modal('show')
|
|
.init(function(){
|
|
//submit form on keypress or enter
|
|
app._form._form_submit_on_keypress("emailDefaultSettingsForm", function(){
|
|
emaildef_setting._validate._init('edit');
|
|
});
|
|
//set tinymce content
|
|
emaildef_setting._prepare._set_data(rowData);
|
|
});
|
|
},
|
|
|
|
"save" : function(form){
|
|
var _form = $("#emailDefaultSettingsForm").data("email_default_setting");
|
|
$.ajax({
|
|
"url" : app.get_vars().baseurl+"update_default_configuration/"+_form.email_tpl_setting_id,
|
|
type : "POST",
|
|
dataType : "json",
|
|
data : emaildef_setting._prepare._data_to_server("edit"),
|
|
success : function(result){
|
|
if(app.isalive(result)) {
|
|
app._notify(result.mtype, result.message);
|
|
if (result.mtype == "success") {
|
|
bootbox.hideAll();
|
|
(emaildef_setting.get_vars()._emaildef_setting).ajax.reload( null, false );
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
"_delete" : {
|
|
"confirm" : function(email_tpl_setting_id){
|
|
app.modal.confirm_box({
|
|
"message" : app.get_vars().email.cmsg.delete_email_template+" ?<br/><br><span class='label label-danger' style='font-size: 12px;'>"+app.get_vars()._app.cma_msg.note+"</span>",
|
|
"_continue" : function() {
|
|
emaildef_setting._delete.save(email_tpl_setting_id);
|
|
},
|
|
"id" : "delete_confirm_box",
|
|
"className" : "delete_confirm_box"
|
|
});
|
|
},
|
|
|
|
"save" : function(email_tpl_setting_id){
|
|
$.ajax({
|
|
"url" : app.get_vars().baseurl+"delete_configuration_setting/"+email_tpl_setting_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();
|
|
(emaildef_setting.get_vars()._emaildef_setting).ajax.reload(null, false);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
"_grid" : {
|
|
"load" : function(){
|
|
var table = $('#emaildef_setting_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_default_setting_list",
|
|
"type": "POST" ,
|
|
"data" : function(d){
|
|
}
|
|
},
|
|
"columns": [
|
|
{ "data": "email_tpl_order" },
|
|
{ "data": "email_type"},
|
|
{ "data": "email_tpl_setting_sched"},
|
|
// { "data": "email_tpl_number_of_recipients", render : function(data, type, full, meta){
|
|
// if(full.action.email_type_id == "1"){
|
|
// return "Not Applicable";
|
|
// }
|
|
// return full.email_tpl_number_of_recipients;
|
|
// }},
|
|
{ "data": "email_tpl_sched_author"},
|
|
{ "data": "email_tpl_sched_date_added"},
|
|
{ "data": "action" , render : function(data, type, full, meta){
|
|
var action_btns = "";
|
|
//if(parseInt(full.onqueue_mails) !=0 && full.event_status < 4) {
|
|
if (authorize(PAGE_CODE['email'], PRIVS[PAGE_CODE['email']]['settings_edit'])) {
|
|
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._edit, "pencil", "success", "emaildef_setting._update.modal("+meta.row+")");
|
|
}
|
|
// action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", "emaildef_setting._delete.confirm("+full.action.email_tpl_setting_id +")");
|
|
//} else {
|
|
// return "Fermé";
|
|
//}
|
|
//action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._openpreview, "eye-open","info", "event_mail._view.modal("+full.action.event_id+")");
|
|
return '<div class="row-fluid" align="center"><div class="row" align="center">'+action_btns+'</div></div>';
|
|
}}
|
|
],
|
|
"fnDrawCallback": function() {
|
|
app._tooltip._hide();
|
|
$('#emaildef_setting_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": [0], "orderable": false},
|
|
//{ "targets": [6], "orderable": false},
|
|
{ "targets": [3], "orderable": true},
|
|
{ "targets": [5], "orderable": true},
|
|
{ "targets": [4], "orderable": true},
|
|
{ "targets": [1], width: "20%", className : "truncate-content-text custom-popover-tooltip"}
|
|
],
|
|
"initComplete": function(settings, json) {
|
|
//run tooltip
|
|
app._tooltip._hide();
|
|
app._tooltip._pop();
|
|
|
|
$("div#emaildef_setting_list_length").css({"width" : "20%", "float":"left"});
|
|
$("select[name='emaildef_setting_list_length']").css({"width" : "6.4rem"});
|
|
|
|
if (authorize(PAGE_CODE['email'], PRIVS[PAGE_CODE['email']]['settings_add'])) {
|
|
$("div.toolbar").html('<div class="btn-group dropdown pull-right">'
|
|
+'<button class="btn btn-primary btn-sm" type="button" id="dropdownMenu2" data-toggle="dropdown">'
|
|
+'<i class="fa fa-cog fa-1"></i> '+app.get_vars().email.title.set_default_email_setting
|
|
+'</button>'
|
|
+'<button type="button" class="btn btn-primary dropdown-toggle btn-sm" data-toggle="dropdown">'
|
|
+'<span class="caret"></span>'
|
|
+'<span class="sr-only">Toggle Dropdown</span>'
|
|
+'</button>'
|
|
+'<ul class ="dropdown-menu" id="emailtemplatetype" role="menu">'
|
|
+'<li><a class="" href="#"><p><i class="fa fa-spin fa-spinner"></i> Loading...</p></a></li>'
|
|
+'</ul>'
|
|
+'</div>');
|
|
}
|
|
|
|
emaildef_setting.util.load_email_type();
|
|
}
|
|
});
|
|
emaildef_setting.set_vars({_emaildef_setting : table});
|
|
}
|
|
},
|
|
|
|
"_prepare" : {
|
|
"_data_to_server" : function(action){
|
|
var _form = $("form#emailDefaultSettingsForm"),
|
|
form_data = _form.serializeArray(),
|
|
form_data_ = _form.data("email_default_setting");
|
|
if(action == "edit"){
|
|
form_data.push({"name" : "email_tpl_setting_id", "value" : form_data_.email_tpl_setting_id});
|
|
form_data.push({"name" : "email_type_id", "value" : form_data_.email_type_id});
|
|
} else {
|
|
form_data.push({"name" : "email_type_id", "value" : form_data_.email_type_id});
|
|
}
|
|
|
|
return form_data;
|
|
},
|
|
|
|
"_set_data" : function(data){
|
|
//set values
|
|
$("#email_tpl_setting_sched_by").val(data.action.email_tpl_setting_sched_by);
|
|
$("#email_tpl_setting_sched").val(data.action.email_tpl_setting_sched);
|
|
// if(parseInt(data.action.email_type_id) != 1) {
|
|
// $("#email_tpl_number_of_recipients").val(data.email_tpl_number_of_recipients);
|
|
// }
|
|
},
|
|
|
|
"_modal_labels" : function(){
|
|
$("#email_tpl_setting_sched_by").change(function() {
|
|
$('#email_tpl_setting_sched_by_label').text($('#email_tpl_setting_sched_by :selected').attr('data-labeling') + ' (Unit)');
|
|
$('#email_tpl_setting_sched').attr('placeholder', $('#email_tpl_setting_sched_by :selected').attr('data-labeling'));
|
|
$('#email_tpl_setting_sched_label').text($('#email_tpl_setting_sched_by :selected').attr('data-labeling'));
|
|
}).change();
|
|
}
|
|
|
|
},
|
|
|
|
"_validate" : {
|
|
"_init": function (action) {
|
|
var options = {
|
|
boot_box: {
|
|
"action" : action,
|
|
"message": (action == "add")
|
|
? app.get_vars().email.cmsg.save_configuration
|
|
: app.get_vars().email.cmsg.edit_configuration
|
|
,
|
|
"_continue": function () {
|
|
var _form_ = $("form#emailDefaultSettingsForm");
|
|
(action == "add")
|
|
? emaildef_setting._create.save(_form_)
|
|
: emaildef_setting._update.save(_form_)
|
|
}
|
|
},
|
|
"validation": {
|
|
"form_id": "form#emailDefaultSettingsForm",
|
|
"ignore": "",
|
|
"rules": {
|
|
// "email_tpl_number_of_recipients": {
|
|
// "digits": {
|
|
// depends : emaildef_setting._validate.check_number_of_recipients_field
|
|
// },
|
|
// "required": {
|
|
// depends : emaildef_setting._validate.check_number_of_recipients_field
|
|
// }
|
|
// },
|
|
"email_tpl_setting_sched": {
|
|
"digits": true,
|
|
"required": true,
|
|
"minlength": 1
|
|
},
|
|
"email_tpl_setting_sched_by": {
|
|
"required": true
|
|
}
|
|
}
|
|
}
|
|
};
|
|
app._form._validate(options);
|
|
},
|
|
|
|
check_number_of_recipients_field : function(){
|
|
var _form = $("form#emailDefaultSettingsForm"),
|
|
_form_data = _form.data("email_default_setting");
|
|
if(typeof _form_data.email_type_id != "undefined" && parseInt(_form_data.email_type_id) == 2) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
},
|
|
|
|
util : {
|
|
loader : function(el){
|
|
el.html('<p><i class="fa fa-spin fa-spinner"></i> Loading...</p>');
|
|
},
|
|
load_email_type : function(){
|
|
$.get(app.get_vars().baseurl+"load_email_type/tpl_email_default_setting_list/", function(data) {
|
|
var datalen = data.length, options = "";
|
|
if(datalen > 0) {
|
|
$.map(data, function(val, i){
|
|
options += '<li data-email_type="'+val.email_type_id+'" onclick="emaildef_setting._create.modal('+val.email_type_id+', \`'+val.email_type+'\`);">' +
|
|
'<a class="" href="#">'+val.email_type+' <span class="spinner-msg"></span></a></li>';
|
|
if(i == 0 || (i+1) != datalen){ options += '<li class="divider"></li>';}
|
|
});
|
|
$("#emailtemplatetype").html(options);
|
|
} else { $("#emailtemplatetype").html('<li><a class="" href="#"No email type added!</a></li>'); }
|
|
});
|
|
}
|
|
}
|
|
|
|
};//end of return
|
|
// Pass in jQuery.
|
|
})(jQuery, this);
|
|
|
|
$(function() {
|
|
//load datatable
|
|
emaildef_setting._grid.load();
|
|
|
|
});
|
|
|
|
|