added new add products order items action

This commit is contained in:
claudiosmweb 2014-07-16 15:11:48 -03:00
parent 3ca145ac85
commit 04e8fbcb5e
7 changed files with 171 additions and 104 deletions

View File

@ -1,15 +1,15 @@
jQuery( function($){
jQuery( function ( $ ) {
// ORDERS
jQuery('#woocommerce-order-actions input, #woocommerce-order-actions a').click(function(){
$( '#woocommerce-order-actions input, #woocommerce-order-actions a' ).click( function () {
window.onbeforeunload = '';
});
$('a.edit_address').click(function(event){
$(this).hide();
$(this).closest('.order_data_column').find('div.address').hide();
$(this).closest('.order_data_column').find('div.edit_address').show();
event.preventDefault();
$( 'a.edit_address' ).click( function ( e ) {
e.preventDefault();
$( this ).hide();
$( this ).closest( '.order_data_column' ).find( 'div.address' ).hide();
$( this ).closest( '.order_data_column' ).find( 'div.edit_address' ).show();
});
// When the page is loaded, store the unit costs
@ -160,7 +160,7 @@ jQuery( function($){
$items.each(function() {
var $row = $(this);
var refund_qty = $row.find( '.wc-order-item-refund-quantity input' ).val();
if ( refund_qty ) {
refund_amount = parseFloat( refund_amount ) + ( refund_qty * ( parseFloat( $row.attr( 'data-unit_total' ) ) + parseFloat( $row.attr( 'data-unit_total_tax' ) ) ) );
}
@ -169,10 +169,10 @@ jQuery( function($){
$('#refund_amount').val( refund_amount ).change();
})
// Add some meta to a line item
.on('click', 'button.add_order_item_meta', function(){
.on( 'click', 'button.add_order_item_meta', function () {
var $button = $(this);
var $item = $button.closest('tr.item');
var $button = $( this );
var $item = $button.closest( 'tr.item' );
var data = {
order_item_id: $item.attr( 'data-order_item_id' ),
@ -219,7 +219,7 @@ jQuery( function($){
} );
}
return false;
});
});
$('#woocommerce-order-items')
.on( 'click', 'button.add_line_item', function() {
@ -241,46 +241,10 @@ jQuery( function($){
$('.wc-order-edit-line-item').show();
return false;
})
.on( 'click', 'button.add_order_item', function() {
var add_item_ids = $('select#add_item_id').val();
if ( add_item_ids ) {
count = add_item_ids.length;
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
$.each( add_item_ids, function( index, value ) {
var data = {
action: 'woocommerce_add_order_item',
item_to_add: value,
order_id: woocommerce_admin_meta_boxes.post_id,
security: woocommerce_admin_meta_boxes.order_item_nonce
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
$('table.woocommerce_order_items tbody#order_items_list').append( response );
if (!--count) {
$('select#add_item_id, #add_item_id_chosen .chosen-choices').css('border-color', '').val('');
runTipTip();
$('select#add_item_id').trigger("chosen:updated");
$('table.woocommerce_order_items').unblock();
}
$('#order_items_list tr.new_row').trigger('init_row').removeClass('new_row');
});
});
} else {
$('select#add_item_id, #add_item_id_chosen .chosen-choices').css('border-color', 'red');
.on( 'click', 'button.add_order_item', function () {
if ( window.WCBackbone.Modal.__instance === undefined ) {
window.WCBackbone.Modal.__instance = new WCBackbone.Modal.View({ target: '#wc-modal-add-products' });
}
return false;
})
.on( 'click', 'button.add_order_fee', function() {
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
@ -642,6 +606,65 @@ jQuery( function($){
return false;
});
// Adds new products in order items
$( 'body' ).on( 'wc_backbone_modal_response', function ( e, target ) {
if ( '#wc-modal-add-products' !== target ) {
return;
}
var add_item_ids = $( 'select#add_item_id' ).val();
if ( add_item_ids ) {
count = add_item_ids.length;
$( 'table.woocommerce_order_items' ).block({
message: null,
overlayCSS: {
background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
opacity: 0.6
}
});
$.each( add_item_ids, function( index, value ) {
var data = {
action: 'woocommerce_add_order_item',
item_to_add: value,
order_id: woocommerce_admin_meta_boxes.post_id,
security: woocommerce_admin_meta_boxes.order_item_nonce
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
$( 'table.woocommerce_order_items tbody#order_items_list' ).append( response );
if ( !--count ) {
$( 'select#add_item_id, #add_item_id_chosen .chosen-choices' ).css( 'border-color', '' ).val( '' );
$( '#tiptip_holder' ).removeAttr( 'style' );
$( '#tiptip_arrow' ).removeAttr( 'style' );
$( '.tips' ).tipTip({
'attribute': 'data-tip',
'fadeIn': 50,
'fadeOut': 50,
'delay': 200
});
$( 'select#add_item_id' ).trigger( 'chosen:updated' );
$( 'table.woocommerce_order_items' ).unblock();
}
$( '#order_items_list tr.new_row' ).trigger( 'init_row' ).removeClass( 'new_row' );
});
});
} else {
$( 'select#add_item_id, #add_item_id_chosen .chosen-choices' ).css( 'border-color', 'red' );
}
});
$('span.inline_total').closest('.totals_group').find('input').change();
// Download permissions
@ -888,5 +911,5 @@ jQuery( function($){
});
return false;
});
});
});
});

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
jQuery( function($){
/*global woocommerce_admin_meta_boxes */
jQuery( function ( $ ) {
// run tip tip
function runTipTip() {
// remove any lingering tooltips
@ -19,11 +20,11 @@ jQuery( function($){
$('#titlediv #title').keyup(function( event ) {
var code = event.keyCode || event.which;
if ( code == '9' && $('#woocommerce-coupon-description').size() > 0 ) {
event.stopPropagation();
$('#woocommerce-coupon-description').focus();
return false;
}
if ( code == '9' && $('#woocommerce-coupon-description').size() > 0 ) {
event.stopPropagation();
$('#woocommerce-coupon-description').focus();
return false;
}
});
$(function(){
@ -56,61 +57,79 @@ jQuery( function($){
// Ajax Chosen Product Selectors
jQuery("select.ajax_chosen_select_products").ajaxChosen({
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_products',
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_products',
security: woocommerce_admin_meta_boxes.search_products_nonce
}
}
}, function (data) {
var terms = {};
$.each(data, function (i, val) {
terms[i] = val;
});
$.each(data, function (i, val) {
terms[i] = val;
});
return terms;
return terms;
});
jQuery("select.ajax_chosen_select_products_and_variations").ajaxChosen({
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_products_and_variations',
security: woocommerce_admin_meta_boxes.search_products_nonce
}
}, function (data) {
var terms = {};
/**
* Load Chosen for select products and variations
*
* @return {void}
*/
function loadSelectProductAndVariation() {
$( 'select.ajax_chosen_select_products_and_variations' ).ajaxChosen({
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_products_and_variations',
security: woocommerce_admin_meta_boxes.search_products_nonce
}
},
function ( data ) {
var terms = {};
$.each(data, function (i, val) {
terms[i] = val;
});
$.each(data, function ( i, val ) {
terms[i] = val;
});
return terms;
return terms;
});
}
// Run on document load
loadSelectProductAndVariation();
// Load chosen inside WC Backbone Modal
$( 'body' ).on( 'wc_backbone_modal_loaded', function ( e, target ) {
if ( '#wc-modal-add-products' === target ) {
loadSelectProductAndVariation();
}
});
jQuery("select.ajax_chosen_select_downloadable_products_and_variations").ajaxChosen({
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_downloadable_products_and_variations',
method: 'GET',
url: woocommerce_admin_meta_boxes.ajax_url,
dataType: 'json',
afterTypeDelay: 100,
data: {
action: 'woocommerce_json_search_downloadable_products_and_variations',
security: woocommerce_admin_meta_boxes.search_products_nonce
}
}
}, function (data) {
var terms = {};
$.each(data, function (i, val) {
terms[i] = val;
});
$.each(data, function (i, val) {
terms[i] = val;
});
return terms;
return terms;
});
$( ".date-picker" ).datepicker({
@ -147,4 +166,4 @@ jQuery( function($){
jQuery(this).find('.wc-metabox-content').hide();
});
});
});

View File

@ -1 +1 @@
jQuery(function(a){function b(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})}b(),a("#titlediv #title").keyup(function(b){var c=b.keyCode||b.which;return"9"==c&&a("#woocommerce-coupon-description").size()>0?(b.stopPropagation(),a("#woocommerce-coupon-description").focus(),!1):void 0}),a(function(){jQuery(".wc-metabox > h3").click(function(){a(this).parent(".wc-metabox").toggleClass("closed").toggleClass("open")})}),a("ul.wc-tabs").show(),a("div.panel-wrap").each(function(){a(this).find("div.panel:not(:first)").hide()}),a("ul.wc-tabs a").click(function(){var b=a(this).closest("div.panel-wrap");return a("ul.wc-tabs li",b).removeClass("active"),a(this).parent().addClass("active"),a("div.panel",b).hide(),a(a(this).attr("href")).show(),!1}),a("ul.wc-tabs li:visible").eq(0).find("a").click(),jQuery("select.chosen_select").chosen(),jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"}),jQuery("select.ajax_chosen_select_products").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),jQuery("select.ajax_chosen_select_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),jQuery("select.ajax_chosen_select_downloadable_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_downloadable_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),a(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_admin_meta_boxes.calendar_image,buttonImageOnly:!0}),a(".date-picker-field").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0}),jQuery(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(b){a(b.target).filter(":input, option").length||jQuery(this).next(".wc-metabox-content").toggle()}).on("click",".expand_all",function(){return jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").show(),!1}).on("click",".close_all",function(){return jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").hide(),!1}),jQuery(".wc-metabox.closed").each(function(){jQuery(this).find(".wc-metabox-content").hide()})});
jQuery(function(a){function b(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})}function c(){a("select.ajax_chosen_select_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c})}b(),a("#titlediv #title").keyup(function(b){var c=b.keyCode||b.which;return"9"==c&&a("#woocommerce-coupon-description").size()>0?(b.stopPropagation(),a("#woocommerce-coupon-description").focus(),!1):void 0}),a(function(){jQuery(".wc-metabox > h3").click(function(){a(this).parent(".wc-metabox").toggleClass("closed").toggleClass("open")})}),a("ul.wc-tabs").show(),a("div.panel-wrap").each(function(){a(this).find("div.panel:not(:first)").hide()}),a("ul.wc-tabs a").click(function(){var b=a(this).closest("div.panel-wrap");return a("ul.wc-tabs li",b).removeClass("active"),a(this).parent().addClass("active"),a("div.panel",b).hide(),a(a(this).attr("href")).show(),!1}),a("ul.wc-tabs li:visible").eq(0).find("a").click(),jQuery("select.chosen_select").chosen(),jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"}),jQuery("select.ajax_chosen_select_products").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),c(),a("body").on("wc_backbone_modal_loaded",function(a,b){"#wc-modal-add-products"===b&&c()}),jQuery("select.ajax_chosen_select_downloadable_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_downloadable_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),a(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_admin_meta_boxes.calendar_image,buttonImageOnly:!0}),a(".date-picker-field").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0}),jQuery(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(b){a(b.target).filter(":input, option").length||jQuery(this).next(".wc-metabox-content").toggle()}).on("click",".expand_all",function(){return jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").show(),!1}).on("click",".close_all",function(){return jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").hide(),!1}),jQuery(".wc-metabox.closed").each(function(){jQuery(this).find(".wc-metabox-content").hide()})});

View File

@ -27,6 +27,7 @@
$( 'body' ).css({
'overflow': 'hidden'
}).append( this.$el );
$( 'body' ).trigger( 'wc_backbone_modal_loaded', this._target );
},
closeButton: function ( e ) {
e.preventDefault();
@ -36,10 +37,11 @@
'overflow': 'auto'
});
this.remove();
$( 'body' ).trigger( 'wc_backbone_modal_removed', this._target );
window.WCBackbone.Modal.__instance = undefined;
},
addButton: function ( e ) {
$( 'body' ).trigger( 'wc_backbone_modal_response', this.getFormData() );
$( 'body' ).trigger( 'wc_backbone_modal_response', this._target, this.getFormData() );
this.closeButton( e );
},
getFormData: function () {

View File

@ -1 +1 @@
!function(a,b,c){"use strict";window.WCBackbone={Modal:{__instance:void 0}},window.WCBackbone.Modal.View=b.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:void 0,events:{"click #btn-cancel":"closeButton","click #btn-ok":"addButton"},initialize:function(a){this._target=a.target,c.bindAll(this,"render"),this.render()},render:function(){this.$el.attr("tabindex","0").append(a(this._target).html()),a("body").css({overflow:"hidden"}).append(this.$el)},closeButton:function(b){b.preventDefault(),this.undelegateEvents(),a(document).off("focusin"),a("body").css({overflow:"auto"}),this.remove(),window.WCBackbone.Modal.__instance=void 0},addButton:function(b){a("body").trigger("wc_backbone_modal_response",this.getFormData()),this.closeButton(b)},getFormData:function(){var b={};return a.each(a("form",this.$el).serializeArray(),function(c,d){b.hasOwnProperty(d.name)?(b[d.name]=a.makeArray(b[d.name]),b[d.name].push(d.value)):b[d.name]=d.value}),b}})}(jQuery,Backbone,_);
!function(a,b,c){"use strict";window.WCBackbone={Modal:{__instance:void 0}},window.WCBackbone.Modal.View=b.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:void 0,events:{"click #btn-cancel":"closeButton","click #btn-ok":"addButton"},initialize:function(a){this._target=a.target,c.bindAll(this,"render"),this.render()},render:function(){this.$el.attr("tabindex","0").append(a(this._target).html()),a("body").css({overflow:"hidden"}).append(this.$el),a("body").trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(b){b.preventDefault(),this.undelegateEvents(),a(document).off("focusin"),a("body").css({overflow:"auto"}),this.remove(),a("body").trigger("wc_backbone_modal_removed",this._target),window.WCBackbone.Modal.__instance=void 0},addButton:function(b){a("body").trigger("wc_backbone_modal_response",this._target,this.getFormData()),this.closeButton(b)},getFormData:function(){var b={};return a.each(a("form",this.$el).serializeArray(),function(c,d){b.hasOwnProperty(d.name)?(b[d.name]=a.makeArray(b[d.name]),b[d.name].push(d.value)):b[d.name]=d.value}),b}})}(jQuery,Backbone,_);

View File

@ -133,8 +133,7 @@ class WC_Meta_Box_Order_Items {
</p>
</div>
<div class="wc-order-data-row wc-order-add-item" style="display:none;">
<select id="add_item_id" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>" style="width: 400px"></select>
<button type="button" class="button add_order_item"><?php _e( 'Add item(s)', 'woocommerce' ); ?></button>
<button type="button" class="button add_order_item"><?php _e( 'Add product(s)', 'woocommerce' ); ?></button>
<button type="button" class="button add_order_fee"><?php _e( 'Add fee', 'woocommerce' ); ?></button>
<button type="button" class="button cancel-action"><?php _e( 'Done', 'woocommerce' ); ?></button>
</div>
@ -165,6 +164,30 @@ class WC_Meta_Box_Order_Items {
<button type="button" class="button button-primary do-manual-refund"><?php _e( 'Refund manually', 'woocommerce' ); ?></button>
<button type="button" class="button cancel-action"><?php _e( 'Cancel', 'woocommerce' ); ?></button>
</div>
<script type="text/template" id="wc-modal-add-products">
<div class="wc-backbone-modal">
<div class="wc-backbone-modal-content">
<section class="wc-backbone-modal-main" role="main">
<header>
<h1><?php echo __( 'Add products', 'woocommerce' ); ?></h1>
</header>
<article>
<form>
<select id="add_item_id" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>" style="width: 96%"></select>
</form>
</article>
<footer>
<div class="inner">
<button id="btn-cancel" class="button button-large"><?php echo __( 'Cancel' , 'woocommerce' ); ?></button>
<button id="btn-ok" class="button button-primary button-large"><?php echo __( 'Add' , 'woocommerce' ); ?></button>
</div>
</footer>
</section>
</div>
</div>
<div class="wc-backbone-modal-backdrop">&nbsp;</div>
</script>
<?php
}