Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery.noConflict();
- jQuery(document).ready(function ($) {
- var admin_forum_categories = $('#admin_forum_categories');
- var modal_message_text = $('#modal-message-text');
- var message_modal = $('#message-modal');
- /*
- * http://jsfiddle.net/gyrocode/abhbs4x8/
- * Updates "Select all" control in a data table
- * */
- function updateDataTableSelectAllCtrl(table){
- var $table = table.table().node();
- var $chkbox_all = $('tbody input[type="checkbox"]', $table);
- var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
- var chkbox_select_all = $('thead input[name="select_all"]', $table).get(0);
- // If none of the checkboxes are checked
- if($chkbox_checked.length === 0){
- chkbox_select_all.checked = false;
- if('indeterminate' in chkbox_select_all){
- chkbox_select_all.indeterminate = false;
- }
- // If all of the checkboxes are checked
- } else if ($chkbox_checked.length === $chkbox_all.length){
- chkbox_select_all.checked = true;
- if('indeterminate' in chkbox_select_all){
- chkbox_select_all.indeterminate = false;
- }
- // If some of the checkboxes are checked
- } else {
- chkbox_select_all.checked = true;
- if('indeterminate' in chkbox_select_all){
- chkbox_select_all.indeterminate = true;
- }
- }
- }
- var selected = [];
- var rows_selected = [];
- var table = $(admin_forum_categories).DataTable({
- 'paging' : true,
- 'lengthChange': true,
- 'searching' : true,
- 'ordering' : true,
- 'responsive' : true,
- 'info' : true,
- 'autoWidth' : false,
- "processing": true,
- "serverSide": true,
- "pageLength": 10,
- 'language' :{
- "url" : "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Hungarian.json"
- },
- "ajax":{
- "url": base_url + "/admin/forum/kategoriak_ajax",
- "dataType": "json",
- "type": "POST"
- },
- "columnDefs":[
- {
- "className" : "text-center",
- "targets" : "_all"
- },
- {
- "targets":[0, 3],
- "orderable":false
- }
- ],
- "rowCallback": function( row, data ) {
- // Get row ID
- if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
- $(row).addClass('selected');
- }
- }
- });
- $(admin_forum_categories).find('tbody').on('click', 'tr', function () {
- var id = this.id;
- var index = $.inArray(id, selected);
- if ( index === -1 ) {
- selected.push( id );
- } else {
- selected.splice( index, 1 );
- }
- $(this).toggleClass('selected');
- });
- // Handle click on checkbox
- $(admin_forum_categories).find('tbody').on('click', 'input[type="checkbox"]', function(e){
- var $row = $(this).closest('tr');
- // Get row data
- var data = table.row($row).data();
- // Get row ID
- var rowId = data[0];
- // Determine whether row ID is in the list of selected row IDs
- var index = $.inArray(rowId, rows_selected);
- // If checkbox is checked and row ID is not in list of selected row IDs
- if(this.checked && index === -1){
- rows_selected.push(rowId);
- // Otherwise, if checkbox is not checked and row ID is in list of selected row IDs
- } else if (!this.checked && index !== -1){
- rows_selected.splice(index, 1);
- }
- if(this.checked){
- $row.addClass('selected');
- } else {
- $row.removeClass('selected');
- }
- // Update state of "Select all" control
- updateDataTableSelectAllCtrl(table);
- // Prevent click event from propagating to parent
- e.stopPropagation();
- });
- // Handle click on table cells with checkboxes
- $(admin_forum_categories).on('click', 'tbody td, thead th:first-child', function(e){
- $(this).parent().find('input[type="checkbox"]').trigger('click');
- });
- // Handle click on "Select all" control
- $('thead input[name="select_all"]', table.table().container()).on('click', function(e){
- if(this.checked){
- $(admin_forum_categories).find('tbody input[type="checkbox"]:not(:checked)').trigger('click');
- } else {
- $(admin_forum_categories).find('tbody input[type="checkbox"]:checked').trigger('click');
- }
- // Prevent click event from propagating to parent
- e.stopPropagation();
- });
- // Handle table draw event
- table.on('draw', function(){
- // Update state of "Select all" control
- updateDataTableSelectAllCtrl(table);
- });
- // ----------------------------- Kijelölt kategóriák törlése -----------------------------
- var delete_categories_multiple_modal = $('#delete_category_multiple_modal');
- var delete_selected_categories_button = $('#delete_selected_categories');
- $('#cat_delete_selected').on('click', function(e){
- var delete_this = $('#admin_forum_categories > tbody > tr >td:first-child > input').serialize();
- var delete_req_segments = delete_this.split("&");
- var delete_ids = [];
- for(i=0; i<delete_req_segments.length; i++){
- delete_ids[i] = delete_req_segments[i].split("=")[1];
- }
- delete_ids = delete_ids.sort(function(a, b){return a-b});
- var selected_items_count = delete_ids.length;
- $(delete_categories_multiple_modal).css('z-index',9999);
- $(delete_categories_multiple_modal).modal('show');
- $('#delete_multiple_num').text(selected_items_count);
- $(delete_selected_categories_button).on('click',function () {
- $.ajax({
- url: base_url+"/admin/forum/kategoriak/torles",
- cache: false,
- type: "POST",
- data: {
- delete_ids: delete_this
- },
- dataType: "json",
- success: function (data) {
- if(data['status-code'] === "danger"){
- //https://stackoverflow.com/questions/19528173/bootstrap-open-another-modal-in-modal/30250853#30250853
- $(delete_categories_multiple_modal).modal('hide').on('hidden.bs.modal', function (e) {
- $(modal_message_text).text(data['status-text']);
- $(modal_message_text).addClass('alert-'+data['status-code']);
- $(message_modal).css('z-index',9999);
- $(message_modal).modal('show');
- $(this).off('hidden.bs.modal'); // Remove the 'on' event binding
- });
- }
- else if(data['status-code'] === "success"){
- window.location.href = base_url+"/admin/forum/kategoriak";
- }
- }
- });
- });
- // Prevent actual form submission
- e.preventDefault();
- });
- // ----------------------------- // Kijelölt kategóriák törlése -----------------------------
- // Single category delete
- $(admin_forum_categories).on('click', 'tbody tr td button.delete_category_btn', function () {
- var category_id = $(this).data('category_id');
- var category_title = $(this).data('category_title');
- var delete_category_modal = $('#delete_category_modal');
- var delete_category_button = $('#delete_this_category');
- $(delete_category_modal).css('z-index', 9999);
- $(delete_category_modal).modal('show');
- $('#modal_cat_name').text(category_title);
- $(delete_category_button).on('click', function () {
- $.ajax({
- url: base_url + "/admin/forum/kategoriak/torles",
- cache: false,
- type: "POST",
- data: {
- category_id: category_id,
- category_title: category_title
- },
- dataType: "json",
- success: function (data) {
- console.log(data);
- if(data['status-code'] === "danger"){
- $(modal_message_text).text(data['status-text']);
- $(modal_message_text).addClass('alert-' + data['status-code']);
- $(message_modal).css('z-index', 9999);
- $(message_modal).modal('show');
- }
- else if(data['status-code'] === "success"){
- window.location.href = base_url+"/admin/forum/kategoriak";
- }
- }
- });
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement