211 lines
6.9 KiB
JavaScript
211 lines
6.9 KiB
JavaScript
var custom_files_lists;
|
|
var custom_files_view;
|
|
var myDropzoneCustomFiles;
|
|
|
|
/*Custom Files Dropzone*/
|
|
myDropzoneCustomFiles = $("div#DropZoneAreaCustomFiles").dropzone({
|
|
url: $(this).attr('action'),
|
|
complete: function (file) {
|
|
//console.log(file);
|
|
}, init: function () {
|
|
this.on("success", function (file, responseText) {
|
|
var makeHiddenTextBox = '<input type="hidden" name="upload_custom_files[]" value="' + responseText.filename + '" />';
|
|
$('#custom_files_form').append(makeHiddenTextBox);
|
|
});
|
|
},
|
|
sending: function (file, xhr, formData) {
|
|
formData.append("type", 5);
|
|
return formData.append("_token", jQuery('[name="_token"]').val());
|
|
},
|
|
|
|
});
|
|
|
|
|
|
var $custom_files_farm = jQuery('#custom_files_form');
|
|
jQuery(document).ready(function () {
|
|
custom_files_listing();
|
|
/*Custom Files Add/Edit*/
|
|
validateForm($custom_files_farm);
|
|
jQuery('#assign_custom_files_btn').click(function () {
|
|
|
|
if ($custom_files_farm.validate().form()) {
|
|
ajaxRequest('/user/farm/custom_files/save', 'post', 'json', $custom_files_farm.serialize(), function (html) {
|
|
showMsg("success", html.message);
|
|
$('#custom_files-modal').modal('toggle');
|
|
custom_files_listing();
|
|
$("#custom_file_farm_section_id").val('').change();
|
|
$("#custom_file_name").val('');
|
|
});
|
|
}
|
|
});
|
|
/*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 + "/user/farm/custom_files/delete",
|
|
data: {
|
|
id: id,
|
|
_token: jQuery('[name="_token"]').val()
|
|
},
|
|
method: 'post',
|
|
dataType: 'json',
|
|
success: function () {
|
|
custom_files_listing();
|
|
$("#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 Listing*/
|
|
function custom_files_listing() {
|
|
|
|
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 + "/user/farm/custom_files/lists",
|
|
fnDrawCallback: function (oSettings) {
|
|
$("#custom_files_table_listing tbody").sortable({
|
|
// helper: fixHelperModified,
|
|
stop: updateIndexCustomFiles
|
|
//connectWith: "table"
|
|
}).disableSelection();
|
|
}
|
|
});
|
|
}
|
|
|
|
/*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 + "/user/farm/custom_files/view/" + id,
|
|
fnDrawCallback: function (oSettings) {
|
|
|
|
}
|
|
});
|
|
$("#media-library-custom-files").modal();
|
|
}
|
|
|
|
|
|
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('user/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 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 + "/user/farm/custom_files/order",
|
|
data: {'data_id': all_id, _token: jQuery('[name="_token"]').val()}
|
|
}).done(function (data) {
|
|
alert("Order set successfully.");
|
|
});
|
|
} |