Skip to content

Commit

Permalink
Merge pull request #83 from joomla/revert-79-_helpsite
Browse files Browse the repository at this point in the history
Revert "helpsite.js refactor"
  • Loading branch information
wilsonge committed Oct 24, 2016
2 parents 2e14a1d + e730fee commit 2057128
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 52 deletions.
77 changes: 26 additions & 51 deletions media/system/js/helpsite.js
@@ -1,57 +1,32 @@
/**
* @package Joomla.JavaScript
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package Joomla.JavaScript
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

/**
* Rebuilds the list with the available help sites
* gets the help site with ajax
*/
"use strict";

var resetHelpSiteList = function() {

// Uses global variable helpsite_base for bast uri
var select_id = this.getAttribute('rel');
var showDefault = this.getAttribute('showDefault');

Joomla.request(
{
url: 'index.php?option=com_users&task=profile.gethelpsites&format=json',
method: 'GET',
data: '',
perform: true,
headers: {'Content-Type': 'application/json;charset=utf-8'},
onSuccess: function(response, xhr)
{
response = JSON.parse(response);

// The response contains the options to use in help site select field
var node;

document.getElementById("#" + select_id).innerHTML = '';

// Build options
response.data.forEach(function(key, val) {
if (val.value !== '' || showDefault === 'true') {
node = document.createElement('option');
node.value = val.value;
node.innerHTML = val.text
document.getElementById("#" + select_id).appendChild(items);
}
});
},
onError: function(xhr)
{
// Remove js messages, if they exist.
Joomla.removeMessages();

Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr));
}
}
);
};

document.addEventListener('DOMContentLoaded', function() {
document.getElementById('helpsite-refresh').addEventListener('click', resetHelpSiteList);
jQuery(document).ready(function() {
jQuery('#helpsite-refresh').click(function()
{
// Uses global variable helpsite_base for bast uri
var select_id = jQuery(this).attr('rel');
var showDefault = jQuery(this).attr('showDefault');

jQuery.getJSON('index.php?option=com_users&task=profile.gethelpsites&format=json', function(data){
// The response contains the options to use in help site select field
var items = [];

// Build options
jQuery.each(data, function(key, val) {
if (val.value !== '' || showDefault === 'true') {
items.push('<option value="' + val.value + '">' + val.text + '</option>');
}
});

// Replace current select options. The trigger is needed for Chosen select box enhancer
jQuery("#" + select_id).empty().append(items).trigger("liszt:updated");
});
});
});
2 changes: 1 addition & 1 deletion media/system/js/helpsite.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2057128

Please sign in to comment.