From 9079093f5ace76555b15e613ca9b8e473aa8461d Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sat, 31 Aug 2019 15:31:32 +0530 Subject: updated the code for R TBC --- js/r_tbc_fixer.js | 330 ++++++++++++++++++++++++ js/r_tbc_fixer_edit_category.js | 156 ++++++++++++ js/textbook_companion_fixer.js | 363 --------------------------- js/textbook_companion_fixer_edit_category.js | 156 ------------ 4 files changed, 486 insertions(+), 519 deletions(-) create mode 100755 js/r_tbc_fixer.js create mode 100755 js/r_tbc_fixer_edit_category.js delete mode 100755 js/textbook_companion_fixer.js delete mode 100644 js/textbook_companion_fixer_edit_category.js (limited to 'js') diff --git a/js/r_tbc_fixer.js b/js/r_tbc_fixer.js new file mode 100755 index 0000000..dbb20d7 --- /dev/null +++ b/js/r_tbc_fixer.js @@ -0,0 +1,330 @@ +(function($) { + $(document).ready(function() { + var basePath = Drupal.settings.basePath; + var modPath = basePath + "r_tbc_fixer/"; + var modPath1 = basePath + "textbook_companion_fixer/aicte/book/"; + $category = $("#fix-tbc-form #edit-category"); + $book = $("#fix-tbc-form #edit-book"); + $chapter = $("#fix-tbc-form #edit-chapter"); + $example = $("#fix-tbc-form #edit-example"); + $caption = $("#fix-tbc-form #edit-caption"); + $code = $("#fix-tbc-form #edit-code"); + $caption_form = $("#scilab-fixer-caption-form"); + $code_form = $("#scilab-fixer-code-form"); + $updating = $("#fix-tbc-page #updating"); + $done = $("#fix-tbc-page #done"); + $example.attr("multiple", "enabled"); + + function reset() { + for (var i = 0, l = arguments.length; i < l; i++) { + switch (arguments[i]) { + case "book": + $book.html(""); + break; + case "chapter": + $chapter.html(""); + break; + case "example": + $example.html(""); + break; + case "caption": + $caption.val(""); + break; + } + } + } + $(".select-book").hide(); + $(".select-chapter").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + $book.change(function() { + reset("chapter", "example", "caption"); + var book_id = $(this).val(); + if (book_id < 1) { + $(".select-chapter").hide(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".select-chapter").show(); + $(".select-example").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } + $.ajax({ + url: modPath + "ajax/book/" + book_id, + type: "POST", + dataType: "html", + success: function(data) { + $chapter.html(data); + } + }); + }); + $chapter.change(function() { + reset("example", "caption"); + var chapter_name = $('option:selected', this).attr("data-chaptername"); + var chapter_id = $(this).val(); + if (chapter_id < 1) { + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".select-example").show(); + $(".enter-chapter-name").show(); + $(".chapter-example-chk").show(); + $("#edit-chapter-name").val(chapter_name); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".update-button").show(); + } + $.ajax({ + url: modPath + "ajax/chapter/" + chapter_id, + type: "POST", + dataType: "html", + success: function(data) { + $example.html(data); + } + }); + }); + $example.change(function() { + reset("caption"); + var example_id = $(this).val(); + var example_name = $('option:selected', this).attr("data-exampleid"); + var example_caption = $(this).text(); + if (example_id < 1) { + $(".enter-caption").hide(); + // $("#edit-caption").val(""); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".enter-caption").show(); + $("#edit-caption").val(example_name); + $(".example-code-edit").show(); + $(".well").show(); + $(".update-button").show(); + } + $.ajax({ + url: modPath + "ajax/example/" + example_id, + type: "POST", + dataType: "html", + success: function(data) { + var code = $(data).filter("#code").html(); + /* checking whether it is for .well or textarea */ + if ($code.hasClass("fix-caption-code")) { + $code.html(code); + } else { + $code.val(code); + } + var caption = $(data).filter("#caption").html(); + try { + $caption.val(caption); + } catch (e) { + return; + } + } + }); + }); + //edit caption form submit + $caption_form.submit(function(e) { + var example_id = $example.val(); + var chapter_id = $('option:selected', $chapter).attr("data-chapterid"); + if ($('.chapter-caption-chk').prop('checked') == true && $( + '.example-caption-chk').prop('checked') == true) { + if (example_id != "0" && chapter_id != "0") { + var caption = $caption.val(); + caption = caption.trim(); + caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(caption) == true) { + alert('Enter valid text for example caption'); + return false; + } + var chapter_caption = $("#edit-chapter-name").val(); + chapter_caption = chapter_caption.trim(); + chapter_caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(chapter_caption) == true) { + alert('Enter valid text for chapter caption'); + return false; + } + if (caption == '' || chapter_caption =='') { + alert('Please enter new caption '); + return false; + } + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-both/", + type: "POST", + data: { + example_id: example_id, + caption: caption, + chapter_id: chapter_id, + chapter_caption: chapter_caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $book.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No entry is selected.") + } + } else if ($('.example-caption-chk').prop('checked') == true) { + if (example_id != "0") { + var caption = $caption.val(); + caption = caption.trim(); + caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(caption) == true) { + alert('Enter valid text'); + return false; + } + if (caption == '') { + alert('Please enter new caption '); + return false; + } + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-example/", + type: "POST", + data: { + example_id: example_id, + caption: caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No example selected.") + } + } else if ($('.chapter-caption-chk').prop('checked') == true) { + if (chapter_id != "0") { + var chapter_caption = $("#edit-chapter-name").val(); + chapter_caption = chapter_caption.trim(); + chapter_caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(chapter_caption) == true) { + alert('Enter valid text for chapter caption'); + return false; + } + if (chapter_caption == '') { + alert('Please enter new caption '); + return false; + } + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-chapter/", + type: "POST", + data: { + chapter_id: chapter_id, + chapter_caption: chapter_caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $book.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No example selected.") + } + } else { + alert("Please select the checkbox option") + } + e.preventDefault(); + }); + $code_form.submit(function(e) { + var example_id = $example.val(); + if (example_id != "0") { + var code = $code.val(); + code = code.trim(); + if (code == '') { + alert('Please enter new code'); + return false; + } + $.ajax({ + url: modPath + "ajax/code/" + example_id, + type: "POST", + data: { + code: code + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + $(".example-code-edit").show(); + } + }); + } else { + alert("No example selected.") + } + e.preventDefault(); + }); + $Selected = $(".selected"); + $Selected.click(function(e) { + $(".sync-msg").remove(); + $(this).after("Saving..."); + $.ajax({ + url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), + success: function() { + $(".sync-msg").remove(); + console.log("success"); + } + }); + }); + function validateCaption(text){ + var re = /([a-zA-Z|*|_|.|+|-|\\|?|/|!|~|!|@|#|$|%|^|&|(|)|<|>|{|}|;|:|\"|\'|,])\1{2,}/; + return re.test(text); + } + /* toggle in edition */ + $ind_ed = $(".ind-ed"); + $ind_ed.click(function(e) { + var aicte_id = $(this).attr("data-aicte"); + $t = $(this); + $.ajax({ + url: modPath + "ajax/ind-ed/" + aicte_id, + type: "GET", + dataType: "html", + success: function(data) { + $tr = $t.parents("tr:first"); + if ($tr.hasClass("orange")) { + $t.parents("tr:first").removeClass("orange"); + $t.html("Mark"); + } else { + $t.parents("tr:first").addClass("orange"); + $t.html("Unmark"); + } + }, + }); + e.preventDefault(); + }); + }); +})(jQuery); diff --git a/js/r_tbc_fixer_edit_category.js b/js/r_tbc_fixer_edit_category.js new file mode 100755 index 0000000..bad5ec7 --- /dev/null +++ b/js/r_tbc_fixer_edit_category.js @@ -0,0 +1,156 @@ +(function($) { + $(document).ready(function() { + var basePath = Drupal.settings.basePath; + //var modPath = basePath + "textbook_companion_fixer/"; + var modPath = basePath + + "textbook_companion_fixer/ajax/edit-book-category/"; + $category_form = $("#fix-tbc-category-form"); + $(".main-subcategory-table-div").hide(); + + /*********************************************/ + //$('#main-subcategory-table-'+ 1).show(); + //var main_cat_chk_value = []; + $("input[name='ids[]']:checked").each(function() { + main_cat_chk_value = $(this).val(); + console.log('ooo' + main_cat_chk_value); + if (main_cat_chk_value) { + $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); + } else { + $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); + } + }); + + $('.main-category-checkbox').change(function() { + main_cat_chk_value = $(this).val(); + if (!this.checked) + $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); + else + $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); + }); + + $("#fix-tbc-category-form").on('click', '#btn-add', function() { + //$('#btn-add').click(function(){ + var selectID = $(this).attr("data-cid"); + console.log(selectID); + $('#subcats-' + selectID + ' option:selected').each(function() { + $('#selected-subcats-' + selectID).append(""); + + /**********************/ + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + var sub_cat_select_value = $(this).val(); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + sub_category: sub_cat_select_value, + action: "add" + }, + dataType: "html", + success: function(data) { + //alert("Updated"); + console.log("My data:" + data); + $updating.hide(); + $done.show(); + console.log("data1: " + main_cat_chk_value + " data2: " + + sub_cat_select_value + " data3: " + pref_id); + $done.fadeOut("slow"); + //alert("ok"); + } + }); + /**********************/ + + $(this).remove(); + }); + }); + $("#fix-tbc-category-form").on('click', '#btn-remove', function() { + //$('#btn-remove').click(function(){ + var selectID = $(this).attr("data-cid"); + $('#selected-subcats-' + selectID + ' option:selected').each(function() { + $('#subcats-' + selectID).append(""); + var action = "delete"; + /**********************/ + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + var sub_cat_select_value = $(this).val(); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + sub_category: sub_cat_select_value, + action: action + }, + dataType: "html", + success: function(data) { + //alert("Updated"); + console.log("My data:" + data); + $updating.hide(); + $done.show(); + console.log(action + "data1: " + main_cat_chk_value + + " data2: " + sub_cat_select_value + " data3: " + pref_id); + $done.fadeOut("slow"); + //alert("ok"); + } + }); + /**********************/ + $(this).remove(); + }); + }); + + //$("#main_cat_checkbox").change(function() { + $("#fix-tbc-category-form").on('change', '.main-category-checkbox', + function() { + var selectID = $(this).val(); + prop = $(this).prop('checked'); + if (prop) { + $('main-subcategory-table-' + selectID).show(); + } else { + if (confirm('Are you sure?')) { + alert('Thanks for confirming'); + var action = "delete-main-with-ub-category"; + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + console.log(action + "data1: " + main_cat_chk_value + " data2: " + + action + " data3: " + pref_id); + //ConfirmFunction(); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + action: action + }, + dataType: "html", + success: function(data) { + //alert("Updated"); + location.reload(); + $('main-subcategory-table-' + selectID).hide(); + console.log("My data:" + data); + $updating.hide(); + $done.show(); + console.log(action + "data1: " + main_cat_chk_value + " data2: " + + action + " data3: " + pref_id); + $done.fadeOut("slow"); + //alert("ok"); + } + }); + } else { + alert('You have not confirmed the action'); + location.reload(); + } + } + }); + /**********************************************************************/ + }); +})(jQuery); + +function ConfirmFunction() { + confirm("Are you sure?"); +} diff --git a/js/textbook_companion_fixer.js b/js/textbook_companion_fixer.js deleted file mode 100755 index b655b05..0000000 --- a/js/textbook_companion_fixer.js +++ /dev/null @@ -1,363 +0,0 @@ -(function($) { - $(document).ready(function() { - var basePath = Drupal.settings.basePath; - var modPath = basePath + "textbook_companion_fixer/"; - var modPath1 = basePath + "textbook_companion_fixer/aicte/book/"; - $category = $("#fix-tbc-form #edit-category"); - $book = $("#fix-tbc-form #edit-book"); - $chapter = $("#fix-tbc-form #edit-chapter"); - $example = $("#fix-tbc-form #edit-example"); - $caption = $("#fix-tbc-form #edit-caption"); - $code = $("#fix-tbc-form #edit-code"); - $caption_form = $("#scilab-fixer-caption-form"); - $code_form = $("#scilab-fixer-code-form"); - $updating = $("#fix-tbc-page #updating"); - $done = $("#fix-tbc-page #done"); - $example.attr("multiple", "enabled"); - - function reset() { - for (var i = 0, l = arguments.length; i < l; i++) { - switch (arguments[i]) { - case "book": - $book.html(""); - break; - case "chapter": - $chapter.html(""); - break; - case "example": - $example.html(""); - break; - case "caption": - $caption.val(""); - break; - } - } - } - $(".select-book").hide(); - $(".select-chapter").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - $category.change(function() { - reset("book", "chapter", "example", "caption"); - var category_id = $(this).val(); - if (category_id < 1) { - $(".select-book").hide(); - $(".select-chapter").hide(); - $(".enter-chapter-name").hide(); - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".chapter-example-chk").hide(); - $(".example-code-edit").hide(); - (".well").hide(); - $(".update-button").hide(); - } else { - $(".select-book").show(); - $(".select-chapter").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } - $.ajax({ - url: modPath + "ajax/category/" + category_id, - type: "POST", - dataType: "html", - success: function(data) { - $book.html(data); - } - }); - }); - $book.change(function() { - reset("chapter", "example", "caption"); - var book_id = $(this).val(); - if (book_id < 1) { - $(".select-chapter").hide(); - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } else { - $(".select-chapter").show(); - $(".select-example").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".enter-caption").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } - $.ajax({ - url: modPath + "ajax/book/" + book_id, - type: "POST", - dataType: "html", - success: function(data) { - $chapter.html(data); - } - }); - }); - $chapter.change(function() { - reset("example", "caption"); - var chapter_name = $('option:selected', this).attr("data-chaptername"); - var chapter_id = $(this).val(); - if (chapter_id < 1) { - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } else { - $(".select-example").show(); - $(".enter-chapter-name").show(); - $(".chapter-example-chk").show(); - $("#edit-chapter-name").val(chapter_name); - $(".enter-caption").hide(); - $(".example-code-edit").hide(); - $(".update-button").show(); - } - $.ajax({ - url: modPath + "ajax/chapter/" + chapter_id, - type: "POST", - dataType: "html", - success: function(data) { - $example.html(data); - } - }); - }); - $example.change(function() { - reset("caption"); - var example_id = $(this).val(); - var example_name = $('option:selected', this).attr("data-exampleid"); - var example_caption = $(this).text(); - if (example_id < 1) { - $(".enter-caption").hide(); - // $("#edit-caption").val(""); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } else { - $(".enter-caption").show(); - $("#edit-caption").val(example_name); - $(".example-code-edit").show(); - $(".well").show(); - $(".update-button").show(); - } - $.ajax({ - url: modPath + "ajax/example/" + example_id, - type: "POST", - dataType: "html", - success: function(data) { - var code = $(data).filter("#code").html(); - /* checking whether it is for .well or textarea */ - if ($code.hasClass("fix-caption-code")) { - $code.html(code); - } else { - $code.val(code); - } - var caption = $(data).filter("#caption").html(); - try { - $caption.val(caption); - } catch (e) { - return; - } - } - }); - }); - //edit caption form submit - $caption_form.submit(function(e) { - var example_id = $example.val(); - var chapter_id = $('option:selected', $chapter).attr("data-chapterid"); - if ($('.chapter-caption-chk').prop('checked') == true && $( - '.example-caption-chk').prop('checked') == true) { - if (example_id != "0" && chapter_id != "0") { - var caption = $caption.val(); - caption = caption.trim(); - caption = caption.replace(/\s\s+/g, ' '); - if(validateCaption(caption) == true) { - alert('Enter valid text for example caption'); - return false; - } - var chapter_caption = $("#edit-chapter-name").val(); - chapter_caption = chapter_caption.trim(); - chapter_caption = caption.replace(/\s\s+/g, ' '); - if(validateCaption(chapter_caption) == true) { - alert('Enter valid text for chapter caption'); - return false; - } - if (caption == '' || chapter_caption =='') { - alert('Please enter new caption '); - return false; - } - $updating.show(); - $.ajax({ - url: modPath + "ajax/update-both/", - type: "POST", - data: { - example_id: example_id, - caption: caption, - chapter_id: chapter_id, - chapter_caption: chapter_caption - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $book.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - } - }); - } else { - alert("No entry is selected.") - } - } else if ($('.example-caption-chk').prop('checked') == true) { - if (example_id != "0") { - var caption = $caption.val(); - caption = caption.trim(); - caption = caption.replace(/\s\s+/g, ' '); - if(validateCaption(caption) == true) { - alert('Enter valid text'); - return false; - } - if (caption == '') { - alert('Please enter new caption '); - return false; - } - $updating.show(); - $.ajax({ - url: modPath + "ajax/update-example/", - type: "POST", - data: { - example_id: example_id, - caption: caption - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - } - }); - } else { - alert("No example selected.") - } - } else if ($('.chapter-caption-chk').prop('checked') == true) { - if (chapter_id != "0") { - var chapter_caption = $("#edit-chapter-name").val(); - chapter_caption = chapter_caption.trim(); - chapter_caption = caption.replace(/\s\s+/g, ' '); - if(validateCaption(chapter_caption) == true) { - alert('Enter valid text for chapter caption'); - return false; - } - if (chapter_caption == '') { - alert('Please enter new caption '); - return false; - } - $updating.show(); - $.ajax({ - url: modPath + "ajax/update-chapter/", - type: "POST", - data: { - chapter_id: chapter_id, - chapter_caption: chapter_caption - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $book.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - } - }); - } else { - alert("No example selected.") - } - } else { - alert("Please select the checkbox option") - } - e.preventDefault(); - }); - $code_form.submit(function(e) { - var example_id = $example.val(); - if (example_id != "0") { - var code = $code.val(); - code = code.trim(); - if (code == '') { - alert('Please enter new code'); - return false; - } - $.ajax({ - url: modPath + "ajax/code/" + example_id, - type: "POST", - data: { - code: code - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - $(".example-code-edit").show(); - } - }); - } else { - alert("No example selected.") - } - e.preventDefault(); - }); - $Selected = $(".selected"); - $Selected.click(function(e) { - $(".sync-msg").remove(); - $(this).after("Saving..."); - $.ajax({ - url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), - success: function() { - $(".sync-msg").remove(); - console.log("success"); - } - }); - }); - function validateCaption(text){ - var re = /([a-zA-Z|*|_|.|+|-|\\|?|/|!|~|!|@|#|$|%|^|&|(|)|<|>|{|}|;|:|\"|\'|,])\1{2,}/; - return re.test(text); - } - /* toggle in edition */ - $ind_ed = $(".ind-ed"); - $ind_ed.click(function(e) { - var aicte_id = $(this).attr("data-aicte"); - $t = $(this); - $.ajax({ - url: modPath + "ajax/ind-ed/" + aicte_id, - type: "GET", - dataType: "html", - success: function(data) { - $tr = $t.parents("tr:first"); - if ($tr.hasClass("orange")) { - $t.parents("tr:first").removeClass("orange"); - $t.html("Mark"); - } else { - $t.parents("tr:first").addClass("orange"); - $t.html("Unmark"); - } - }, - }); - e.preventDefault(); - }); - }); -})(jQuery); diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js deleted file mode 100644 index bad5ec7..0000000 --- a/js/textbook_companion_fixer_edit_category.js +++ /dev/null @@ -1,156 +0,0 @@ -(function($) { - $(document).ready(function() { - var basePath = Drupal.settings.basePath; - //var modPath = basePath + "textbook_companion_fixer/"; - var modPath = basePath + - "textbook_companion_fixer/ajax/edit-book-category/"; - $category_form = $("#fix-tbc-category-form"); - $(".main-subcategory-table-div").hide(); - - /*********************************************/ - //$('#main-subcategory-table-'+ 1).show(); - //var main_cat_chk_value = []; - $("input[name='ids[]']:checked").each(function() { - main_cat_chk_value = $(this).val(); - console.log('ooo' + main_cat_chk_value); - if (main_cat_chk_value) { - $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); - } else { - $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); - } - }); - - $('.main-category-checkbox').change(function() { - main_cat_chk_value = $(this).val(); - if (!this.checked) - $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); - else - $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); - }); - - $("#fix-tbc-category-form").on('click', '#btn-add', function() { - //$('#btn-add').click(function(){ - var selectID = $(this).attr("data-cid"); - console.log(selectID); - $('#subcats-' + selectID + ' option:selected').each(function() { - $('#selected-subcats-' + selectID).append(""); - - /**********************/ - var pref_id = $('.prefrence_id').val(); - var main_cat_chk_value = selectID; - var sub_cat_select_value = $(this).val(); - $.ajax({ - url: modPath, - type: "POST", - data: { - pref_id: pref_id, - main_category: main_cat_chk_value, - sub_category: sub_cat_select_value, - action: "add" - }, - dataType: "html", - success: function(data) { - //alert("Updated"); - console.log("My data:" + data); - $updating.hide(); - $done.show(); - console.log("data1: " + main_cat_chk_value + " data2: " + - sub_cat_select_value + " data3: " + pref_id); - $done.fadeOut("slow"); - //alert("ok"); - } - }); - /**********************/ - - $(this).remove(); - }); - }); - $("#fix-tbc-category-form").on('click', '#btn-remove', function() { - //$('#btn-remove').click(function(){ - var selectID = $(this).attr("data-cid"); - $('#selected-subcats-' + selectID + ' option:selected').each(function() { - $('#subcats-' + selectID).append(""); - var action = "delete"; - /**********************/ - var pref_id = $('.prefrence_id').val(); - var main_cat_chk_value = selectID; - var sub_cat_select_value = $(this).val(); - $.ajax({ - url: modPath, - type: "POST", - data: { - pref_id: pref_id, - main_category: main_cat_chk_value, - sub_category: sub_cat_select_value, - action: action - }, - dataType: "html", - success: function(data) { - //alert("Updated"); - console.log("My data:" + data); - $updating.hide(); - $done.show(); - console.log(action + "data1: " + main_cat_chk_value + - " data2: " + sub_cat_select_value + " data3: " + pref_id); - $done.fadeOut("slow"); - //alert("ok"); - } - }); - /**********************/ - $(this).remove(); - }); - }); - - //$("#main_cat_checkbox").change(function() { - $("#fix-tbc-category-form").on('change', '.main-category-checkbox', - function() { - var selectID = $(this).val(); - prop = $(this).prop('checked'); - if (prop) { - $('main-subcategory-table-' + selectID).show(); - } else { - if (confirm('Are you sure?')) { - alert('Thanks for confirming'); - var action = "delete-main-with-ub-category"; - var pref_id = $('.prefrence_id').val(); - var main_cat_chk_value = selectID; - console.log(action + "data1: " + main_cat_chk_value + " data2: " + - action + " data3: " + pref_id); - //ConfirmFunction(); - $.ajax({ - url: modPath, - type: "POST", - data: { - pref_id: pref_id, - main_category: main_cat_chk_value, - action: action - }, - dataType: "html", - success: function(data) { - //alert("Updated"); - location.reload(); - $('main-subcategory-table-' + selectID).hide(); - console.log("My data:" + data); - $updating.hide(); - $done.show(); - console.log(action + "data1: " + main_cat_chk_value + " data2: " + - action + " data3: " + pref_id); - $done.fadeOut("slow"); - //alert("ok"); - } - }); - } else { - alert('You have not confirmed the action'); - location.reload(); - } - } - }); - /**********************************************************************/ - }); -})(jQuery); - -function ConfirmFunction() { - confirm("Are you sure?"); -} -- cgit