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.
503 lines
24 KiB
503 lines
24 KiB
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 + " <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.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 + " <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 () {
|
|
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+"<br/><br><span class='label label-danger' style='font-size: 12px;'>"+app.get_vars()._app.cma_msg.note+"</span>",
|
|
"_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 += "<b>➭</b> "+value;
|
|
if(i>1 || (i+1) != len){
|
|
_list +="<br/>";
|
|
}
|
|
});
|
|
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 '<div class="row-fluid" align="center"><div class="row" align="center">'+action_btns+'</div></div>';
|
|
}}
|
|
],
|
|
"fnDrawCallback": function() {
|
|
app._tooltip._hide();
|
|
$('#emailassign_template_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": [5], "orderable": false},
|
|
{ "targets": [4], "orderable": true},
|
|
{ "targets": [2], "orderable": true, width: "20%", className : "truncate-content-text custom-popover-tooltip"},
|
|
{ "targets": [1], "orderable": true},
|
|
{ "targets": [3], "orderable": true, width: "30%", className : "truncate-content-text custom-popover-tooltip"}
|
|
],
|
|
"initComplete": function(settings, json) {
|
|
//run tooltip
|
|
app._tooltip._hide();
|
|
app._tooltip._pop();
|
|
|
|
$("div#emailassign_template_list_length").css({"width" : "20%", "float":"left"});
|
|
$("select[name='emailassign_template_list_length']").css({"width" : "70px"});
|
|
$("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-exchange fa-1"></i> '+app.get_vars().email.btn.assign_template
|
|
+'</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>');
|
|
emailassign_template.util.load_email_type();
|
|
}
|
|
});
|
|
emailassign_template.set_vars({_emailassign_template : table});
|
|
}
|
|
},
|
|
|
|
"_prepare" : {
|
|
"_data_to_server" : function(action){
|
|
var _form = $("form#emailAssignTemplateForm"),
|
|
form_data = _form.serializeArray();
|
|
|
|
$.map(form_data, function(x, t){
|
|
if(x.name == "event_id"){
|
|
var get_hdata = $("input#"+ x.name).data("event_id");
|
|
if(typeof get_hdata!= "undefined") {
|
|
form_data[t].value = get_hdata.id;
|
|
} else {
|
|
form_data[t].value = "";
|
|
}
|
|
} else if(x.name == "email_tpl_id"){
|
|
var get_hdata = $("input#"+ x.name).data("email_tpl_id");
|
|
if(typeof get_hdata!= "undefined") {
|
|
form_data[t].value = get_hdata.id;
|
|
} else {
|
|
form_data[t].value = "";
|
|
}
|
|
}
|
|
});
|
|
|
|
var form_hidden_data = _form.data("email_assign_template");
|
|
if(action == "edit"){
|
|
form_data.push({"name" : "email_map_id", "value" : form_hidden_data.email_map_id});
|
|
form_data.push({"name" : "email_type_id", "value" : form_hidden_data.email_type_id});
|
|
} else {
|
|
form_data.push({"name" : "email_type_id", "value" : form_hidden_data.email_type_id});
|
|
}
|
|
|
|
return form_data;
|
|
},
|
|
|
|
"_set_data" : function(data){
|
|
//set values
|
|
$("#event_id")
|
|
.val(data.events_title)
|
|
.data("event_id", {
|
|
"id" : data.action.events_ids,
|
|
"name" : data.events_title
|
|
});
|
|
$("#email_tpl_id")
|
|
.val(data.email_tpl_name)
|
|
.data("email_tpl_id", {
|
|
"id" : data.action.email_tpl_id,
|
|
"name" : data.email_tpl_name
|
|
});
|
|
|
|
//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"
|
|
});
|
|
}
|
|
},
|
|
|
|
"_validate" : {
|
|
"_init": function (action) {
|
|
var options = {
|
|
boot_box: {
|
|
"action" : action,
|
|
"message": (action == "add")
|
|
? app.get_vars().email.cmsg.assign_template
|
|
: app.get_vars().email.cmsg.update_assign_template
|
|
,
|
|
"_continue": function () {
|
|
var _form_ = $("form#emailAssignTemplateForm");
|
|
(action == "add")
|
|
? emailassign_template._create.save(_form_)
|
|
: emailassign_template._update.save(_form_)
|
|
}
|
|
},
|
|
"validation": {
|
|
"custom" : {
|
|
"rules": {
|
|
"check_event_id": {
|
|
"_fnc": function (value, element, options) {
|
|
var event_id = $("input#event_id"),
|
|
event_id_data = event_id.data("event_id");
|
|
if(typeof event_id_data == "undefined" || event_id.val().trim() == "") {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
msg: app.get_vars().email.val.email_event_req
|
|
},
|
|
"check_email_tpl_id": {
|
|
"_fnc": function (value, element, options) {
|
|
var email_tpl_id = $("input#email_tpl_id"),
|
|
email_type_id_data = email_tpl_id.data("email_tpl_id");
|
|
if(typeof email_type_id_data == "undefined" || email_tpl_id.val().trim() == "") {
|
|
return false;
|
|
}
|
|
return true;
|
|
|
|
},
|
|
msg: app.get_vars().email.val.email_template_req
|
|
}
|
|
}
|
|
},
|
|
"form_id": "form#emailAssignTemplateForm",
|
|
"ignore": "",
|
|
"rules": {
|
|
"event_id": {
|
|
check_event_id : true
|
|
},
|
|
"email_tpl_id": {
|
|
check_email_tpl_id : true
|
|
}
|
|
}
|
|
}
|
|
};
|
|
app._form._validate(options);
|
|
}
|
|
},
|
|
|
|
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_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=\"emailassign_template._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>'); }
|
|
});
|
|
}
|
|
},
|
|
|
|
"_typeheadjs" : {
|
|
"_load" : function(model) {
|
|
$('#'+model.id).typeahead({
|
|
source: function (query, process) {
|
|
var _form_data = $("form#emailAssignTemplateForm").data("email_assign_template");
|
|
var $url = app.get_vars().baseurl+ model.location;
|
|
var $items = new Array;
|
|
var postdata = {
|
|
"search": query,
|
|
"email_type_id" : _form_data.email_type_id
|
|
};
|
|
if(typeof _form_data.events_ids != "undefined"){postdata["events_ids"] = _form_data.events_ids;}
|
|
|
|
$items = [""];
|
|
$.ajax({
|
|
url: $url,
|
|
data: postdata,
|
|
dataType: "json",
|
|
type: "POST",
|
|
success: function (data) {
|
|
$.map(data, function (data) {
|
|
var group;
|
|
group = {
|
|
id: data[model.id],
|
|
name: data[model.name],
|
|
//extra : data.reservation,
|
|
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: model.name,
|
|
items:7,
|
|
minLength: 0,
|
|
showHintOnFocus: "all",
|
|
updater: function (item) {
|
|
var item = JSON.parse(item);
|
|
$("#"+model.id).data(model.store, item);
|
|
return item[model.name];
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};//end of return
|
|
// Pass in jQuery.
|
|
})(jQuery, this);
|
|
|
|
$(function() {
|
|
//load datatable
|
|
emailassign_template._grid.load();
|
|
});
|