-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
143 additions
and
165 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,103 +1,88 @@ | ||
jQuery(document).ready(function ($) { | ||
const globalAttributes = $('.global_attribute_table'); | ||
let uniqueId = Math.random().toString(36).substr(2, 9); | ||
const globalAttributes = $('.global_attribute_table'); | ||
let uniqueId = Math.random().toString(36).substr(2, 9); | ||
|
||
// deploy-button FROM build_hook | ||
const buildUrl = $('#build_url'); | ||
$('#deploy-button').click(function (e) { | ||
e.preventDefault(); | ||
$.ajax({ | ||
url: buildUrl.val(), | ||
type: 'POST', | ||
success: function (data) { | ||
alert('Build triggered successfully'); | ||
}, | ||
}); | ||
}); | ||
// product_attributes is an object that contains the product attributes | ||
|
||
// add global attribute | ||
$('.add_global_attribute').click(function (e) { | ||
e.preventDefault(); | ||
console.log('add global attribute'); | ||
const newAttribute = ` | ||
<tr> | ||
<td> | ||
<input type="text" | ||
class="flex-1" | ||
name="woonuxt_options[global_attributes][${uniqueId}][label]" | ||
value="" | ||
placeholder="e.g. Filter by Color" | ||
/> | ||
</td> | ||
<td> | ||
<select name="woonuxt_options[global_attributes][${uniqueId}][slug]" required> | ||
<?php foreach ( $product_attributes as $attribute ) : ?> | ||
<option value="" disabled selected>Select Attribute</option> | ||
<option value="pa_<?php echo $attribute->attribute_name; ?>"> | ||
<?php echo $attribute->attribute_label; ?> | ||
</option> | ||
<?php endforeach; ?> | ||
</select> | ||
</td> | ||
<td> | ||
<input type="checkbox" | ||
name="woonuxt_options[global_attributes][${uniqueId}][showCount]" | ||
value="1" | ||
/> | ||
</td> | ||
<td> | ||
<input type="checkbox" | ||
name="woonuxt_options[global_attributes][${uniqueId}][hideEmpty]" | ||
value="1" | ||
/> | ||
</td> | ||
<td> | ||
<input type="checkbox" | ||
name="woonuxt_options[global_attributes][${uniqueId}][openByDefault]" | ||
value="1" | ||
/> | ||
</td> | ||
<td> | ||
<div class="text-right row-actions"> | ||
<a href="#" class="text-danger remove_global_attribute">Delete</a> | | ||
<a href="#" title="Move Up" class="text-primary move_global_attribute_up">▲</a> | | ||
<a href="#" title="Move Down" class="text-primary move_global_attribute_down">▼</a> | ||
</div> | ||
</td> | ||
</tr> | ||
`; | ||
// deploy-button FROM build_hook | ||
const buildUrl = $('#build_url'); | ||
$('#deploy-button').click(function (e) { | ||
e.preventDefault(); | ||
$.ajax({ | ||
url: buildUrl.val(), | ||
type: 'POST', | ||
success: function (data) { | ||
alert('Build triggered successfully'); | ||
}, | ||
}); | ||
}); | ||
|
||
globalAttributes.find('tbody').append(newAttribute); | ||
// add global attribute | ||
$('.add_global_attribute').click(function (e) { | ||
e.preventDefault(); | ||
console.log('add global attribute'); | ||
const newAttribute = ` | ||
<tr> | ||
<td> | ||
<input type="text" class="flex-1" name="woonuxt_options[global_attributes][${uniqueId}][label]" value="" placeholder="e.g. Filter by Color"/> | ||
</td> | ||
<td> | ||
<select name="woonuxt_options[global_attributes][${uniqueId}][slug]" required> | ||
${Object.keys(product_attributes).map((key) => { | ||
return `<option value="pa_${product_attributes[key].attribute_name}">${product_attributes[key].attribute_label}</option>`; | ||
})} | ||
</select> | ||
</td> | ||
<td> | ||
<input type="checkbox" name="woonuxt_options[global_attributes][${uniqueId}][showCount]" value="1" /> | ||
</td> | ||
<td> | ||
<input type="checkbox" name="woonuxt_options[global_attributes][${uniqueId}][hideEmpty]"value="1" /> | ||
</td> | ||
<td> | ||
<input type="checkbox" name="woonuxt_options[global_attributes][${uniqueId}][openByDefault]" value="1" /> | ||
</td> | ||
<td> | ||
<div class="text-right row-actions"> | ||
<a href="#" class="text-danger remove_global_attribute">Delete</a> | | ||
<a href="#" title="Move Up" class="text-primary move_global_attribute_up">▲</a> | | ||
<a href="#" title="Move Down" class="text-primary move_global_attribute_down">▼</a> | ||
</div> | ||
</td> | ||
</tr> | ||
`; | ||
|
||
uniqueId = Math.random().toString(36).substr(2, 9); | ||
}); | ||
globalAttributes.find('tbody').append(newAttribute); | ||
|
||
// remove global attribute | ||
$(document).on('click', '.remove_global_attribute', function (e) { | ||
e.preventDefault(); | ||
console.log('remove'); | ||
// find parent tr | ||
$(this).closest('tr').remove(); | ||
}); | ||
uniqueId = Math.random().toString(36).substr(2, 9); | ||
}); | ||
|
||
// move global attribute | ||
$(document).on('click', '.move_global_attribute_up', function (e) { | ||
e.preventDefault(); | ||
console.log('move up'); | ||
const currentRow = $(this).closest('tr'); | ||
const prevRow = currentRow.prev(); | ||
if (prevRow.length) { | ||
currentRow.insertBefore(prevRow); | ||
} | ||
}); | ||
// remove global attribute | ||
$(document).on('click', '.remove_global_attribute', function (e) { | ||
e.preventDefault(); | ||
console.log('remove'); | ||
// find parent tr | ||
$(this).closest('tr').remove(); | ||
}); | ||
|
||
$(document).on('click', '.move_global_attribute_down', function (e) { | ||
e.preventDefault(); | ||
console.log('move down'); | ||
const currentRow = $(this).closest('tr'); | ||
const nextRow = currentRow.next(); | ||
if (nextRow.length) { | ||
currentRow.insertAfter(nextRow); | ||
} | ||
}); | ||
// move global attribute | ||
$(document).on('click', '.move_global_attribute_up', function (e) { | ||
e.preventDefault(); | ||
console.log('move up'); | ||
const currentRow = $(this).closest('tr'); | ||
const prevRow = currentRow.prev(); | ||
if (prevRow.length) { | ||
currentRow.insertBefore(prevRow); | ||
} | ||
}); | ||
|
||
$(document).on('click', '.move_global_attribute_down', function (e) { | ||
e.preventDefault(); | ||
console.log('move down'); | ||
const currentRow = $(this).closest('tr'); | ||
const nextRow = currentRow.next(); | ||
if (nextRow.length) { | ||
currentRow.insertAfter(nextRow); | ||
} | ||
}); | ||
}); |
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