Available sub categories | +Selected sub categories | +
---|---|
+ Add » + | +« Remove + + | +
From c8b0bd4ef8f3eb26d006fcd792ce628ac0b5f14b Mon Sep 17 00:00:00 2001
From: prashantsinalkar
Date: Mon, 8 May 2017 15:17:01 +0530
Subject: added new interface to edit the categories
---
js/textbook_companion_fixer_edit_category.js | 206 +++++++++++-------
textbook_companion_fixer.module | 127 +----------
textbook_companion_fixer_edit_book_category.inc | 272 +++++++++++++++++++++---
3 files changed, 377 insertions(+), 228 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("");
+
+ /**********************/
+ 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("");
+ 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?");
+}
diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module
index a844bda..d31eac8 100755
--- a/textbook_companion_fixer.module
+++ b/textbook_companion_fixer.module
@@ -67,7 +67,8 @@ function textbook_companion_fixer_menu()
$items["textbook_companion_fixer/ajax/edit-book-category"] = array(
"page callback" => "textbook_companion_fixer_edit_book_category_ajax",
"access callback" => TRUE,
- "type" => MENU_CALLBACK
+ "type" => MENU_CALLBACK,
+ "file" => "textbook_companion_fixer_edit_book_category.inc"
);
/* for admin */
$items['admin/settings/textbook_companion_fixer_settings'] = array(
@@ -764,131 +765,7 @@ function scilab_fixer_code_all()
$page_content .= "";
return $page_content;
}
-function _tbc_fixer_list_of_category($category_id = NULL)
-{
- $category[0] = "Please select";
- if ($category_id == NULL) {
- $query = db_select('list_of_category');
- $query->fields('list_of_category');
- $query->orderBy('id', 'ASC');
- $category_list = $query->execute();
- } //$category_id == NULL
- else {
- $query = db_select('list_of_category');
- $query->fields('list_of_category');
- $query->condition('category_id', $category_id);
- $query->orderBy('id', 'ASC');
- $category_list = $query->execute();
- }
- while ($category_list_data = $category_list->fetchObject()) {
- $category[$category_list_data->category_id] = $category_list_data->category_name;
- } //$category_list_data = $category_list->fetchObject()
- return $category;
-}
-function _textbook_companion_fixer_list_of_category($category_id = NULL)
-{
- if ($category_id == NULL )
- {
- $query = db_select('list_of_category');
- $query->fields('list_of_category');
- $query->orderBy('id', 'ASC');
- $category_list = $query->execute();
- } //$category_id == NULL
- else
- {
- $query = db_select('list_of_category');
- $query->fields('list_of_category');
- $query->condition('category_id', $category_id);
- $query->orderBy('id', 'ASC');
- $category_list = $query->execute();
- }
- while ($category_list_data = $category_list->fetchObject())
- {
- $category = $category_list_data->category_name;
- } //$category_list_data = $category_list->fetchObject()
- return $category;
-}
-
-function textbook_companion_fixer_edit_book_category_ajax($item,$key){
- $data = "";
- $item = arg(2);
-
- if ($item == "edit-book-category") {
- $data .= "Updated";
- foreach($_POST['main_category'] as $main_category && $_POST['sub_category'] as $sub_category) {
- $query = "
- INSERT INTO textbook_companion_book_main_subcategories
- (pref_id, main_category, sub_category)
- VALUES
- (:pref_id, :main_category, :subcategory)
- ";
- $args = array(
- ':pref_id' => $_POST['pref_id'],
- ':main_category' =>$main_category,
- ':subcategory' => $sub_category,
- );
- $result = db_query($query, $args);
- /* sending email */
- $email_to = $user->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc = variable_get('textbook_companion_fixer_bcc_emails', '');
- $cc = variable_get('textbook_companion_fixer_cc_emails', '');
- $params['category_updated']['pref_id'] = $pref_id;
- $params['category_updated']['user_id'] = $user->uid;
- $params['category_updated']['headers'] = array(
- 'From' => $from,
- 'MIME-Version' => '1.0',
- 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer' => 'Drupal',
- 'Cc' => $cc,
- 'Bcc' => $bcc
- );
- if (!drupal_mail('textbook_companion_fixer', 'category_updated', $email_to, language_default(), $params, $from, TRUE)) {
- $data .= 'Error sending email message.';
- } //!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE)
- }
-
- }
- $data .= $main_cat;
- echo $data;
- exit();
-}
-function _textbook_companion_fixer_list_of_category_checkboxes()
-{
- $query = db_select('list_of_category');
- $query->fields('list_of_category');
- //$query->fields(array('category_id','main_category'));
- $query->orderBy('category_id', 'ASC');
- $category_list = $query->execute();
-
-
- while ($category_list_data = $category_list->fetchObject())
- {
- $categoryname=$category_list_data->main_category;
- if($categoryname!=null||strlen($categoryname)!=0){
- //$category[$category_list_data->category_id] = $category_list_data->main_category;
- $category .= "".$category_list_data->main_category."
-