Removed uneccesary code from wiaas admin panels.js

This commit is contained in:
Nedim Uka
2018-09-26 13:55:31 +02:00
parent 6afffc7eca
commit 21d96a0e55

View File

@@ -1,76 +1,23 @@
jQuery(function ($) { jQuery(function ($) {
var $edit_in_cart = $('.bundle_edit_in_cart'), var $template_categories_container_hardware = $('.wiaas-template-items_hardware'),
$group_mode_select = $('select#_wc_pb_group_mode'), $template_categories_container_software = $('.wiaas-template-items_software'),
$bundled_products_panel = $('#bundled_product_data'), $template_categories_container_services = $('.wiaas-template-items_services'),
$bundled_products_toolbar = $bundled_products_panel.find('.toolbar'), $template_categories_container_isntallation = $('.wiaas-template-items_installation'),
$template_products_container_hardware = $('.wiaas-template-items_hardware'),
$template_products_container_software = $('.wiaas-template-items_software'),
$template_products_container_services = $('.wiaas-template-items_services'),
$template_products_container_isntallation = $('.wiaas-template-items_installation'),
$template_products = $('.wc-bundled-item', $template_categories = $('.wc-bundled-item',
$template_products_container_services, $template_categories_container_services,
$template_products_container_software, $template_categories_container_software,
$template_products_container_hardware, $template_categories_container_hardware,
$template_products_container_isntallation), $template_categories_container_isntallation),
$template_search_hardware = $('#wiaastemplate_products_hardware'), $template_search_hardware = $('#wiaastemplate_products_hardware'),
$template_search_software = $('#wiaastemplate_products_software'), $template_search_software = $('#wiaastemplate_products_software'),
$template_search_services = $('#wiaastemplate_products_services'), $template_search_services = $('#wiaastemplate_products_services'),
$template_search_installation = $('#wiaastemplate_products_installation'), $template_search_installation = $('#wiaastemplate_products_installation'),
bundled_product_objects = {}, template_category_objects = {},
bundled_products_add_count = $template_products.length, template_category_add_count = $template_categories.length;
block_params = {
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
};
$.fn.wc_bundles_select2 = function () {
$(document.body).trigger('wc-enhanced-select-init');
};
// Bundle type move stock msg up.
$('.bundle_stock_msg').appendTo('._manage_stock_field .description');
// Simple type options are valid for bundles.
$('.show_if_simple:not(.hide_if_bundle)').addClass('show_if_bundle');
$('body').on('woocommerce-product-type-change', function (event, select_val) {
if ('bundle' === select_val) {
$('.show_if_external').hide();
$('.show_if_bundle').show();
$('input#_manage_stock').change();
$('#_nyp').change();
}
});
$group_mode_select.change(function () {
if ($.inArray($group_mode_select.val(), wc_bundles_admin_params.group_modes_with_parent) === -1) {
$edit_in_cart.hide();
} else {
$edit_in_cart.show();
}
});
// Downloadable support.
$('input#_downloadable').change(function () {
$('select#product-type').change();
});
// Trigger product type change.
$('select#product-type').change();
// Trigger group mode change.
$group_mode_select.change();
init_event_handlers(); init_event_handlers();
@@ -81,52 +28,50 @@ jQuery(function ($) {
$template_search_hardware $template_search_hardware
.on('change', function () { .on('change', function () {
addSearchedProduct('hardware', $template_search_hardware, $template_products_container_hardware) addSearchedTemplateCategory('hardware', $template_search_hardware, $template_categories_container_hardware)
}); });
$template_search_software $template_search_software
.on('change', function () { .on('change', function () {
addSearchedProduct('software', $template_search_software, $template_products_container_software) addSearchedTemplateCategory('software', $template_search_software, $template_categories_container_software)
}); });
$template_search_installation $template_search_installation
.on('change', function () { .on('change', function () {
addSearchedProduct('services', $template_search_installation, $template_products_container_isntallation) addSearchedTemplateCategory('services', $template_search_installation, $template_categories_container_isntallation)
}); });
$template_search_services $template_search_services
.on('change', function () { .on('change', function () {
addSearchedProduct('installation', $template_search_services, $template_products_container_services) addSearchedTemplateCategory('installation', $template_search_services, $template_categories_container_services)
}); });
function addSearchedProduct(options, search, container) { function addSearchedTemplateCategory(options, search, container) {
var bundled_product_ids = search.val(), var template_category_ids = search.val(),
bundled_product_id = bundled_product_ids && bundled_product_ids.length > 0 ? bundled_product_ids.shift() : false; template_category_id = template_category_ids && template_category_ids.length > 0 ? template_category_ids.shift() : false;
var template_category_title =search.text(); var template_category_title =search.text();
if (!bundled_product_id) { if (!template_category_id) {
return false; return false;
} }
search.val([]).change(); search.val([]).change();
$bundled_products_panel.block(block_params); template_category_add_count++;
bundled_products_add_count++;
var data = { var data = {
action: 'wiaas_add_template_product', action: 'wiaas_add_template_product',
post_id: woocommerce_admin_meta_boxes.post_id, post_id: woocommerce_admin_meta_boxes.post_id,
id: bundled_products_add_count, id: template_category_add_count,
title: template_category_title, title: template_category_title,
product_id: bundled_product_id, product_id: template_category_id,
security: wc_bundles_admin_params.add_bundled_product_nonce, security: wc_bundles_admin_params.add_bundled_product_nonce,
options: options, options: options,
}; };
@@ -140,13 +85,11 @@ jQuery(function ($) {
container.append(response.markup); container.append(response.markup);
var $added = $('.wiaas-template-item', container).last(), var $added = $('.wiaas-template-item', container).last(),
added_id = 'bundled_item_' + bundled_products_add_count; added_id = 'bundled_item_' + template_category_add_count;
$added.data('bundled_item_id', added_id); $added.data('bundled_item_id', added_id);
$added.wc_bundles_select2(); $added.wc_bundles_select2();
$bundled_products_panel.trigger('wc-bundles-added-bundled-product');
} else if (response.message !== '') { } else if (response.message !== '') {
window.alert(response.message); window.alert(response.message);
} }
@@ -161,8 +104,6 @@ jQuery(function ($) {
} }
search.text(''); search.text('');
$bundled_products_panel.unblock();
}); });
}, 250); }, 250);
@@ -170,7 +111,7 @@ jQuery(function ($) {
return false; return false;
} }
$template_products_container_isntallation $template_categories_container_isntallation
// Remove Item. // Remove Item.
.on('click', 'a.remove_row', function (e) { .on('click', 'a.remove_row', function (e) {
@@ -181,15 +122,13 @@ jQuery(function ($) {
$el.find('*').off(); $el.find('*').off();
$el.remove(); $el.remove();
delete bundled_product_objects[el_id]; delete template_category_objects[el_id];
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
e.preventDefault(); e.preventDefault();
}); });
$template_products_container_hardware $template_categories_container_hardware
// Remove Item. // Remove Item.
.on('click', 'a.remove_row', function (e) { .on('click', 'a.remove_row', function (e) {
@@ -200,15 +139,13 @@ jQuery(function ($) {
$el.find('*').off(); $el.find('*').off();
$el.remove(); $el.remove();
delete bundled_product_objects[el_id]; delete template_category_objects[el_id];
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
e.preventDefault(); e.preventDefault();
}); });
$template_products_container_software $template_categories_container_software
// Remove Item. // Remove Item.
.on('click', 'a.remove_row', function (e) { .on('click', 'a.remove_row', function (e) {
@@ -219,15 +156,13 @@ jQuery(function ($) {
$el.find('*').off(); $el.find('*').off();
$el.remove(); $el.remove();
delete bundled_product_objects[el_id]; delete template_category_objects[el_id];
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
e.preventDefault(); e.preventDefault();
}); });
$template_products_container_services $template_categories_container_services
// Remove Item. // Remove Item.
.on('click', 'a.remove_row', function (e) { .on('click', 'a.remove_row', function (e) {
@@ -238,9 +173,7 @@ jQuery(function ($) {
$el.find('*').off(); $el.find('*').off();
$el.remove(); $el.remove();
delete bundled_product_objects[el_id]; delete template_category_objects[el_id];
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
e.preventDefault(); e.preventDefault();