406 lines
14 KiB
JavaScript
406 lines
14 KiB
JavaScript
var share_lists;
|
|
var report_lists;
|
|
var custom_files_lists;
|
|
var $report_farm = jQuery('#report_form');
|
|
var $custom_files_farm = jQuery('#custom_files_form');
|
|
var custom_files_view;
|
|
jQuery(document).ready(function () {
|
|
|
|
share_map_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
$("#report_id").val('');
|
|
report_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
custom_files_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
|
|
var $share_farm = jQuery('#share_form');
|
|
validateForm($share_farm);
|
|
|
|
jQuery('#assign_share_btn').click(function () {
|
|
|
|
if ($share_farm.validate().form()) {
|
|
ajaxRequest('/superadmin/farm/share/save/' + jQuery('[name="farm_id"]').val(), 'post', 'json', $share_farm.serialize(), function (html) {
|
|
showMsg("success", "Share successfully.");
|
|
$('#projects-task-modal').modal('toggle');
|
|
share_map_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
/*Custom Files Add/Edit*/
|
|
validateForm($custom_files_farm);
|
|
jQuery('#assign_custom_files_btn').click(function () {
|
|
|
|
if ($custom_files_farm.validate().form()) {
|
|
ajaxRequest('/superadmin/farm/custom_files/save', 'post', 'json', $custom_files_farm.serialize(), function (html) {
|
|
showMsg("success", html.message);
|
|
$('#custom_files-modal').modal('toggle');
|
|
custom_files_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
$("#custom_file_farm_section_id").val('').change();
|
|
$("#custom_file_name").val('');
|
|
});
|
|
}
|
|
});
|
|
|
|
/*Report*/
|
|
validateForm($report_farm);
|
|
jQuery('#assign_report_btn').click(function () {
|
|
|
|
if ($report_farm.validate().form()) {
|
|
ajaxRequest('/superadmin/farm/report/save/' + jQuery('[name="farm_id"]').val(), 'post', 'json', $report_farm.serialize(), function (html) {
|
|
showMsg("success", html.status);
|
|
$('#report-modal').modal('toggle');
|
|
report_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
$("#report_id").val('');
|
|
$("#farm_section_id").val('').change();
|
|
$("#db_report_url").val('');
|
|
$("#report_name").val('');
|
|
});
|
|
}
|
|
});
|
|
|
|
$('#share_table_listing').on('click', 'a.delete-row', function (e) {
|
|
e.preventDefault();
|
|
var id = jQuery(this).attr("data-id");
|
|
|
|
swal({
|
|
title: "Are you sure?",
|
|
text: "You will not be able to recover this data.",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "Yes, delete it!",
|
|
cancelButtonText: "No, cancel plx!",
|
|
closeOnConfirm: true,
|
|
closeOnCancel: true
|
|
},
|
|
function (isConfirm) {
|
|
if (isConfirm) {
|
|
$.ajax({
|
|
url: baseURL + "/superadmin/farm/share/delete",
|
|
data: {
|
|
id: id,
|
|
_token: jQuery('[name="_token"]').val()
|
|
},
|
|
method: 'post',
|
|
dataType: 'json',
|
|
success: function () {
|
|
share_map_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
showMsg("deleted", "Farm sharing deleted successfully.");
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
});
|
|
});
|
|
|
|
/*Report Delete*/
|
|
$('#report_table_listing').on('click', 'a.delete-row', function (e) {
|
|
e.preventDefault();
|
|
var id = jQuery(this).attr("data-id");
|
|
|
|
swal({
|
|
title: "Are you sure?",
|
|
text: "You will not be able to recover this data.",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "Yes, delete it!",
|
|
cancelButtonText: "No, cancel plx!",
|
|
closeOnConfirm: true,
|
|
closeOnCancel: true
|
|
},
|
|
function (isConfirm) {
|
|
if (isConfirm) {
|
|
$.ajax({
|
|
url: baseURL + "/superadmin/farm/report/delete",
|
|
data: {
|
|
id: id,
|
|
_token: jQuery('[name="_token"]').val()
|
|
},
|
|
method: 'post',
|
|
dataType: 'json',
|
|
success: function () {
|
|
report_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
$("#report_id").val('');
|
|
$("#farm_section_id").val('').change();
|
|
$("#db_report_url").val('');
|
|
$("#report_name").val('');
|
|
showMsg("deleted", "Report deleted successfully.");
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
});
|
|
});
|
|
|
|
/*Custom Files Delete*/
|
|
$('#custom_files_table_listing').on('click', 'a.delete-row', function (e) {
|
|
e.preventDefault();
|
|
var id = jQuery(this).attr("data-id");
|
|
|
|
swal({
|
|
title: "Are you sure?",
|
|
text: "You will not be able to recover this data.",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "Yes, delete it!",
|
|
cancelButtonText: "No, cancel plx!",
|
|
closeOnConfirm: true,
|
|
closeOnCancel: true
|
|
},
|
|
function (isConfirm) {
|
|
if (isConfirm) {
|
|
$.ajax({
|
|
url: baseURL + "/superadmin/farm/custom_files/delete",
|
|
data: {
|
|
id: id,
|
|
_token: jQuery('[name="_token"]').val()
|
|
},
|
|
method: 'post',
|
|
dataType: 'json',
|
|
success: function () {
|
|
custom_files_listing(jQuery('[name="farmer_id"]').val(), jQuery('[name="farm_id"]').val());
|
|
$("#custom_file_farm_section_id").val('').change();
|
|
$("#custom_file_name").val('');
|
|
showMsg("deleted", "Custom Files deleted successfully.");
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
});
|
|
});
|
|
/* custom file view */
|
|
$('#custom_files_table_listing').on('click', 'a.view-row', function (e) {
|
|
e.preventDefault();
|
|
var id = jQuery(this).attr("data-id");
|
|
custom_file_view(id);
|
|
});
|
|
});
|
|
|
|
/*Custom Files view*/
|
|
function custom_file_view(id) {
|
|
|
|
if (typeof (custom_files_view) != "undefined") {
|
|
custom_files_view.destroy();
|
|
}
|
|
|
|
custom_files_view = $('#media_library_custom_files_table').DataTable({
|
|
// "pagingType": "bootstrap_extended",
|
|
"lengthMenu": [
|
|
[10, 20, 50, -1],
|
|
[10, 20, 50, "All"] // change per page values here
|
|
],
|
|
"aoColumns": [
|
|
{data: 'filename', name: 'filename'},
|
|
{data: 'org_name', name: 'org_name'},
|
|
{data: 'action', name: 'action', orderable: false, searchable: false}
|
|
],
|
|
// set the initial value
|
|
"pageLength": 10,
|
|
"order": [
|
|
[1, 1, "asc"]
|
|
],
|
|
processing: true,
|
|
serverSide: true,
|
|
ajax: baseURL + "/superadmin/farm/custom_files/view/" + id,
|
|
fnDrawCallback: function (oSettings) {
|
|
|
|
}
|
|
});
|
|
$("#media-library-custom-files").modal();
|
|
}
|
|
|
|
function share_map_listing(farmer_id, farm_id) {
|
|
|
|
if (typeof (share_lists) != "undefined") {
|
|
share_lists.destroy();
|
|
}
|
|
|
|
share_lists = $('#share_table_listing').DataTable({
|
|
// "pagingType": "bootstrap_extended",
|
|
"lengthMenu": [
|
|
[10, 20, 50, -1],
|
|
[10, 20, 50, "All"] // change per page values here
|
|
],
|
|
"aoColumns": [
|
|
{data: 'first_name', name: 'first_name'},
|
|
{data: 'name', name: 'name'},
|
|
{data: 'action', name: 'action', orderable: false, searchable: false}
|
|
],
|
|
// set the initial value
|
|
"pageLength": 10,
|
|
"order": [
|
|
[1, 1, "asc"]
|
|
],
|
|
processing: true,
|
|
serverSide: true,
|
|
ajax: baseURL + "/superadmin/farm/share/lists/" + farmer_id + "/" + farm_id,
|
|
fnDrawCallback: function (oSettings) {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
/*Report Listing*/
|
|
function report_listing(farmer_id, farm_id) {
|
|
|
|
if (typeof (report_lists) != "undefined") {
|
|
report_lists.destroy();
|
|
}
|
|
|
|
report_lists = $('#report_table_listing').DataTable({
|
|
// "pagingType": "bootstrap_extended",
|
|
"lengthMenu": [
|
|
[10, 20, 50, -1],
|
|
[10, 20, 50, "All"] // change per page values here
|
|
],
|
|
"aoColumns": [
|
|
{data: 'name', name: 'name'},
|
|
{data: 'section_name', name: 'section_name'},
|
|
{data: 'action', name: 'action', orderable: false, searchable: false}
|
|
],
|
|
// set the initial value
|
|
"pageLength": 10,
|
|
"order": [
|
|
[1, 1, "asc"]
|
|
],
|
|
processing: true,
|
|
serverSide: true,
|
|
ajax: baseURL + "/superadmin/farm/report/lists/" + farmer_id + "/" + farm_id,
|
|
fnDrawCallback: function (oSettings) {
|
|
$("#report_table_listing tbody").sortable({
|
|
// helper: fixHelperModified,
|
|
stop: updateIndexReport
|
|
//connectWith: "table"
|
|
}).disableSelection();
|
|
}
|
|
});
|
|
}
|
|
|
|
/*Custom Files Listing*/
|
|
function custom_files_listing(farmer_id, farm_id) {
|
|
|
|
if (typeof (custom_files_lists) != "undefined") {
|
|
custom_files_lists.destroy();
|
|
}
|
|
|
|
custom_files_lists = $('#custom_files_table_listing').DataTable({
|
|
// "pagingType": "bootstrap_extended",
|
|
"lengthMenu": [
|
|
[10, 20, 50, -1],
|
|
[10, 20, 50, "All"] // change per page values here
|
|
],
|
|
"aoColumns": [
|
|
{data: 'name', name: 'name'},
|
|
{data: 'section_name', name: 'section_name'},
|
|
{data: 'action', name: 'action', orderable: false, searchable: false}
|
|
],
|
|
// set the initial value
|
|
"pageLength": 10,
|
|
"order": [
|
|
[1, 1, "asc"]
|
|
],
|
|
processing: true,
|
|
serverSide: true,
|
|
ajax: baseURL + "/superadmin/farm/custom_files/lists/" + farmer_id + "/" + farm_id,
|
|
fnDrawCallback: function (oSettings) {
|
|
$("#custom_files_table_listing tbody").sortable({
|
|
// helper: fixHelperModified,
|
|
stop: updateIndexCustomFiles
|
|
//connectWith: "table"
|
|
}).disableSelection();
|
|
}
|
|
});
|
|
}
|
|
|
|
/*Report Edit*/
|
|
$('#report_table_listing').on('click', 'a.edit-row', function (e) {
|
|
e.preventDefault();
|
|
var id = jQuery(this).attr("data-id");
|
|
$("#report_id").val(id);
|
|
ajaxRequest('superadmin/farm/report/edit/' + id, 'get', 'json', {}, function (html) {
|
|
$("#farm_section_id").val(html.data.farm_section_id).change();
|
|
$("#db_report_url").val(html.data.url);
|
|
$("#report_name").val(html.data.name);
|
|
$('#report-modal').modal('toggle');
|
|
});
|
|
});
|
|
|
|
|
|
jQuery('#add_custom_files').click(function () {
|
|
Dropzone.forElement("#DropZoneAreaCustomFiles").removeAllFiles(true);
|
|
jQuery('[name="upload_custom_files[]"]').remove();
|
|
$("#custom_file_farm_section_id").val('').change();
|
|
$("#custom_file_name").val('');
|
|
})
|
|
|
|
/*Custom Files Edit*/
|
|
$('#custom_files_table_listing').on('click', 'a.edit-row', function (e) {
|
|
e.preventDefault();
|
|
var id = jQuery(this).attr("data-id");
|
|
$("#custom_files_id").val(id);
|
|
|
|
Dropzone.forElement("#DropZoneAreaCustomFiles").removeAllFiles(true);
|
|
jQuery('[name="upload_custom_files[]"]').remove();
|
|
|
|
ajaxRequest('superadmin/farm/custom_files/edit/' + id, 'get', 'json', {}, function (html) {
|
|
$("#custom_file_farm_section_id").val(html.data.farm_section_id).change();
|
|
$("#custom_file_name").val(html.data.name);
|
|
$('#custom_files-modal').modal('toggle');
|
|
});
|
|
});
|
|
|
|
function validateForm(formEle) {
|
|
|
|
formEle.validate({
|
|
errorElement: 'span', //default input error message container
|
|
errorClass: 'help-inline', // default input error message class
|
|
focusInvalid: false, // do not focus the last invalid input
|
|
rules: {
|
|
},
|
|
messages: {
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateIndexReport() {
|
|
var all_id = new Array();
|
|
var i = 0;
|
|
$('#report_table_listing tbody').find('tr').each(function (i) {
|
|
var id = $(this).find('.report-id').val();
|
|
all_id[i] = id;
|
|
i++;
|
|
|
|
});
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: baseURL + "/superadmin/farm/report/order",
|
|
data: {'data_id': all_id, _token: jQuery('[name="_token"]').val()}
|
|
}).done(function (data) {
|
|
alert("Order set successfully.");
|
|
});
|
|
}
|
|
|
|
function updateIndexCustomFiles() {
|
|
var all_id = new Array();
|
|
var i = 0;
|
|
$('#custom_files_table_listing tbody').find('tr').each(function (i) {
|
|
var id = $(this).find('.custom-files-id').val();
|
|
all_id[i] = id;
|
|
i++;
|
|
|
|
});
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: baseURL + "/superadmin/farm/custom_files/order",
|
|
data: {'data_id': all_id, _token: jQuery('[name="_token"]').val()}
|
|
}).done(function (data) {
|
|
alert("Order set successfully.");
|
|
});
|
|
} |