summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorprashantsinalkar2017-05-08 15:17:01 +0530
committerprashantsinalkar2017-05-08 15:17:01 +0530
commitc37080cb2d893cdbf62b46cc35805081164914a7 (patch)
treea5d99fdd2a7b2a7938cef3a29b136abda409cc28 /js
parent9bb4d56b6bd962b453692ceb83274eba8d516e6d (diff)
downloadtextbook_companion_fixer-c37080cb2d893cdbf62b46cc35805081164914a7.tar.gz
textbook_companion_fixer-c37080cb2d893cdbf62b46cc35805081164914a7.tar.bz2
textbook_companion_fixer-c37080cb2d893cdbf62b46cc35805081164914a7.zip
added new interface to edit the categories
Diffstat (limited to 'js')
-rw-r--r--js/textbook_companion_fixer_edit_category.js206
1 files changed, 128 insertions, 78 deletions
diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js
index f10973b..545f689 100644
--- a/js/textbook_companion_fixer_edit_category.js
+++ b/js/textbook_companion_fixer_edit_category.js
@@ -2,106 +2,156 @@
$(document).ready(function() {
var basePath = Drupal.settings.basePath;
//var modPath = basePath + "textbook_companion_fixer/";
- var modPath = basePath + "textbook_companion_fixer/ajax/edit-book-category/";
+ var modPath = basePath +
+ "textbook_companion_fixer/ajax/edit-book-category/";
$category_form = $("#fix-tbc-category-form");
- $(".main-subcategory-1").hide();
- $(".main-subcategory-2").hide();
- $(".main-subcategory-3").hide();
- $(".main-subcategory-4").hide();
- $(".main-subcategory-5").hide();
- $(".main-subcategory-6").hide();
- $(".main-subcategory-7").hide();
- prop = $('.main-category-chk-1').prop('checked');
- $('.main-category-chk-1').change(function() {
- if (!this.checked) {
- $('.main-subcategory-1').hide();
- $('.main-subcategory-1').prop('selectedIndex', 0);
- } else {
- $('.main-subcategory-1').show();
- }
- });
- $('.main-category-chk-2').change(function() {
- if (!this.checked) {
- $('.main-subcategory-2').hide();
- $('.main-subcategory-2').prop('selectedIndex', 0);
- } else {
- $('.main-subcategory-2').show();
- }
- });
- $('.main-category-chk-3').change(function() {
- if (!this.checked) {
- $('.main-subcategory-3').hide();
- $('.main-subcategory-3').prop('selectedIndex', 0);
- } else {
- $('.main-subcategory-3').show();
- }
- });
- $('.main-category-chk-4').change(function() {
- if (!this.checked) {
- $('.main-subcategory-4').hide();
- $('.main-subcategory-4').prop('selectedIndex', 0);
- } else {
- $('.main-subcategory-4').show();
- }
- });
- $('.main-category-chk-5').change(function() {
- if (!this.checked) {
- $('.main-subcategory-5').hide();
- $('.main-subcategory-5').prop('selectedIndex', 0);
- } else {
- $('.main-subcategory-5').show();
- }
- });
- $('.main-category-chk-6').change(function() {
- if (!this.checked) {
- $('.main-subcategory-6').hide();
- $('.main-subcategory-6').prop('selectedIndex', 0);
+ $(".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-6').show();
+ $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide();
}
});
- $('.main-category-chk-7').change(function() {
- if (!this.checked) {
- $('.main-subcategory-7').hide();
- $('.main-subcategory-7').prop('selectedIndex', 0);
- } else {
- $('.main-subcategory-7').show();
- }
+
+ $('.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();
});
- //edit category form submit
- $("#submit-button-category").click(function(e) {
- var main_cat_chk_value = [];
- $("input[name='ids[]']:checked").each(function (){
- main_cat_chk_value.push(parseInt($(this).val()));
- });
- var sub_cat_select_value = $.map($('select[name="subcats"] :selected'), function (val, _) {
- var newObj = {};
- if(val.value > '0'){
- newObj.subcats = val.value;
- }
- return newObj;
+
+ $("#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("<option value='" + $(this)
+ .val() + "'>" + $(this).text() + "</option>");
+
+ /**********************/
+ console.log($('.main-subcategory-' + selectID).attr('data-cid'));
+ 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();
});
- var pref_id = $('.prefrence_id').val();
- console.log(pref_id);
+ });
+ $("#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("<option value='" + $(this).val() +
+ "'>" + $(this).text() + "</option>");
+ 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
+ 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("data1: " + main_cat_chk_value + " data2: "+ sub_cat_select_value);
+ console.log(action + "data1: " + main_cat_chk_value +
+ " data2: " + sub_cat_select_value + " data3: " + pref_id);
$done.fadeOut("slow");
//alert("ok");
}
});
- e.preventDefault();
+ /**********************/
+ $(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?");
+}