var email_push = (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 = $("#emailPushForm");
bootbox.dialog({
"title": app.get_vars().email.title.add_email_push,
"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_push,
"class": "btn btn-success",
"callback": function () {
email_push._validate._init('add');
return false;
}
}
]
}).on('shown.bs.modal', function() {
email_push._typeheadjs._store._reset();
_form.show();
app._form._reset(this);
//submit form on keypress or enter
app._form._form_submit_on_keypress("emailPushForm", function(){
email_push._validate._init('add');
});
$(this).off('shown.bs.modal');
}).on('hide.bs.modal', function(e) {
app._form._resetFormValidation("#emailPushForm");
app._form._reset(this);
email_push._typeheadjs._store._reset();
$(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_push",
"type" : "POST",
"dataType": "json",
"data" : email_push._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_push.get_vars()._email_push).ajax.reload( null, false );
//location.reload();
//window.setTimeout(function(){window.location.href = app.get_vars().baseurl+"email_push";},1000);
}
}
}
});
}
},
"_update" : {
"modal" : function(row){
app.modal.focusout_solution("on");
var rowData = (email_push.get_vars()._email_push).row(row).data();
var _form = $("#emailPushForm");
_form.data("email_push", rowData.action);
bootbox.dialog({
"title": app.get_vars().email.title.update_email_push,
"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_push._validate._init('edit');
return false;
}
}
]
}).on('shown.bs.modal', function() {
_form.show();
app._form._reset(this);
//jQuery('.selectpicker').selectpicker('removeDiv');
email_push._prepare._set_data(rowData);
//submit form on keypress or enter
app._form._form_submit_on_keypress("emailPushForm", function(){
email_push._validate._init('edit');
});
$(this).off('shown.bs.modal');
}).on('hide.bs.modal', function(e) {
app._form._resetFormValidation("#emailPushForm");
app._form._reset(this);
email_push._typeheadjs._store._reset();
$(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_push",
type : "POST",
dataType : "json",
data : email_push._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_push.get_vars()._email_push).ajax.reload( null, false );
//window.setTimeout(function(){window.location.href = app.get_vars().baseurl+"email_push";},1000);
//location.reload();
}
}
}
});
}
},
"_delete" : {
"confirm" : function(email_custom_id){
app.modal.confirm_box({
"message" : app.get_vars().email.cmsg.delete_email_push+"
"+app.get_vars()._app.cma_msg.note+"",
"_continue" : function() {
email_push._delete.save(email_custom_id);
},
"id" : "delete_confirm_box",
"className" : "delete_confirm_box"
});
},
"save" : function(email_custom_id){
$.ajax({
"url" : app.get_vars().baseurl+"delete_email_push/",
"type" : "POST",
"data" : {
"email_custom_id" : email_custom_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_push.get_vars()._email_push).ajax.reload(null, false);
//window.setTimeout(function(){window.location.href = app.get_vars().baseurl+"email_push";},1000);
}
}
}
});
}
},
"_typeheadjs" : {
"_load" : function(model) {
$('#'+model.store.store_ids).selectpicker({
actionsBox : model.actionsBox,
liveSearch : true,
multiple : true
}).ajaxSelectPicker({
ajax: {
url:app.get_vars().baseurl+ model.location,
dataType: 'json',
data: function () {
var params = {
search: '{{{q}}}'
};
if(typeof model.initData != "undefined" && typeof model.initData =="function"){
params = $.extend(params, model.initData(model.store.store_ids));
}
return params;
}
},
locale : {
emptyTitle : ""
},
preprocessData: function (data) {
var i, l = data.length,
arr = [];
if (l) {
for (i = 0; i < l; i++) {
if (data[i].name.toLowerCase().indexOf(this.plugin.query) != -1 || data[i].name.toLowerCase().indexOf(this.plugin.query) != -1) {
arr.push($.extend(true, data[i], {
text: data[i].name,
value: data[i].id,
data: {
subtext: data[i].name
}
}));
}
}
}
return arr;
}
}).on('changed.bs.select', function (e) {
app._form._resetValidationByField(model.store.store_ids);
if(typeof model.updateSubList != "undefined" && typeof model.updateSubList == "function"){
model.updateSubList();
}
}).on('hide.bs.select', function (e) {
//$("#emailPushForm").validate();
});
},
"_store" : {
"_deleteItem" : function(_this, store_ids, store_values, deleteId){
var datastore = $("#"+store_ids),
data = datastore.data(store_ids),
ids = data[store_ids].split(", "),
values = data[store_values].split(", ");
$.map(ids, function(val, index){
if(deleteId == val){
ids.splice(index, 1);
values.splice(index, 1);
return false;
}
});
var data = new Object;
data[store_ids] = ids.join(", ");
data[store_values] = values.join(", ");
datastore.data(store_ids, data);
_this.remove();
//immediately reload subscribers list once a filter is removed
if(store_ids != "subscriber_id"){
email_push.changFilterPar.updateSubList();
}
},
"_reset":function(){
$('.city_location_id').val([]).prop("disabled", true).trigger('change.abs.preserveSelected').selectpicker("refresh");
$('.event_type_id').val([]).prop("disabled", true).trigger('change.abs.preserveSelected').selectpicker("refresh");
$('.subscriber_id').val([]).prop("disabled", true).trigger('change.abs.preserveSelected').selectpicker("refresh");
$('.email_filter_id').val([]).trigger('change.abs.preserveSelected').selectpicker("refresh");
$('.event_id').selectpicker('val',[]).trigger('change.abs.preserveSelected').selectpicker("refresh");
$("#email_custom_sendto").removeData("email_custom_sendto");
$("#subscription_date").val("").prop("disabled", true);
$("div.custom-filters").hide();
$("div#subscriber_list").hide();
}
}
},
"_grid" : {
"load" : function(){
var table = $('#email_push_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_push_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": "event_filters" },
{ "data": "email_subscribers" },
{ "data": "email_sent" },
{ "data": "email_onqueue" },
{ "data": "action" , render : function(data, type, full, meta){
var action_btns = "";
if(parseInt(full.action.email_custom_status) == 0) {
action_btns += app.grid.create_action_btn(app.get_vars()._app.action._edit, "pencil", "success", "email_push._update.modal("+meta.row+")");
}
action_btns += app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", "email_push._delete.confirm("+full.action.email_custom_id +")");
return '