Commit 9fa1dbd7 authored by Dom.'s avatar Dom. Committed by Dom.

Issue #2382785 by Dominique CLAUSE, ñull, jmdeleon: Add localize to no_results...

Issue #2382785 by Dominique CLAUSE, ñull, jmdeleon: Add localize to no_results and all_results labels.
parent b4fe1f81
......@@ -39,8 +39,7 @@
if (item.value == '') {
elem = $("<li class='ui-state-disabled ui-menu-item-" + first + " ui-menu-item'>" + item.label + "</li>" );
}
elem.data("item.autocomplete", item)
.appendTo(ul);
elem.data("item.autocomplete", item).appendTo(ul);
Drupal.attachBehaviors(elem);
return elem;
......@@ -66,10 +65,12 @@
$.getJSON(Drupal.settings.search_autocomplete[key].datas, { q: request.term }, function (results) {
// Only return the number of values set in the settings.
if (!results.length && no_results) {
results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, request.term))];
results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>'))];
} else {
results.slice(0, Drupal.settings.search_autocomplete[key].max_sug);
results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, request.term)));
if (all_results) {
results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>')));
}
}
response(results);
});
......@@ -79,10 +80,12 @@
$.getJSON(Drupal.settings.search_autocomplete[key].datas + request.term, { }, function (results) {
// Only return the number of values set in the settings.
if (!results.length && no_results) {
results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, request.term))];
results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>'))];
} else {
results.slice(0, Drupal.settings.search_autocomplete[key].max_sug);
results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, request.term)));
if (all_results) {
results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>')));
}
}
response(results);
});
......@@ -91,10 +94,12 @@
else if (Drupal.settings.search_autocomplete[key].type == 'static') {
var results = $.ui.autocomplete.filter(Drupal.settings.search_autocomplete[key].datas, request.term);
if (!results.length && no_results) {
results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, request.term))];
results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>'))];
} else {
results.slice(0, Drupal.settings.search_autocomplete[key].max_sug);
results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, request.term)));
if (all_results) {
results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>')));
}
}
response(results);
}
......
......@@ -81,7 +81,7 @@ function search_autocomplete_form_add_submit($form, &$form_state) {
'title' => $values['title'],
'selector' => $values['selector'],
'no_results' => json_encode(array( // manually add no_results default
'label' => 'No results found for <b>[search-phrase]</b>.<br/>Click to perform full search.',
'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -89,7 +89,7 @@ function search_autocomplete_form_add_submit($form, &$form_state) {
),
)),
'all_results' => json_encode(array( // manually add all_results default
'label' => 'View all results for <b>[search-phrase]</b>.',
'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......
......@@ -87,7 +87,7 @@ function search_autocomplete_form_configure($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('Custom "view all results" message label'),
'#description' => t('This message is going to be displayed at the end of suggestion list when suggestions are found. Leave empty to disable this functionality. You can use HTML tags as well as the token [search-phrase] to replace user input.'),
'#default_value' => $all_results->label,
'#default_value' => t($all_results->label),
'#maxlength' => 255,
'#required' => FALSE,
);
......@@ -124,7 +124,7 @@ function search_autocomplete_form_configure($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('Custom "no result" message label'),
'#description' => t('This message is going to be displayed when no suggestions can be found. Leave empty to disable this functionality. You can use HTML tags as well as the token [search-phrase] to replace user input.'),
'#default_value' => $no_results->label,
'#default_value' => t($no_results->label),
'#maxlength' => 255,
'#required' => FALSE,
);
......@@ -395,4 +395,4 @@ function _search_autocomplete_get_all_children($fid, &$items = array(), $depth =
_search_autocomplete_get_all_children($item->fid, $items, $depth);
}
return $items;
}
\ No newline at end of file
}
......@@ -159,7 +159,7 @@ function search_autocomplete_install() {
'min_char' => $trigger,
'max_sug' => $limit,
'no_results' => json_encode(array(
'label' => 'No results found for <b>[search-phrase]</b>.<br/>Click to perform full search.',
'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -167,7 +167,7 @@ function search_autocomplete_install() {
),
)),
'all_results' => json_encode(array(
'label' => 'View all results for <b>[search-phrase]</b>.',
'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -191,7 +191,7 @@ function search_autocomplete_install() {
'min_char' => $trigger,
'max_sug' => $limit,
'no_results' => json_encode(array(
'label' => 'No results found for <b>[search-phrase]</b>.<br/> Click to perform full search.',
'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -199,7 +199,7 @@ function search_autocomplete_install() {
),
)),
'all_results' => json_encode(array(
'label' => 'View all results for <b>[search-phrase]</b>.',
'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -223,7 +223,7 @@ function search_autocomplete_install() {
'min_char' => $trigger,
'max_sug' => $limit,
'no_results' => json_encode(array(
'label' => 'No results found for <b>[search-phrase]</b>.<br/>Click to perform full search.',
'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -231,7 +231,7 @@ function search_autocomplete_install() {
),
)),
'all_results' => json_encode(array(
'label' => 'View all results for <b>[search-phrase]</b>.',
'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -395,7 +395,7 @@ function search_autocomplete_update_7410(&$sandbox) {
}
/**
* Migrate no_results and all_resuts fields from 4.0 to 4.1 default value
* Migrate no_results and all_results fields from 4.0 to 4.1 default values
*/
function search_autocomplete_update_7411(&$sandbox) {
if (!db_field_exists('search_autocomplete_forms', 'no_results')) {
......@@ -415,7 +415,7 @@ function search_autocomplete_update_7411(&$sandbox) {
}
db_update('search_autocomplete_forms') // Table name no longer needs {}
->fields(array('no_results' => json_encode(array(
'label' => 'No results found for <b>[search-phrase]</b>.<br/>Click to perform full search.',
'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -434,7 +434,7 @@ function search_autocomplete_update_7411(&$sandbox) {
}
db_update('search_autocomplete_forms') // Table name no longer needs {}
->fields(array('all_results' => json_encode(array(
'label' => 'View all results for <b>[search-phrase]</b>.',
'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
......@@ -442,4 +442,31 @@ function search_autocomplete_update_7411(&$sandbox) {
),
))))
->execute();
}
\ No newline at end of file
}
/**
* Migrate no_results and all_results fields from 4.1 to 4.2 default values
*/
function search_autocomplete_update_7420(&$sandbox) {
$all_fields = db_select('search_autocomplete_forms', 'sa')
->fields('sa', array('fid', 'no_results', 'all_results'))
->execute()
->fetchAllAssoc('fid');
foreach($all_fields as $fid => $field) {
// Remove html tags in no_results label
$no_results = json_decode($field->no_results);
$no_results->label = strip_tags($no_results->label);
$all_results = json_decode($field->all_results);
$all_results->label = strip_tags($all_results->label);
db_update('search_autocomplete_forms')
->fields(array(
'no_results' => json_encode($no_results),
'all_results' => json_encode($all_results)
))
->condition('fid', $fid, '=')
->execute();
}
}
......@@ -70,13 +70,21 @@ function search_autocomplete_page_build() {
}
}
// Translate no_results label
$no_results = json_decode($match->no_results);
$no_results->label = t($no_results->label);
// Translate all_results label
$all_results = json_decode($match->all_results);
$all_results->label = t($all_results->label);
drupal_add_js(array('search_autocomplete' => array(
$form_id => array(
'selector' => $match->selector,
'minChars' => $match->min_char,
'max_sug' => $match->max_sug,
'no_results' => t($match->no_results),
'all_results' => t($match->all_results),
'no_results' => $no_results->label ? json_encode($no_results) : null,
'all_results' => $all_results->label ? json_encode($all_results) : null,
'type' => $data_source,
'datas' => $match->data_source == 'static' ? $data_static : $data_callback,
'fid' => $match->fid,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment