text: var app=app||{},arrayTarget=[];app.init=function(){changeImage("#logoImage",'input[id="logo"]',"#EventForm"),$(document).on("shown.bs.tab",'a[data-toggle="tab"]',function(a){$.fn.dataTable.tables({visible:!0,api:!0}).columns.adjust()}),$("#modal-event").on("show.bs.modal",function(a){$('input[type="radio"], input[type="checkbox"]').length>0&&$('input[type="radio"], input[type="checkbox"]').iCheck({checkboxClass:"icheckbox_minimal-blue",radioClass:"iradio_minimal-blue"});var b=$(this);$("#date").daterangepicker({parentEl:b,locale:{format:"DD/MM/YYYY"}})}),$("#modal-event").on("shown.bs.modal",function(a){$("#modal-event #target").val(arrayTarget).trigger("change")});var a=$(".table-dynamic-event").DataTable({processing:!0,serverSide:!0,ajax:base_admin+"/ajax/event",responsive:!0,paging:!0,lengthChange:!0,searching:!0,ordering:!0,info:!0,autoWidth:!0,scrollX:!0,scrollCollapse:!0,columns:[{data:"id"},{data:"name"},{data:"type"},{data:"time"},{data:"discount"},{data:"code"},{data:"status"},{data:"action"}],columnDefs:[{width:"150px",targets:[3,5],class:"text-center"},{width:"100px",targets:[0,4,6],class:"text-center"},{width:"200px",targets:[2,-1],class:"text-center"},{targets:[-1],orderable:!1}],drawCallback:function(a){$('[data-toggle="tooltip"]').tooltip()},initComplete:function(a,b){$('[data-toggle="tooltip"]').tooltip()}});$("#EventForm").validator().on("submit",function(b){$("#addEventBtn").button("loading"),$(".alert").addClass("no-display"),b.isDefaultPrevented()?$("#EventBtn").button("reset"):(b.preventDefault(),app.EventFormSubmit(a))}),$(document).on("click",".table-action-delete",function(a){a.preventDefault();var b=$(this).data("id");$("#confirm-delete-modal #id").val(b),$("#confirm-delete-modal").modal({backdrop:"static",keyboard:!1})}),$("#confirm-delete-modal").on("click","#confirm-delete",function(b){$("#confirm-delete-modal #confirm-delete").button("loading");var c=$("#confirm-delete-modal #id").val();app.DeleteEvent(c,a)}),$(document).on("click",".table-action-edit, #modal-event .tab_edit_event",function(a){a.preventDefault(),$("#EventForm #name").prop("required",!1),$("#EventForm #slug").prop("required",!1),$("#EventForm #discount").prop("required",!1),$("#EventForm #code").prop("required",!1),$("#EventForm").validator("validate"),$("#EventForm #name").prop("required",!0),$("#EventForm #slug").prop("required",!0),$("#EventForm #discount").prop("required",!0),$("#EventForm #code").prop("required",!0),$("#EventForm").validator("update");var b=$(this).attr("data-id"),c=$(this).attr("data-lang");app.ClearFormEvent(c,"edit"),app.UpdateEvent(b,c)}),$(document).on("click","#addEvent",function(a){a.preventDefault(),$("#EventForm")[0].reset();var b=$(this).attr("data-lang");app.ClearFormEvent(b,"add"),$("#modal-event .tab_edit_event").attr("data-id","null"),arrayTarget=[],$("#target").empty(),$("#modal-event").modal("show")}),$(document).on("click","#EventBtn",function(a){a.preventDefault(),$("#EventForm").submit()}),$("#type").select2({placeholder:"Chọn đối tượng",allowClear:!0}).on("select2:select",function(a){var b=a.params.data;app.switchFunction(b.id)}),$("#type").on("select2:unselect",function(a){$("#target").empty()})},app.ClearFormEvent=function(a,b){"add"==b?($("#modal-event .nav-tabs").hide(),$("#modal-event #ttlModal").html("Thêm sự kiện mới"),$("#modal-event #action").val("insert")):($("#modal-event .nav-tabs").show(),$("#modal-event #ttlModal").html("Cập nhật sự kiện"),$("#modal-event #action").val("update")),$("#modal-event ul > li").removeClass("active"),$("#modal-event .tab_edit_event[data-lang="+a+"]").parent().addClass("active"),$("#modal-event #lang").val(a),$("#EventForm")[0].reset(),$("#modal-event #logoImage").attr("src",base_url+"/assets/backend/img/avatar.png"),$("#modal-event #content").summernote("code",""),$("#modal-event #target").val([]).trigger("change"),$("#modal-event #type").val("").trigger("change")},app.EventFormSubmit=function(a){$.ajax({url:base_admin+"/ajax/event",type:"post",data:$("#EventForm").serialize(),success:function(b){"200"==b.code?(Lobibox.notify("success",{title:"Thông báo",pauseDelayOnHover:!0,continueDelayOnInactiveTab:!1,icon:!1,sound:!1,msg:b.msg}),a.ajax.reload(null,!0),$("#EventBtn").button("reset"),$("#modal-event").modal("hide")):Lobibox.notify("warning",{title:"Thông báo",pauseDelayOnHover:!0,continueDelayOnInactiveTab:!1,icon:!1,sound:!1,msg:b.msg})},error:function(a,b,c){Lobibox.notify("warning",{title:"Thông báo",pauseDelayOnHover:!0,continueDelayOnInactiveTab:!1,icon:!1,sound:!1,msg:"Có lỗi trong quá trình xử lý"})}})},app.UpdateEvent=function(a,b){$.ajax({url:base_admin+"/ajax/event?lang="+b+"&id="+a,type:"get",success:function(a){if("200"==a.code){if(void 0!==a.data.mSchoolEventTranslationsAll&&$.each(a.data.mSchoolEventTranslationsAll,function(c,d){b==d.language_id&&($("#modal-event #id").val(a.data.id),$("#modal-event .tab_edit_event").attr("data-id",a.data.id),$("#modal-event #name").val(d.name),$("#modal-event #slug").val(d.slug),null!=d.logo&&$("#modal-event #logoImage").attr("src",base_url+"/img/"+d.logo),$("#modal-event #content").summernote("code",d.content))}),1==a.data.date_type?$("#modal-event #date_type_forever").iCheck("check"):$("#modal-event #date_type_period").iCheck("check"),a.data.start_date&&a.data.end_date){var c=new Date(a.data.start_date),d=new Date(a.data.end_date);$("#date").val(c.getDate()+"/"+(c.getMonth()+1)+"/"+c.getFullYear()+" - "+d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear())}else $("#date").val("");1==a.data.discount_type?$("#modal-event #discount_type_percent").iCheck("check"):$("#modal-event #discount_type_cash").iCheck("check"),$("#modal-event #discount").val(a.data.discount),$("#modal-event #code").val(a.data.code),$("#modal-event #type").val(a.data.type).trigger("change"),arrayTarget=a.data.target.split(","),app.switchFunction(a.data.type.toString()),$("#modal-event #position").val(a.data.position).trigger("change"),1==a.data.status?$("#modal-event #status").iCheck("check"):$("#modal-event #status").iCheck("uncheck"),$("#modal-event").modal("show")}else Lobibox.notify("warning",{title:"Thông báo",pauseDelayOnHover:!0,continueDelayOnInactiveTab:!1,icon:!1,sound:!1,msg:a.msg})},error:function(a,b,c){Lobibox.notify("warning",{title:"Thông báo",pauseDelayOnHover:!0,continueDelayOnInactiveTab:!1,icon:!1,sound:!1,msg:response.msg})}})},app.DeleteEvent=function(a,b){$.ajax({url:base_admin+"/ajax/event?action=delete&id="+a,type:"post",success:function(a){"200"==a.code?(Lobibox.notify("success",{title:"Thông báo",pauseDelayOnHover:!0,continueDelayOnInactiveTab:!1,icon:!1,sound:!1,msg:a.msg}),b.ajax.reload(null,!0)):Lobibox.notify("warning",{title:"Thông báo",pauseDelayOnHover:!0,continueDelayOnInactiveTab:!1,icon:!1,sound:!1,msg:a.msg}),$("#confirm-delete-modal #confirm-delete").button("reset"),$("#confirm-delete-modal").modal("hide")},error:function(a,b,c){Lobibox.notify("warning",{title:"Thông báo",pauseDelayOnHover:!0,continueDelayOnInactiveTab:!1,icon:!1,sound:!1,msg:"Có lỗi trong quá trình xử lý"}),$("#confirm-delete-modal #confirm-delete").button("reset"),$("#confirm-delete-modal").modal("hide")}})},app.switchFunction=function(a){var b=$("#target");switch(b.empty(),a){case"1":$.ajax({type:"GET",dataType:"json",url:base_admin+"/ajax/type"}).then(function(a){$.map(a.data,function(a){var c=new Option(a.name,a.id,!1,!1);b.append(c)})}).then(function(a){$("#modal-event #target").val(arrayTarget).trigger("change")});break;case"2":$.ajax({type:"GET",dataType:"json",url:base_admin+"/ajax/school"}).then(function(a){$.map(a.data,function(a){var c=new Option(a.name,a.id,!1,!1);b.append(c)})});break;case"3":$.ajax({type:"GET",dataType:"json",url:base_admin+"/ajax/customer"}).then(function(a){$.map(a.data,function(a){var c=new Option(a.name,a.id,!1,!1);b.append(c)})});break;default:$.ajax({type:"GET",dataType:"json",url:base_admin+"/ajax/customer"}).then(function(a){$.map(a.data,function(a){var c=new Option(a.name,a.id,!1,!1);b.append(c)})})}},$(function(){app.init()});