-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from vendidero/shipping-rules
Shipping rules, label configuration sets
- Loading branch information
Showing
64 changed files
with
16,307 additions
and
6,097 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
window.germanized = window.germanized || {}; | ||
window.germanized.admin = window.germanized.admin || {}; | ||
|
||
( function( $, admin ) { | ||
admin.packaging = { | ||
params: {}, | ||
|
||
init: function() { | ||
var self = germanized.admin.packaging; | ||
|
||
$( document ) | ||
.on( 'change', 'input.gzd-override-toggle', self.onChangeOverride ); | ||
}, | ||
|
||
onChangeOverride: function() { | ||
var $checkbox = $( this ), | ||
$wrapper = $checkbox.parents( '.wc-gzd-shipping-provider-override-title-wrapper' ), | ||
$next = $wrapper.next( '.wc-gzd-packaging-zone-wrapper' ); | ||
|
||
$next.removeClass( 'zone-wrapper-has-override' ); | ||
|
||
if ( $checkbox.is( ':checked' ) ) { | ||
$next.addClass( 'zone-wrapper-has-override' ); | ||
} | ||
}, | ||
}; | ||
|
||
$( document ).ready( function() { | ||
germanized.admin.packaging.init(); | ||
}); | ||
|
||
})( jQuery, window.germanized.admin ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
window.germanized = window.germanized || {}; | ||
window.germanized.admin = window.germanized.admin || {}; | ||
|
||
( function( $, admin ) { | ||
admin.shipment_settings = { | ||
params: {}, | ||
|
||
init: function() { | ||
var self = germanized.admin.shipment_settings; | ||
self.params = wc_gzd_admin_shipment_settings_params; | ||
|
||
$( document ) | ||
.on( 'click', 'a.woocommerce-gzd-shipment-input-toggle-trigger', self.onInputToggleClick ) | ||
.on( 'change gzd_shipments_show_or_hide_fields', 'table.form-table :input[id]', self.onChangeInput ); | ||
|
||
$( 'table.form-table :input[id]' ).trigger( 'gzd_shipments_show_or_hide_fields' ); | ||
}, | ||
|
||
getCleanInputId: function( $mainInput ) { | ||
var self = germanized.admin.shipment_settings, | ||
fieldId = $mainInput.attr( 'id' ) ? $mainInput.attr( 'id' ) : $mainInput.attr( 'name' ); | ||
|
||
if ( self.params.hasOwnProperty( 'clean_input_callback' ) ) { | ||
var callback = self.params.clean_input_callback, | ||
params = [], | ||
objectName = '', | ||
methodName = ''; | ||
|
||
if ( callback.substring( 0, 17 ) === 'germanized.admin.' ) { | ||
callback = callback.slice( 17 ); | ||
|
||
params = callback.split( "." ); | ||
objectName = germanized.admin[params[0]]; | ||
methodName = params[1]; | ||
} else { | ||
params = callback.split( "." ); | ||
objectName = window[params[0]]; | ||
methodName = params[1]; | ||
} | ||
|
||
if ( 'object' === typeof objectName && objectName.hasOwnProperty( methodName ) ) { | ||
fieldId = objectName[methodName]( $mainInput ); | ||
} | ||
} | ||
|
||
if ( ! fieldId ) { | ||
return ''; | ||
} | ||
|
||
return fieldId; | ||
}, | ||
|
||
getInputByIdOrName: function( $wrapper , cleanName ) { | ||
var self = germanized.admin.shipment_settings; | ||
cleanName = self.getCleanDataId( cleanName ); | ||
|
||
return $wrapper.find( ':input' ).filter( function() { | ||
var id = self.getCleanInputId( $( this ) ); | ||
|
||
if ( ! id ) { | ||
return false; | ||
} | ||
|
||
return self.getCleanDataId( id ) === cleanName; | ||
}); | ||
}, | ||
|
||
/** | ||
* Make sure to remove any hyphens as data-attributes are stored | ||
* camel case without hyphens in the DOM. | ||
*/ | ||
getCleanDataId: function( id ) { | ||
return id.toLowerCase().replace( /-/g, '' ); | ||
}, | ||
|
||
onChangeInput: function() { | ||
var self = germanized.admin.shipment_settings, | ||
$mainInput = $( this ), | ||
$wrapper = $( this ).parents( 'form' ), | ||
mainId = self.getCleanInputId( $mainInput ), | ||
$dependentFields = $wrapper.find( ':input[data-show_if_' + $.escapeSelector( mainId ) + ']' ); | ||
|
||
var $input, $field, data, meetsConditions, cleanName, $dependentField, valueExpected, val, isChecked; | ||
|
||
$.each( $dependentFields, function () { | ||
$input = $( this ); | ||
$field = $input.parents( 'tr' ); | ||
data = $input.data(); | ||
meetsConditions = true; | ||
|
||
for ( var dataName in data ) { | ||
if ( data.hasOwnProperty( dataName ) ) { | ||
/** | ||
* Check all the conditions for a dependent field. | ||
*/ | ||
if ( dataName.substring( 0, 8 ) === 'show_if_' ) { | ||
cleanName = dataName.replace( 'show_if_', '' ); | ||
$dependentField = self.getInputByIdOrName( $wrapper, cleanName ); | ||
valueExpected = $input.data( dataName ) ? $input.data( dataName ).split(',') : []; | ||
|
||
if ( $dependentField.length > 0 ) { | ||
val = $dependentField.val(); | ||
isChecked = false; | ||
|
||
if ( $dependentField.is( ':radio' ) ) { | ||
val = $dependentField.parents( 'fieldset' ).find( ':checked' ).length > 0 ? $dependentField.parents( 'fieldset' ).find( ':checked' ).val() : 'no'; | ||
|
||
if ( 'no' !== val ) { | ||
isChecked = true; | ||
} | ||
} else if ( $dependentField.is( ':checkbox' ) ) { | ||
val = $dependentField.is( ':checked' ) ? 'yes' : 'no'; | ||
|
||
if ( 'yes' === val ) { | ||
isChecked = true; | ||
} | ||
} else { | ||
isChecked = undefined !== val && '0' !== val && '' !== val; | ||
} | ||
|
||
if ( valueExpected && valueExpected.length > 0 ) { | ||
if ( $.inArray( val, valueExpected ) === -1 ) { | ||
meetsConditions = false; | ||
} | ||
} else if ( ! isChecked ) { | ||
meetsConditions = false; | ||
} | ||
} | ||
|
||
if ( ! meetsConditions ) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ( meetsConditions ) { | ||
$field.show(); | ||
} else { | ||
$field.hide(); | ||
} | ||
} ); | ||
}, | ||
|
||
onInputToggleClick: function() { | ||
var $toggle = $( this ).find( 'span.woocommerce-gzd-input-toggle' ), | ||
$row = $toggle.parents( 'fieldset' ), | ||
$checkbox = $row.find( 'input[type=checkbox]' ), | ||
$enabled = $toggle.hasClass( 'woocommerce-input-toggle--enabled' ); | ||
|
||
$toggle.removeClass( 'woocommerce-input-toggle--enabled' ); | ||
$toggle.removeClass( 'woocommerce-input-toggle--disabled' ); | ||
|
||
if ( $enabled ) { | ||
$checkbox.prop( 'checked', false ); | ||
$toggle.addClass( 'woocommerce-input-toggle--disabled' ); | ||
} else { | ||
$checkbox.prop( 'checked', true ); | ||
$toggle.addClass( 'woocommerce-input-toggle--enabled' ); | ||
} | ||
|
||
$checkbox.trigger( 'change' ); | ||
|
||
return false; | ||
} | ||
}; | ||
|
||
$( document ).ready( function() { | ||
germanized.admin.shipment_settings.init(); | ||
}); | ||
|
||
})( jQuery, window.germanized.admin ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.