forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 1
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 joomla#83 from Anu1601CS/extension-es6
Transform media/plg_quickicon_extensionupdate to es6
- Loading branch information
Showing
2 changed files
with
132 additions
and
74 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
media/plg_quickicon_extensionupdate/js/extensionupdatecheck.es6.js
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
// Ajax call to get the update status of the installed extensions | ||
(() => { | ||
'use strict'; | ||
|
||
// Add a listener on content loaded to initiate the check | ||
document.addEventListener('DOMContentLoaded', () => { | ||
if (Joomla.getOptions('js-extensions-update')) { | ||
const options = Joomla.getOptions('js-extensions-update'); | ||
Joomla.request({ | ||
url: `${options.ajaxUrl}&eid=0&skip=700`, | ||
method: 'GET', | ||
data: '', | ||
perform: true, | ||
onSuccess: (response) => { | ||
const link = document.getElementById('plg_quickicon_extensionupdate'); | ||
const linkSpan = link.querySelectorAll('span.j-links-link'); | ||
const updateInfoList = JSON.parse(response); | ||
|
||
if (updateInfoList instanceof Array) { | ||
if (updateInfoList.length === 0) { | ||
// No updates | ||
link.classList.add('success'); | ||
for (let i = 0, len = linkSpan.length; i < len; i += 1) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPTODATE'); | ||
} | ||
} else { | ||
const messages = { | ||
message: [ | ||
`${Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND_MESSAGE').replace('%s', `<span class="badge badge-light">${updateInfoList.length}</span>`)}<button class="btn btn-primary" onclick="document.location='${options.url}'">${Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND_BUTTON')}</button>`, | ||
], | ||
error: ['info'], | ||
}; | ||
|
||
// Render the message | ||
Joomla.renderMessages(messages); | ||
|
||
// Scroll to page top | ||
window.scrollTo(0, 0); | ||
|
||
link.classList.add('danger'); | ||
for (let i = 0, len = linkSpan.length; i < len; i += 1) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND').replace('%s', `<span class="badge badge-light">${updateInfoList.length}</span>`); | ||
} | ||
} | ||
} else { | ||
// An error occurred | ||
link.classList.add('danger'); | ||
for (let i = 0, len = linkSpan.length; i < len; i += 1) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_ERROR'); | ||
} | ||
} | ||
}, | ||
onError: () => { | ||
// An error occurred | ||
const link = document.getElementById('plg_quickicon_extensionupdate'); | ||
const linkSpan = link.querySelectorAll('span.j-links-link'); | ||
link.classList.add('danger'); | ||
for (let i = 0, len = linkSpan.length; i < len; i += 1) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_ERROR'); | ||
} | ||
}, | ||
}); | ||
} | ||
}); | ||
})(); |
136 changes: 62 additions & 74 deletions
136
media/plg_quickicon_extensionupdate/js/extensionupdatecheck.js
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,86 +1,74 @@ | ||
/** | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION. | ||
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD. | ||
**/ | ||
|
||
/** | ||
* Ajax call to get the update status of the installed extensions | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
(function() { | ||
"use strict"; | ||
|
||
var checkForExtensionsUpdates = function() { | ||
|
||
if (Joomla.getOptions('js-extensions-update')) { | ||
|
||
var options = Joomla.getOptions('js-extensions-update'); | ||
Joomla.request( | ||
{ | ||
url: options.ajaxUrl + '&eid=0&skip=700', | ||
method: 'GET', | ||
data: '', | ||
perform: true, | ||
onSuccess: function(response, xhr) | ||
{ | ||
var link = document.getElementById('plg_quickicon_extensionupdate'), | ||
linkSpan = link.querySelectorAll('span.j-links-link'); | ||
|
||
var updateInfoList = JSON.parse(response); | ||
|
||
if (updateInfoList instanceof Array) { | ||
if (updateInfoList.length === 0) { | ||
/** No updates **/ | ||
link.classList.add('success'); | ||
for (var i = 0, len = linkSpan.length; i < len; i++) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPTODATE'); | ||
} | ||
} else { | ||
var messages = { | ||
"message": [ | ||
Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND_MESSAGE').replace("%s", '<span class="badge badge-light">' + updateInfoList.length + '</span>') | ||
+ '<button class="btn btn-primary" onclick="document.location=\'' + options.url + '\'">' | ||
+ Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND_BUTTON') + '</button>' | ||
], "error": ["info"] | ||
}; | ||
// Ajax call to get the update status of the installed extensions | ||
(function () { | ||
'use strict'; | ||
|
||
/** Render the message **/ | ||
Joomla.renderMessages(messages); | ||
// Add a listener on content loaded to initiate the check | ||
|
||
/** Scroll to page top **/ | ||
window.scrollTo(0, 0); | ||
document.addEventListener('DOMContentLoaded', function () { | ||
if (Joomla.getOptions('js-extensions-update')) { | ||
var options = Joomla.getOptions('js-extensions-update'); | ||
Joomla.request({ | ||
url: options.ajaxUrl + '&eid=0&skip=700', | ||
method: 'GET', | ||
data: '', | ||
perform: true, | ||
onSuccess: function onSuccess(response) { | ||
var link = document.getElementById('plg_quickicon_extensionupdate'); | ||
var linkSpan = link.querySelectorAll('span.j-links-link'); | ||
var updateInfoList = JSON.parse(response); | ||
|
||
link.classList.add('danger'); | ||
for (var i = 0, len = linkSpan.length; i < len; i++) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND').replace("%s", '<span class="badge badge-light">' + updateInfoList.length + '</span>'); | ||
} | ||
} | ||
} else { | ||
/** An error occurred **/ | ||
link.classList.add('danger'); | ||
for (var i = 0, len = linkSpan.length; i < len; i++) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_ERROR'); | ||
} | ||
} | ||
if (updateInfoList instanceof Array) { | ||
if (updateInfoList.length === 0) { | ||
// No updates | ||
link.classList.add('success'); | ||
for (var i = 0, len = linkSpan.length; i < len; i += 1) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPTODATE'); | ||
} | ||
} else { | ||
var messages = { | ||
message: [Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND_MESSAGE').replace('%s', '<span class="badge badge-light">' + updateInfoList.length + '</span>') + '<button class="btn btn-primary" onclick="document.location=\'' + options.url + '\'">' + Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND_BUTTON') + '</button>'], | ||
error: ['info'] | ||
}; | ||
|
||
}, | ||
onError: function(xhr) | ||
{ | ||
/** An error occurred **/ | ||
var link = document.getElementById('plg_quickicon_extensionupdate'), | ||
linkSpan = link.querySelectorAll('span.j-links-link'); | ||
// Render the message | ||
Joomla.renderMessages(messages); | ||
|
||
link.classList.add('danger'); | ||
for (var i = 0, len = linkSpan.length; i < len; i++) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_ERROR'); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
}; | ||
// Scroll to page top | ||
window.scrollTo(0, 0); | ||
|
||
/** Add a listener on content loaded to initiate the check **/ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
checkForExtensionsUpdates(); | ||
}); | ||
link.classList.add('danger'); | ||
for (var _i = 0, _len = linkSpan.length; _i < _len; _i += 1) { | ||
linkSpan[_i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_UPDATEFOUND').replace('%s', '<span class="badge badge-light">' + updateInfoList.length + '</span>'); | ||
} | ||
} | ||
} else { | ||
// An error occurred | ||
link.classList.add('danger'); | ||
for (var _i2 = 0, _len2 = linkSpan.length; _i2 < _len2; _i2 += 1) { | ||
linkSpan[_i2].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_ERROR'); | ||
} | ||
} | ||
}, | ||
onError: function onError() { | ||
// An error occurred | ||
var link = document.getElementById('plg_quickicon_extensionupdate'); | ||
var linkSpan = link.querySelectorAll('span.j-links-link'); | ||
link.classList.add('danger'); | ||
for (var i = 0, len = linkSpan.length; i < len; i += 1) { | ||
linkSpan[i].innerHTML = Joomla.JText._('PLG_QUICKICON_EXTENSIONUPDATE_ERROR'); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
})(); |