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.
936 lines
44 KiB
936 lines
44 KiB
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+" <br/><br><span class='label label-danger' style='font-size: 12px;'>"+app.get_vars()._app.cma_msg.note+"</span>",
|
|
"_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 '<div class="row-fluid" align="center"><div class="row" align="center">'+action_btns+'</div></div>';
|
|
}},
|
|
{ "data": "email_push_date_created" },
|
|
{ "data": "email_custom_author" }
|
|
],
|
|
"fnDrawCallback": function() {
|
|
app._tooltip._hide();
|
|
$('#email_push_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": [1], className : "truncate-content-text custom-popover-tooltip"},
|
|
{ "targets": [2], className : "truncate-content-text custom-popover-tooltip", "orderable": false},
|
|
{ "targets": [3], "orderable": true, className : "truncate-content-text custom-popover-tooltip", "orderable": false},
|
|
{ "targets": [4], "orderable": false},
|
|
{ "targets": [5], "orderable": false},
|
|
{ "targets": [8], "orderable": false},
|
|
{ "targets": [6], "orderable": false}
|
|
],
|
|
"initComplete": function(settings, json) {
|
|
//run tooltip
|
|
app._tooltip._hide();
|
|
app._tooltip._pop();
|
|
|
|
$("div#email_push_list_length").css({"width" : "20%", "float":"left"});
|
|
$("select[name='email_push_list_length']").css({"width" : "70px"});
|
|
|
|
//add custom button beside searchbox
|
|
$("div.toolbar").html('<div class="col-sm-3.0 pull-right"><button onclick="email_push._create.modal();" ' +
|
|
'class="btn btn-primary btn-sm mr-xs create">' +
|
|
'<i class="fa fa-fw fa-thumb-tack"></i> '+app.get_vars().email.btn.add_email_push+'</button></div>');
|
|
//fire search filter event
|
|
}
|
|
});
|
|
email_push.set_vars({_email_push : table});
|
|
}
|
|
},
|
|
|
|
"_prepare" : {
|
|
"_data_to_server" : function(action){
|
|
var _form = $("form#emailPushForm"),
|
|
form_data = _form.serializeArray(),
|
|
datastores = ["city_location_id[]", "event_type_id[]"],
|
|
dataStoresIds = [],
|
|
filters_val = {"city_location_id" : "city", "event_type_id" : "event_type"},
|
|
sdate = "";
|
|
|
|
$.map(form_data, function(x, t){
|
|
var getIndexOf = datastores.indexOf(x.name);
|
|
if(getIndexOf != -1){
|
|
if(dataStoresIds.indexOf(x.name) == -1){
|
|
dataStoresIds.push(x.name);
|
|
}
|
|
} else if(x.name == "subscription_date") {
|
|
var drange = (form_data[t].value).split(" - ");
|
|
form_data.push({"name": "subscription_date_formatted", "value": moment(drange[0], 'DD/MM/YYYY', true).format("YYYY-MM-DD") + " - " + moment(drange[1], 'DD/MM/YYYY', true).format("YYYY-MM-DD")});
|
|
}
|
|
});
|
|
|
|
$.map(dataStoresIds, function(selector, v){
|
|
var remBrackets = selector.replace("[]", "");
|
|
var text = "";
|
|
$.each($("select#"+remBrackets).find('option:selected'), function(){
|
|
text += $(this).text()+", ";
|
|
});
|
|
form_data.push({"name": filters_val[remBrackets], "value": text.replace(/, $/, '')});
|
|
});
|
|
|
|
if(action == "edit"){
|
|
var _get_data = _form.data("email_push");
|
|
form_data.push({"name" : "email_custom_id", "value" : _get_data.email_custom_id});
|
|
}
|
|
|
|
return form_data;
|
|
},
|
|
|
|
"_set_data" : function(data){
|
|
var rawData = data.action;
|
|
|
|
//custom status
|
|
$("#email_custom_status").val(rawData.email_custom_status);
|
|
$("#email_custom_sendto").val(rawData.email_custom_sendto);
|
|
|
|
//set event
|
|
var selectedFilters = [];
|
|
$('select.event_id').html("<option value='"+rawData.event_id+"'>" + data.event_title + "</option>")
|
|
.selectpicker('val', rawData.event_id)
|
|
.trigger('change.abs.preserveSelected')
|
|
.selectpicker('refresh');
|
|
|
|
if(rawData.subscription_date != null){
|
|
var subscription_date = $("#subscription_date");
|
|
subscription_date.show().prop("disabled", false).val(rawData.subscription_date);
|
|
selectedFilters.push(3);
|
|
$(".custom-filters-3").show();
|
|
}
|
|
if(rawData.city_location_id != null){
|
|
var city_location_id = $("select.city_location_id");
|
|
var city = (rawData.city).split(", "),
|
|
cli="";
|
|
$.map((rawData.city_location_id).split(", "), function(x,y){
|
|
cli += "<option value='"+x+"'>" + city[y] + "</option>";
|
|
});
|
|
|
|
city_location_id.html(cli)
|
|
.selectpicker('val', (rawData.city_location_id).split(", "))
|
|
.selectpicker('refresh');
|
|
|
|
email_push.changFilterPar.filterBy_1();
|
|
selectedFilters.push(1);
|
|
}
|
|
if(rawData.event_type_id != null){
|
|
var event_type_id = $("select.event_type_id");
|
|
var event_type = (rawData.event_type).split(", "),
|
|
et="";
|
|
$.map((rawData.event_type_id).split(", "), function(x,y){
|
|
et += "<option value='"+x+"'>" + event_type[y] + "</option>";
|
|
});
|
|
event_type_id.html(et)
|
|
.selectpicker('val', (rawData.event_type_id).split(", "))
|
|
.selectpicker('refresh');
|
|
email_push.changFilterPar.filterBy_2();
|
|
selectedFilters.push(2);
|
|
}
|
|
if(parseInt(rawData.email_custom_sendto) == 2) { //open subscriber field when selected "specific subscribers"
|
|
if (rawData.subscriber_id != null) {
|
|
var subscriber_id = $("select.subscriber_id");
|
|
var subnames = (data.email_subscribers).split(", "),
|
|
subscribers="";
|
|
$.map((rawData.subscriber_id).split(", "), function(x,y){
|
|
subscribers += "<option value='"+x+"'>" + subnames[y] + "</option>";
|
|
});
|
|
subscriber_id.html(subscribers)
|
|
.selectpicker('val', (rawData.subscriber_id).split(", "))
|
|
.trigger('change.abs.preserveSelected')
|
|
.prop("disabled", false)
|
|
.selectpicker('refresh');
|
|
}
|
|
$('#subscriber_list').show();
|
|
}else {
|
|
//selected all susbcribers
|
|
email_push.changFilterPar.updateSubList();
|
|
}
|
|
|
|
//select filters
|
|
$('select.email_filter_id').selectpicker('val', selectedFilters)
|
|
.trigger('change.abs.preserveSelected')
|
|
.selectpicker('refresh');
|
|
$('select#email_filter_id').data("selectedFilters", selectedFilters);
|
|
}
|
|
},
|
|
|
|
"_validate" : {
|
|
"_init": function (action) {
|
|
var options = {
|
|
boot_box : {
|
|
"message": (action == "add")
|
|
? app.get_vars().email.cmsg.add_email_push
|
|
: app.get_vars().email.cmsg.save_changes
|
|
,
|
|
"_continue": function () {
|
|
var _form_ = $("form#emailPushForm");
|
|
(action == "add")
|
|
? email_push._create.save(_form_)
|
|
: email_push._update.save(_form_)
|
|
}
|
|
},
|
|
"validation": {
|
|
"custom": {
|
|
"rules": {
|
|
"check_event_id": {
|
|
"_fnc": email_push._validate.check_event_id,
|
|
msg: app.get_vars().email.val.email_event_req
|
|
},
|
|
"checkLocation": {
|
|
"_fnc": email_push._validate.checkLocation,
|
|
msg: "This field is required!"
|
|
},
|
|
"checkEventType": {
|
|
"_fnc": email_push._validate.checkEventType,
|
|
msg: "This field is required!"
|
|
},
|
|
|
|
"invalid_date": {
|
|
"_fnc": email_push._validate.check_subAgeDate,
|
|
msg: app.get_vars().email.val.invlaid_date
|
|
},
|
|
|
|
"check_subscribers": {
|
|
"_fnc": email_push._validate.check_subscribers,
|
|
msg: "Select at least one subscriber."
|
|
},
|
|
|
|
"checkAllSubscribers": {
|
|
"_fnc": email_push._validate.checkAllSubscribers,
|
|
msg: "No subscribers found on this query."
|
|
}
|
|
}
|
|
},
|
|
"form_id": "form#emailPushForm",
|
|
"rules": {
|
|
"event_id[]": {
|
|
check_event_id: true
|
|
},
|
|
"city_location_id[]": {
|
|
checkLocation: true
|
|
},
|
|
"event_type_id[]": {
|
|
checkEventType: true
|
|
},
|
|
"subscription_date": {
|
|
"invalid_date" : true
|
|
},
|
|
"email_filter_id[]": {
|
|
"required": false
|
|
},
|
|
"email_custom_sendto": {
|
|
//"required": true,
|
|
"checkAllSubscribers" : true
|
|
},
|
|
"subscriber_id[]": {
|
|
check_subscribers: {
|
|
depends: email_push._validate.checkSubscribersIf
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
app._form._validate(options);
|
|
},
|
|
|
|
"checkAllSubscribers" : function(value, element, options) {
|
|
var sendTo = $("select#email_custom_sendto:visible"),
|
|
creation_status = parseInt($("#email_custom_status option:selected").val());
|
|
var sel = parseInt(sendTo.find("option:selected").val());
|
|
if(sel == 0 && creation_status == 1){
|
|
return false;
|
|
} else if(sel == 1 && creation_status == 1) {
|
|
var datastore = sendTo.data("email_custom_sendto");
|
|
if (typeof datastore == "undefined" || typeof datastore["email_custom_sendto"] == "undefined" || datastore["email_custom_sendto"].trim() == "") {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
},
|
|
|
|
"checkSubscribersIf" : function(value, element, options){
|
|
var validate = false;
|
|
var sendTo = $("select#email_custom_sendto option:selected").val(),
|
|
creation_status = parseInt($("#email_custom_status option:selected").val());
|
|
if (parseInt(sendTo) == 2 && creation_status ==1) {
|
|
if (!email_push._validate.check_event_id(value, element, options)) {
|
|
validate = true;
|
|
} else if (!email_push._validate.checkLocation(value, element, options)) {
|
|
validate = true;
|
|
} else if (!email_push._validate.checkEventType(value, element, options)) {
|
|
validate = true;
|
|
} else if (!email_push._validate.check_subscribers(value, element, options)) {
|
|
validate = true;
|
|
} else if (!email_push._validate.check_subAgeDate(value, element, options)) {
|
|
validate = true;
|
|
}
|
|
}
|
|
return validate;
|
|
},
|
|
|
|
"check_subAgeDate": function (value, element, options) {
|
|
var subAGe = $("input#subscription_date:visible"),
|
|
creation_status = parseInt($("#email_custom_status option:selected").val());
|
|
if (subAGe.length > 0 && creation_status == 1) {
|
|
var dater = subAGe.val();
|
|
if(dater == ""){
|
|
return false;
|
|
} else if(dater !=""){
|
|
var checkdrange = dater.split(" - ");
|
|
if(checkdrange.length <=1){
|
|
return false;
|
|
} else {
|
|
var startdrange = moment(checkdrange[0], "DD/MM/YYYY", true),
|
|
enddrange = moment(checkdrange[1], "DD/MM/YYYY", true);
|
|
if (!startdrange.isValid() || !enddrange.isValid()) {
|
|
return false;
|
|
} else if(!moment(checkdrange[1], "DD/MM/YYYY").isSameOrAfter(moment(checkdrange[0], "DD/MM/YYYY"))){
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
},
|
|
|
|
"check_subscribers": function (value, element, options) {
|
|
var sendTo = $("select#email_custom_sendto option:selected").val(),
|
|
creation_status = parseInt($("#email_custom_status option:selected").val());
|
|
if (parseInt(sendTo) == 2 && creation_status ==1) {
|
|
var datastore = $("select.subscriber_id:visible"),
|
|
countOptions = datastore.val();
|
|
|
|
if (typeof countOptions == "undefined" || countOptions == null) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
},
|
|
|
|
"check_event_id": function (value, element, options) {
|
|
var event_id = $("select.event_id:visible"),
|
|
countOptions = event_id.val();
|
|
if (typeof countOptions == "undefined" || countOptions == null || countOptions == "") {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
"checkLocation": function (value, element, options) {
|
|
var datastore = $("select.city_location_id:visible"),
|
|
countOptions = datastore.val(),
|
|
creation_status = parseInt($("#email_custom_status option:selected").val());
|
|
if(creation_status ==1) {
|
|
if (typeof countOptions == "undefined" || countOptions == null) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
},
|
|
"checkEventType": function (value, element, options) {
|
|
var datastore = $("select.event_type_id:visible"),
|
|
countOptions = datastore.val(),
|
|
creation_status = parseInt($("#email_custom_status option:selected").val());
|
|
if(creation_status ==1) {
|
|
if (typeof countOptions == "undefined" || countOptions == null) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
},
|
|
|
|
changFilterPar : {
|
|
"_init" : function() {
|
|
//reinstialize typeahead
|
|
email_push._typeheadjs._load({
|
|
location: "list_email_push",
|
|
actionsBox : false,
|
|
id: "id",
|
|
name: "name",
|
|
store: {
|
|
store_ids: "event_id"
|
|
},
|
|
updateSubList: email_push.changFilterPar.updateSubList
|
|
});
|
|
|
|
email_push._typeheadjs._load({
|
|
location: "list_email_recipient/",
|
|
actionsBox : true,
|
|
id: "id",
|
|
name: "name",
|
|
store: {
|
|
store_ids: "subscriber_id"
|
|
},
|
|
initData: function (store_ids) {
|
|
return email_push.changFilterPar.filterSubscribers(store_ids);
|
|
}
|
|
});
|
|
|
|
email_push._typeheadjs._load({
|
|
location: "list_city_location/",
|
|
actionsBox : true,
|
|
id: "id",
|
|
name: "name",
|
|
store: {
|
|
store_ids: "city_location_id"
|
|
},
|
|
updateSubList: email_push.changFilterPar.updateSubList
|
|
});
|
|
|
|
email_push._typeheadjs._load({
|
|
location: "list_event_type/",
|
|
actionsBox : true,
|
|
id: "id",
|
|
name: "name",
|
|
|
|
store: {
|
|
store_ids: "event_type_id"
|
|
},
|
|
updateSubList: email_push.changFilterPar.updateSubList
|
|
});
|
|
|
|
moment.locale('fr');
|
|
$('#subscription_date_drange').daterangepicker({
|
|
locale: {
|
|
format: 'DD/MM/YYYY',
|
|
cancelLabel: "Annuler",
|
|
applyLabel: "Appliquer",
|
|
customRangeLabel: "Periode personnalisée",
|
|
"daysOfWeek": 'di_lu_ma_me_je_ce_sa'.split('_'),
|
|
"monthNames": 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_')
|
|
},
|
|
"showDropdowns": true,
|
|
"parentEl": "body",
|
|
startDate: moment(),
|
|
endDate: moment(),
|
|
maxDate: moment(),
|
|
ranges: {
|
|
'Revenir à aujourd\'hui': [moment(), moment()],
|
|
'Hier': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
|
//'Les 7 derniers jours': [moment().subtract(6, 'days'), moment()],
|
|
//'Les 30 derniers jours': [moment().subtract(29, 'days'), moment()],
|
|
//'Ce mois-ci': [moment().startOf('month'), moment().endOf('month')],
|
|
'Mois précédent': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
|
|
}
|
|
}, function (start, end, label) {
|
|
$('#subscription_date').val(start.format('DD/MM/YYYY') + ' - ' + end.format('DD/MM/YYYY'));
|
|
//check first if subscribers list are not empty
|
|
app._form._resetValidationByField("subscription_date_drange");
|
|
email_push.changFilterPar.updateSubList();
|
|
});
|
|
},
|
|
|
|
"updateSubList" : function(){
|
|
//check first if subscribers list are not empty
|
|
var sendTo = $("#email_custom_sendto:visible option:selected"),
|
|
sendToVal = parseInt(sendTo.val());
|
|
if(sendToVal == 2) {
|
|
var ids = $("select.subscriber_id option:selected").val();
|
|
if (typeof ids != "undefined" && ids != null) {
|
|
email_push.changFilterPar.refresh_sublist({
|
|
"store_ids" : "subscriber_id"
|
|
}, 2);
|
|
}
|
|
} else if(sendToVal == 1) {
|
|
email_push.changFilterPar.refresh_sublist({
|
|
"store_ids" : "email_custom_sendto"
|
|
}, 1);
|
|
}
|
|
},
|
|
|
|
"filterSubscribers" : function(store_ids){
|
|
var data = {},
|
|
filters = ["event_id","city_location_id", "event_type_id","subscription_date", "subscriber_id"],
|
|
filters_val = {"city_location_id" : "city", "event_type_id" : "event_type"};
|
|
$.each(filters, function(index, val){
|
|
var _datastore = $("#"+val+":visible");
|
|
if(val != "subscription_date" && _datastore.val() != null && _datastore.length > 0){
|
|
var values = _datastore.val();
|
|
if(typeof values == "string"){
|
|
data[val] = values;
|
|
} else {
|
|
if(typeof filters_val[val] != "undefined"){
|
|
var val_text = "";
|
|
$.each(_datastore.find('option:selected'), function(){
|
|
val_text += $(this).text()+", ";
|
|
});
|
|
data[filters_val[val]] = val_text.replace(/, $/, '');
|
|
}
|
|
data[val] = values.join(", ");
|
|
}
|
|
} else if(val == "subscription_date"){
|
|
//date range
|
|
var drange = $("input#subscription_date:visible");
|
|
if (email_push._validate.check_subAgeDate("", "", "") && drange.length > 0) {
|
|
var drange = (drange.val()).split(" - ");
|
|
data[val] = moment(drange[0], 'DD/MM/YYYY', true).format("YYYY-MM-DD") + " - " + moment(drange[1], 'DD/MM/YYYY', true).format("YYYY-MM-DD");
|
|
}
|
|
}
|
|
});
|
|
return data;
|
|
},
|
|
|
|
"refresh_sublist" : function(store, subs){ //reload subscribers list
|
|
var filterBy = (subs == 1)?"":"subscriber_id";
|
|
var data = email_push.changFilterPar.filterSubscribers(filterBy);
|
|
data["email_custom_sendto"] = subs;
|
|
$.ajax({
|
|
url : app.get_vars().baseurl+"refresh_sub_list/",
|
|
data : data,
|
|
type : "POST",
|
|
success : function(result){
|
|
if(subs == 1) {
|
|
var sub = $("#" + store.store_ids);
|
|
sub.data(store.store_ids, result);
|
|
} else {
|
|
var subscriber_id = $("select.subscriber_id");
|
|
var subnames = (result.subscriber_id != "")?(result.subscriber_name).split(", "):[],
|
|
subids = (result.subscriber_id != "")?(result.subscriber_id).split(", "):[],
|
|
subscribers="";
|
|
$.map(subids, function(x,y){
|
|
subscribers += "<option value='"+x+"'>" + subnames[y] + "</option>";
|
|
});
|
|
subscriber_id.html(subscribers)
|
|
.selectpicker('val', null)
|
|
.selectpicker('refresh')
|
|
.selectpicker('val', subids)
|
|
.trigger('change.abs.preserveSelected')
|
|
.selectpicker('refresh');
|
|
}
|
|
//$("#emailPushForm").validate();
|
|
}
|
|
});
|
|
},
|
|
//localisation
|
|
filterBy_1 : function(reset_spicker){
|
|
$("#filtersByLocalisation").show();
|
|
app._form._resetValidationByField("city_location_id");
|
|
var field = $("select.city_location_id");
|
|
field.prop('disabled', false);
|
|
field.trigger('change.abs.preserveSelected');
|
|
field.selectpicker("refresh");
|
|
},
|
|
|
|
filterBy_2 : function(reset_spicker){
|
|
$("#filterByInterest").show();
|
|
app._form._resetValidationByField("event_type_id");
|
|
var field = $("select.event_type_id");
|
|
field.prop('disabled', false);
|
|
field.trigger('change.abs.preserveSelected');
|
|
field.selectpicker("refresh");
|
|
},
|
|
|
|
filterBy_3 : function(reset_spicker){
|
|
$("#filterBySubAge").show();
|
|
app._form._resetValidationByField("subscription_date");
|
|
var field = $("#subscription_date");
|
|
field.prop('disabled', false).val("");
|
|
|
|
}
|
|
}
|
|
};//end of return
|
|
// Pass in jQuery.
|
|
})(jQuery, this);
|
|
|
|
$(function() {
|
|
var options = [];
|
|
|
|
$( '#emailFilter a, #emailFilter input' ).on( 'click', function( event ) {
|
|
email_push.changFilterPar.selectFilters(event);
|
|
return false;
|
|
});
|
|
|
|
//load datatable
|
|
email_push._grid.load();
|
|
|
|
//show search bar for specific subscribers
|
|
$("#email_custom_sendto").on('change', function(){
|
|
var subscriber_id =$("select.subscriber_id");
|
|
if($('#email_custom_sendto :selected').val() == 2) {
|
|
$("#subscriber_list").show();
|
|
subscriber_id.prop("disabled", false);
|
|
subscriber_id.trigger('change.abs.preserveSelected');
|
|
subscriber_id.selectpicker("refresh");
|
|
} else {
|
|
subscriber_id.prop("disabled", true);
|
|
subscriber_id.val([]);
|
|
subscriber_id.trigger('change.abs.preserveSelected');
|
|
subscriber_id.selectpicker("refresh");
|
|
app._form._resetValidationByField("subscriber_id");
|
|
$("#subscriber_list").hide();
|
|
$(this).removeData("email_custom_sendto");
|
|
email_push.changFilterPar.updateSubList();
|
|
}
|
|
});
|
|
|
|
$('select#email_filter_id').selectpicker({
|
|
actionsBox : true,
|
|
multiple : true
|
|
}).on('changed.bs.select', function (e) {
|
|
var optionsSelected = $(this).val(),
|
|
os = $(this).val(),
|
|
selectedFilters = (typeof $(this).data("selectedFilters") != "undefined")?$(this).data("selectedFilters"):[];
|
|
|
|
$.map(selectedFilters, function(x,y){
|
|
if(optionsSelected != null && optionsSelected.indexOf(x.toString()) == -1){ //hide filters when visible
|
|
var parentDiv = $(".custom-filters-"+x);
|
|
parentDiv.find(".filter-"+x).val([]).prop("disabled", true).trigger('change.abs.preserveSelected').selectpicker("refresh");
|
|
parentDiv.hide();
|
|
} else if(optionsSelected != null && optionsSelected.indexOf(x) != -1){ // keep selected items from the filter
|
|
optionsSelected.splice(optionsSelected.indexOf(x), 1);
|
|
}
|
|
});
|
|
if(os == null) { // hide all filters
|
|
var parentDiv = $(".custom-filters");
|
|
parentDiv.find(".selectpicker").val([]).prop("disabled", true).trigger('change.abs.preserveSelected').selectpicker("refresh");
|
|
parentDiv.hide();
|
|
}
|
|
|
|
var optLength = (optionsSelected!= null)?optionsSelected.length:0;
|
|
|
|
if(optLength > 0) {
|
|
for (var x = 0; x < optLength; x++) {
|
|
var reset_spicker = true;
|
|
app._form._resetValidationByField("subscriber_id");
|
|
email_push.changFilterPar["filterBy_" + optionsSelected[x]](reset_spicker);
|
|
}
|
|
}
|
|
//update list
|
|
$("#email_custom_sendto").removeData("email_custom_sendto");
|
|
email_push.changFilterPar.updateSubList();
|
|
|
|
//update selected data
|
|
$(this).data("selectedFilters", $(this).val());
|
|
});
|
|
//initialize selects
|
|
email_push.changFilterPar._init();
|
|
});
|
|
|