Skip to content

Commit

Permalink
fixed 2 minor bugs and have done more work on autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Apr 25, 2013
1 parent 4c9bac6 commit 9ed769d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 50 deletions.
6 changes: 3 additions & 3 deletions upload/admin/controller/catalog/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ public function autocomplete() {
if ($option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
$type = $this->language->get('text_date');
}

$json[] = array(

$json[$option['type']]['name'] = $type;
$json[$option['type']][] = array(
'option_id' => $option['option_id'],
'name' => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
'category' => $type,
'type' => $option['type'],
'option_value' => $option_value_data
);
Expand Down
2 changes: 2 additions & 0 deletions upload/admin/controller/sale/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,8 @@ protected function validateForm() {

if ($product_info && $product_info['shipping']) {
$shipping = true;

break;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions upload/admin/view/template/catalog/category_form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ $('input[name=\'path\']').on('click keyup', function() {
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/category/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
Expand Down Expand Up @@ -307,7 +307,7 @@ $('input[name=\'filter\']').on('click keyup', function() {
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/filter/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
Expand Down
118 changes: 75 additions & 43 deletions upload/admin/view/template/catalog/product_form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ $('input[name=\'manufacturer\']').on('click keyup', function() {
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/manufacturer/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
Expand Down Expand Up @@ -892,7 +892,6 @@ $('#autocomplete-manufacturer').delegate('a', 'click', function(e) {
}
});
// Category
var timer = null;
Expand All @@ -903,7 +902,7 @@ $('input[name=\'category\']').on('click keyup', function() {
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/category/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
Expand Down Expand Up @@ -949,7 +948,7 @@ $('input[name=\'filter\']').on('click keyup', function() {
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/filter/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
Expand Down Expand Up @@ -994,7 +993,7 @@ $('input[name=\'download\']').on('click keyup', function() {
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/download/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
Expand Down Expand Up @@ -1039,7 +1038,7 @@ $('input[name=\'related\']').on('click keyup', function() {
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
Expand Down Expand Up @@ -1088,7 +1087,7 @@ function addAttribute() {
html += ' </td>';
html += ' <td class="left">';
<?php foreach ($languages as $language) { ?>
html += '<textarea name="product_attribute[' + attribute_row + '][product_attribute_description][<?php echo $language['language_id']; ?>][text]" cols="40" rows="5" placeholder="<?php echo $entry_text; ?>"></textarea><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" align="top" /><br />';
html += '<textarea name="product_attribute[' + attribute_row + '][product_attribute_description][<?php echo $language['language_id']; ?>][text]" cols="40" rows="5" placeholder="<?php echo $entry_text; ?>"></textarea> <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" align="top" /><br />';
<?php } ?>
html += ' </td>';
html += ' <td class="left"><a onclick="$(\'#attribute-row' + attribute_row + '\').remove();" class="btn"><i class="icon-minus-sign"></i> <?php echo $button_remove; ?></a></td>';
Expand All @@ -1110,7 +1109,7 @@ $('#attribute').delegate('input[data-toggle=\'dropdown\']', 'click keyup', funct
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/attribute/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
Expand Down Expand Up @@ -1143,31 +1142,69 @@ $('#attribute').delegate('.dropdown-menu a', 'click', function(e) {
<script type="text/javascript"><!--
var option_row = <?php echo $option_row; ?>;
$('input[name=\'option\']').catcomplete({
delay: 500,
source: function(request, response) {
$('input[name=\'option\']').on('click keyup', function() {
var input = this;
if (timer != null) {
clearTimeout(timer);
}
timer = setTimeout(function() {
$.ajax({
url: 'index.php?route=catalog/option/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request.term),
dataType: 'json',
url: 'index.php?route=catalog/option/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent($(input).val()),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
category: item.category,
label: item.name,
value: item.option_id,
type: item.type,
option_value: item.option_value
html = '';
if (json) {
//for (i = 0; i < json.length; i++) {
// json[json[i]['category']][] =
//}
for (i = 0; i < json.length; i++) {
html += '<li class="disabled"><a href="#"><b>' + json[i]['category'] + '</b></a></li>';
html += '<li data-value="' + json[i]['option_id'] + '"><a href="#">' + json[i]['name'] + '</a>';
html += '<input type="hidden" name="type" value="' + json[i]['type'] + '" />';
for (j = 0; j < json[i]['option_value'].length; i++) {
option_value = json[i]['option_value'];
html += '<input type="hidden" name="option_value[' + j + '][option_value_id]" value="' + option_value[j]['option_value_id'] + '" />';
html += '<input type="hidden" name="option_value[' + j + '][name]" value="' + option_value[j]['name'] + '" />';
}
html += '</li>';
}
}));
}
$($(input).attr('data-target')).find('ul').html(html);
}
});
},
select: function(event, ui) {
}, 250);
});
$('#autocomplete-option').delegate('a', 'click', function(e) {
e.preventDefault();
var value = $(this).parent().attr('data-value');
if (typeof value !== 'undefined') {
$('input[name=\'option\']').val($(this).text());
text = $(this).text();
type = $(this).parent().find('input[name=\'type\']').val();
option_value = $(this).parent().find('input[name^=\'option_value\']');
html = '<div class="tab-pane" id="tab-option' + option_row + '">';
html += ' <input type="hidden" name="product_option[' + option_row + '][product_option_id]" value="" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][name]" value="' + ui.item.label + '" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][option_id]" value="' + ui.item.value + '" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][type]" value="' + ui.item.type + '" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][name]" value="' + text + '" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][option_id]" value="' + value + '" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][type]" value="' + type + '" />';
html += ' <div class="control-group">';
html += ' <label class="control-label" for="input-required' + option_row + '"><?php echo $entry_required; ?></label>';
Expand All @@ -1177,49 +1214,49 @@ $('input[name=\'option\']').catcomplete({
html += ' </select></div>';
html += ' </div>';
if (ui.item.type == 'text') {
if (type == 'text') {
html += ' <div class="control-group">';
html += ' <label class="control-label" for="input-value' + option_row + '"><?php echo $entry_option_value; ?></label>';
html += ' <div class="controls"><input type="text" name="product_option[' + option_row + '][value]" value="" placeholder="<?php echo $entry_option_value; ?>" id="input-value' + option_row + '" /></div>';
html += ' </div>';
}
if (ui.item.type == 'textarea') {
if (type == 'textarea') {
html += ' <div class="control-group">';
html += ' <label class="control-label" for="input-value' + option_row + '"><?php echo $entry_option_value; ?></label>';
html += ' <div class="controls"><textarea name="product_option[' + option_row + '][value]" cols="40" rows="5" placeholder="<?php echo $entry_option_value; ?>" id="input-value' + option_row + '"></textarea></div>';
html += ' </div>';
}
if (ui.item.type == 'file') {
if (type == 'file') {
html += ' <div class="control-group" style="display: none;">';
html += ' <label class="control-label" for="input-value' + option_row + '"><?php echo $entry_option_value; ?></label>';
html += ' <div class="controls"><input type="text" name="product_option[' + option_row + '][value]" value="" placeholder="<?php echo $entry_option_value; ?>" id="input-value' + option_row + '" /></div>';
html += ' </div>';
}
if (ui.item.type == 'date') {
if (type == 'date') {
html += ' <div class="control-group">';
html += ' <label class="control-label" for="input-value' + option_row + '"><?php echo $entry_option_value; ?></label>';
html += ' <div class="controls"><input type="date" name="product_option[' + option_row + '][value]" value="" placeholder="<?php echo $entry_option_value; ?>" id="input-value' + option_row + '" class="input-medium" /></div>';
html += ' </div>';
}
if (ui.item.type == 'datetime') {
if (type == 'datetime') {
html += ' <div class="control-group">';
html += ' <label class="control-label" for="input-value' + option_row + '"><?php echo $entry_option_value; ?></label>';
html += ' <div class="controls"><input type="datetime-local" name="product_option[' + option_row + '][value]" value="" placeholder="<?php echo $entry_option_value; ?>" id="input-value' + option_row + '" /></div>';
html += ' </div>';
}
if (ui.item.type == 'time') {
if (type == 'time') {
html += ' <div class="control-group">';
html += ' <label class="control-label" for="input-value' + option_row + '"><?php echo $entry_option_value; ?></label>';
html += ' <div class="controls"><input type="time" name="product_option[' + option_row + '][value]" value="" placeholder="<?php echo $entry_option_value; ?>" id="input-value' + option_row + '" class="input-mini" /></div>';
html += ' </div>';
}
if (ui.item.type == 'select' || ui.item.type == 'radio' || ui.item.type == 'checkbox' || ui.item.type == 'image') {
if (type == 'select' || type == 'radio' || type == 'checkbox' || type == 'image') {
html += ' <table id="option-value' + option_row + '" class="table table-striped table-bordered table-hover">';
html += ' <thead>';
html += ' <tr>';
Expand All @@ -1243,27 +1280,22 @@ $('input[name=\'option\']').catcomplete({
html += ' </table>';
html += ' <select id="option-values' + option_row + '" style="display: none;">';
for (i = 0; i < ui.item.option_value.length; i++) {
html += ' <option value="' + ui.item.option_value[i]['option_value_id'] + '">' + ui.item.option_value[i]['name'] + '</option>';
for (i = 0; i < option_value.length; i++) {
html += ' <option value="' + option_value[i]['option_value_id'] + '">' + option_value[i]['name'] + '</option>';
}
html += ' </select>';
html += '</div>';
}
$('#tab-option').append(html);
$('#tab-option .tab-content').append(html);
$('#option').prepend('<li><a href="#tab-option' + option_row + '" data-toggle="tab"><i class="icon-minus-sign" onclick="$(\'a[href=\\\'#tab-option' + option_row + '\\\'\').parent().remove(); $(\'#tab-option' + option_row + '\').remove(); $(\'#vtab-option a:first\').trigger(\'click\');"></i> ' + ui.item.label + '</li>');
$('#option').append('<li><a href="#tab-option' + option_row + '" data-toggle="tab"><i class="icon-minus-sign" onclick="$(\'a[href=\\\'#tab-option' + option_row + '\\\'\').parent().remove(); $(\'#tab-option' + option_row + '\').remove(); $(\'#vtab-option a:first\').trigger(\'click\');"></i> ' + text + '</li>');
$('#option a[href=\'#tab-option' + option_row + '\']').tab('show');
option_row++;
return false;
},
focus: function(event, ui) {
return false;
}
}
});
//--></script>
<script type="text/javascript"><!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="limit"><?php echo $text_limit; ?>
<select onchange="location = this.value;">
<?php foreach ($limits as $limits) { ?>
<?php if ($limit['value'] == $limit) { ?>
<?php if ($limits['value'] == $limit) { ?>
<option value="<?php echo $limits['href']; ?>" selected="selected"><?php echo $limits['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $limits['href']; ?>"><?php echo $limits['text']; ?></option>
Expand Down Expand Up @@ -162,4 +162,4 @@ if (view) {
display('list');
}
//--></script>
<?php echo $footer; ?>
<?php echo $footer; ?>

0 comments on commit 9ed769d

Please sign in to comment.