-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 #83 from joomla/revert-79-_helpsite
Revert "helpsite.js refactor"
- Loading branch information
Showing
2 changed files
with
27 additions
and
52 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,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"); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.