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.
270 lines
12 KiB
270 lines
12 KiB
var city_location = (function ($, window, jQuery) {
|
|
var _vars_ = {};
|
|
|
|
return {
|
|
"set_vars": function (options) {
|
|
$.extend(_vars_, options || {});
|
|
},
|
|
"get_vars" : function(){
|
|
return _vars_;
|
|
},
|
|
|
|
"_load" : function(){
|
|
|
|
},
|
|
|
|
"_add" : {
|
|
"modal" : function(){
|
|
//config
|
|
$("h4#cityModalTitle").text("").text(app.get_vars().system_config.title.add_new_city);
|
|
$("button#updateCityBtn").hide();
|
|
$("button#addNewCityBtn").show();
|
|
|
|
$("#cityModal").modal({backdrop: 'static',keyboard : true}).on('shown.bs.modal', function() {
|
|
|
|
app._form._reset(this);
|
|
$("#city").focus();
|
|
|
|
//submit form on keypress or enter
|
|
app._form._form_submit_on_keypress("cityForm", function(){
|
|
city_location._validate('add');
|
|
});
|
|
|
|
$('#cityModal').off('shown.bs.modal');
|
|
|
|
}).on('hidden.bs.modal', function () {
|
|
|
|
app._form._resetFormValidation("#cityModal");
|
|
app._form._reset(this);
|
|
$(this).data('bs.modal', null);
|
|
$('#cityModal').off('hidden.bs.modal');
|
|
|
|
});
|
|
},
|
|
|
|
"save" : function(form){
|
|
$.ajax({
|
|
url : app.get_vars().baseurl+"admin/city_location/add_city",
|
|
type : "POST",
|
|
dataType : "json",
|
|
data : $(form).serializeArray(),
|
|
success : function(result){
|
|
if(app.isalive(result)) {
|
|
app._notify(result.mtype, result.message);
|
|
if (result.mtype == "success") {
|
|
//reload grid
|
|
$("#cityModal").modal("hide");
|
|
(city_location.get_vars()._city_location).ajax.reload(null, false);
|
|
//window.setTimeout(function(){window.location.href = app.get_vars().baseurl+"city_location";},1000);
|
|
} else {
|
|
var x = 0;
|
|
$.map(result.mdetail, function (input, i) {
|
|
app._form._populate_field_error(input.field, input.message, x);
|
|
x++;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
"_edit" : {
|
|
"modal" : function(city_location_id, city){
|
|
//config
|
|
$("#cityModal").data("city_location_id", city_location_id);
|
|
$("h4#cityModalTitle").text("").text(app.get_vars().system_config.title.edit_city);
|
|
|
|
$("button#addNewCityBtn").hide();
|
|
$("button#updateCityBtn").show();
|
|
|
|
$("#cityModal").modal({backdrop: 'static',keyboard : true}).on('shown.bs.modal', function() {
|
|
|
|
app._form._reset(this);
|
|
|
|
$("#city").val(city).focus();
|
|
//submit form on keypress or enter
|
|
app._form._form_submit_on_keypress("cityForm", function(){
|
|
city_location._validate('edit');
|
|
});
|
|
|
|
$('#cityModal').off('shown.bs.modal');
|
|
|
|
}).on('hidden.bs.modal', function () {
|
|
|
|
app._form._resetFormValidation("#cityModal");
|
|
app._form._reset(this);
|
|
$(this).data('bs.modal', null);
|
|
$('#cityModal').off('hidden.bs.modal');
|
|
|
|
});
|
|
},
|
|
|
|
"save" : function(form){
|
|
var city_location_id = $("#cityModal").data("city_location_id");
|
|
$.ajax({
|
|
"url" : app.get_vars().baseurl+"admin/city_location/edit_city/"+city_location_id,
|
|
"type" : "POST",
|
|
"dataType" : "json",
|
|
"data" : $(form).serializeArray(),
|
|
"success" : function(result){
|
|
if(app.isalive(result)) {
|
|
app._notify(result.mtype, result.message);
|
|
if (result.mtype == "success") {
|
|
//reload grid
|
|
$("#cityModal").modal("hide");
|
|
(city_location.get_vars()._city_location).ajax.reload(null, false);
|
|
} else {
|
|
var x = 0;
|
|
$.map(result.mdetail, function (input, i) {
|
|
app._form._populate_field_error(input.field, input.message, x);
|
|
x++;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
"_delete" : {
|
|
"confirm" : function(city_location_id, order){
|
|
app.modal.confirm_box({
|
|
"message" : app.get_vars().system_config.cma_msg.delete_city+" <b>[#"+order+"]</b>?<br/><br><span class='label label-danger' style='font-size: 12px;'>"+app.get_vars()._app.cma_msg.note+"</span>",
|
|
"_continue" : function() {
|
|
city_location._delete.save(city_location_id);
|
|
},
|
|
"id" : "delete_confirm_box",
|
|
"className" : "delete_confirm_box"
|
|
});
|
|
},
|
|
|
|
"save" : function(city_location_id){
|
|
$.ajax({
|
|
"url" : app.get_vars().baseurl+"admin/city_location/delete_city/"+city_location_id,
|
|
"type" : "POST",
|
|
"data" : {
|
|
"ask" : "x0dkdp"
|
|
},
|
|
"dataType" : "json",
|
|
"success" : function(result){
|
|
if(app.isalive(result)) {
|
|
app._notify(result.mtype, result.message);
|
|
if (result.mtype == "session_timeout") {
|
|
window.setTimeout(function () {
|
|
window.location.href = result.mdetail.path;
|
|
}, result.mdetail.redirect);
|
|
}
|
|
else if (result.mtype == "success") {
|
|
//reload grid
|
|
(city_location.get_vars()._city_location).ajax.reload(null, false);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
"_validate" : function(action){
|
|
var options = {
|
|
boot_box : {
|
|
"message" : (action == "add")
|
|
? app.get_vars().system_config.cma_msg.add_new_city
|
|
: app.get_vars().system_config.cma_msg.update_city
|
|
,
|
|
"_continue" : function() {
|
|
(action == "add")
|
|
? city_location._add.save($("form#cityForm"))
|
|
: city_location._edit.save($("form#cityForm"))
|
|
},
|
|
"id" : action+"_confirm_box",
|
|
"className" : action+"_confirm_box"
|
|
},
|
|
"validation" : {
|
|
"form_id" : "form#cityForm",
|
|
"rules" : {
|
|
"city": {
|
|
"minlength":3,
|
|
"required": true
|
|
}
|
|
}
|
|
}
|
|
};
|
|
app._form._validate(options);
|
|
},
|
|
|
|
"load" : function(){
|
|
var table = $('#city_location').DataTable({
|
|
"autoWidth": false,
|
|
"responsive": true,
|
|
"processing": true, //Feature control the processing indicator.
|
|
"serverSide": true, //Feature control DataTables' server-side processing mode.
|
|
"order": [0], //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+"city_location_list",
|
|
"type": "POST"
|
|
},
|
|
"columns": [
|
|
{ "data": "city_order"},
|
|
{ "data": "city"},
|
|
{ "data": "action" , render : function(data, type, full, meta){
|
|
var action_btns = "";
|
|
if (authorize(PAGE_CODE['sys_settings'], PRIVS[PAGE_CODE['sys_settings']]['city_mgt_edit'])) {
|
|
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._edit, "pencil", "success", "city_location._edit.modal("+data+", \'"+full.city+"\')");
|
|
}
|
|
if (authorize(PAGE_CODE['sys_settings'], PRIVS[PAGE_CODE['sys_settings']]['city_mgt_delete'])) {
|
|
action_btns +=app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", "city_location._delete.confirm("+data+", "+full.city_order+")");
|
|
}
|
|
return '<div class="row-fluid"><div class="span4 offset4 text-center">'+action_btns+'</div></div>';
|
|
|
|
}}
|
|
],
|
|
"fnDrawCallback": function() {
|
|
app._tooltip._hide();
|
|
$('#city_location 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": [2], "orderable": false},
|
|
{ "targets": [0], "orderable": false}
|
|
//{ "targets": [1], className : "truncate-content-text custom-popover-tooltip"}
|
|
],
|
|
"initComplete": function(settings, json) {
|
|
//run tooltip
|
|
app._tooltip._hide();
|
|
app._tooltip._pop();
|
|
|
|
//add custom button beside searchbox
|
|
$('.dataTables_filter').each(function () {
|
|
if (authorize(PAGE_CODE['sys_settings'], PRIVS[PAGE_CODE['sys_settings']]['city_mgt_add'])) {
|
|
$(this).append('<button onclick="city_location._add.modal();" ' +
|
|
'class="btn btn-primary btn-sm mr-xs subscribe" type="button" style="padding: 7px;">' +
|
|
'<span class="glyphicon glyphicon-plus"></span> '+app.get_vars().system_config.btn.add_new_city+'</button>');
|
|
}
|
|
});
|
|
|
|
//fire search filter event
|
|
app.grid.search_filter("city_location", city_location.get_vars()._city_location);
|
|
}
|
|
});
|
|
|
|
city_location.set_vars({_city_location : table});
|
|
}
|
|
};//end of return
|
|
// Pass in jQuery.
|
|
})(jQuery, this);
|
|
|
|
$(function() {
|
|
//load datatable
|
|
city_location.load();
|
|
});
|