Commit 6bb43155 authored by Thierry BUGEAT's avatar Thierry BUGEAT

Code refactoring. Add listeners classes.

parent 2b9dcdcc
......@@ -261,6 +261,12 @@
<script type="text/javascript" src="js/classes/MyFeeds/TinyTinyRss.class.js"></script>
<script type="text/javascript" src="js/classes/MyFeeds/AolReader.class.js"></script>
<script type="text/javascript" src="js/classes/MyFeeds/SimplePie.class.js"></script>
<script type="text/javascript" src="js/classes/MyListeners/SimplePie.class.js"></script>
<script type="text/javascript" src="js/classes/MyListeners/AolReader.class.js"></script>
<script type="text/javascript" src="js/classes/MyListeners/Feedly.class.js"></script>
<script type="text/javascript" src="js/classes/MyListeners/TheOldReader.class.js"></script>
<script type="text/javascript" src="js/classes/MyListeners/TinyTinyRss.class.js"></script>
<script type="text/javascript" src="js/gestures.js"></script>
<script type="text/javascript" src="js/app.js"></script>
......
This diff is collapsed.
......@@ -77,6 +77,11 @@ AolReader.prototype.setToken = function(token) {
}
}
/**
* Get AOL Reader token
* @param {null}
* @return {string} Token
*/
AolReader.prototype.getToken = function() {
_MyFeeds.log('AolReader.prototype.getToken()');
return this.aolreader.token;
......@@ -85,8 +90,7 @@ AolReader.prototype.getToken = function() {
/**
* @param {null}
* @return {CustomEvent} AolReader.login.done | AolReader.login.error
* */
*/
AolReader.prototype.login = function() {
var _url = _AolReader.aolreader.host_auth + '/auth/authorize' +
'?client_id=' + encodeURIComponent(_AolReader.aolreader.client_id) +
......@@ -163,8 +167,7 @@ AolReader.prototype._loginCallback = function(url) {
/**
* @param {null}
* @return {CustomEvent} AolReader.getSubscriptions.done | AolReader.getSubscriptions.error
* */
*/
AolReader.prototype.getSubscriptions = function () {
_MyFeeds.log('AolReader.prototype.getSubscriptions()');
......@@ -192,8 +195,7 @@ AolReader.prototype.getSubscriptions = function () {
* Use "refresh_token" to obtain a new "access_token"
* @param {null}
* @return {CustomEvent} AolReader.getNewToken.done | AolReader.getNewToken.error
* */
*/
AolReader.prototype.updateToken = function() {
_MyFeeds.log('AolReader.prototype.getNewToken()');
......@@ -232,8 +234,7 @@ AolReader.prototype.updateToken = function() {
/**
* @param {feedId} String Feed url
* @return {CustomEvent} AolReader.deleteSubscription.done | AolReader.deleteSubscription.error
* */
*/
AolReader.prototype.deleteSubscription = function (feedId) {
_MyFeeds.log('AolReader.prototype.deleteSubscription()', arguments);
......@@ -266,8 +267,7 @@ AolReader.prototype.deleteSubscription = function (feedId) {
* @param string url Url to load.
* @param object myParams You can retrieve this object in response.
*
* */
*/
AolReader.prototype.get = function (url, myParams) {
_MyFeeds.log('AolReader.prototype.get()', arguments);
......@@ -311,8 +311,7 @@ AolReader.prototype.get = function (url, myParams) {
* @param {string} params Url parameters.
* @param {string} callback.
*
* */
*/
AolReader.prototype.post = function (url, params, callback) {
_MyFeeds.log('AolReader.prototype.post()', arguments);
......
/**
* Copyright 2016 Thierry BUGEAT
*
* This file is part of myFeeds.
*
* myFeeds is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* myFeeds is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with myFeeds. If not, see <http://www.gnu.org/licenses/>.
*/
/* ================================= */
/* --- Listeners AolReader Class --- */
/* ================================= */
var MyListeners_AolReader = function() {
document.body.addEventListener('AolReader.login.done', function(response){
liveValues['login']['inProgress']['aolreader'] = true;
my.log(aolreader.getToken());
params.accounts.aolreader.logged = true;
_saveParams();
document.getElementById('aolreaderLogin').checked = true; // Enable settings checkbox
aolreader.getSubscriptions(); // CustomEvent AolReader.getSubscriptions.done, AolReader.getSubscriptions.error
});
document.body.addEventListener('AolReader.login.error', function(response){
my.log('CustomEvent : AolReader.login.error', arguments);
my.message('Aol Reader login error');
});
document.body.addEventListener('AolReader.getSubscriptions.done', function(response){
my.log('CustomEvent : AolReader.getSubscriptions.done');
var _subscriptions = response.detail.subscriptions;
var _feed = '';
var _newFeeds = [];
for (var i = 0; i < _subscriptions.length; i++) {
_feed = {
'url': _subscriptions[i].url,
'pulsations': params['feeds']['defaultPulsations'],
'account': 'aolreader',
'id': _subscriptions[i].id
};
_newFeeds.push(_feed);
}
addNewSubscriptions(_newFeeds);
sp.setFeedsSubscriptions(myFeedsSubscriptions);
if (liveValues['login']['inProgress']['aolreader'] == true ) {
liveValues['login']['inProgress']['aolreader'] = false;
loadFeeds();
}
my._save("subscriptions.aolreader.json", "application/json", JSON.stringify(myFeedsSubscriptions.aolreader)).then(function(results) {
my.log("Save file subscriptions.aolreader.json");
}).catch(function(error) {
my.error("ERROR saving file subscriptions.aolreader.json", error);
my.alert("ERROR saving file subscriptions.aolreader.json");
});
my._save("cache/aolreader/subscriptions.json", "application/json", JSON.stringify(_subscriptions)).then(function(results) {
my.log("Save file cache/aolreader/subscriptions.json");
}).catch(function(error) {
my.error("ERROR saving file cache/aolreader/subscriptions.json", error);
my.alert("ERROR saving file cache/aolreader/subscriptions.json");
});
});
document.body.addEventListener('AolReader.getSubscriptions.error', function(response) {
my.log('CustomEvent : AolReader.getSubscriptions.error', arguments);
my.alert(document.webL10n.get('aolreader-get-subscriptions-error') + JSON.stringify(response.detail.message));
});
}
/**
* Copyright 2016 Thierry BUGEAT
*
* This file is part of myFeeds.
*
* myFeeds is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* myFeeds is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with myFeeds. If not, see <http://www.gnu.org/licenses/>.
*/
/* ============================== */
/* --- Listeners Feedly Class --- */
/* ============================== */
var MyListeners_Feedly = function() {
document.body.addEventListener('Feedly.login.done', function(response){
liveValues['login']['inProgress']['feedly'] = true;
my.log(feedly.getToken());
params.accounts.feedly.logged = true;
_saveParams();
document.getElementById('feedlyLogin').checked = true; // Enable settings checkbox
feedly.getSubscriptions(); // CustomEvent Feedly.getSubscriptions.done, Feedly.getSubscriptions.error
});
document.body.addEventListener('Feedly.login.error', function(response){
my.log('CustomEvent : Feedly.login.error', arguments);
my.message('Feedly login error');
});
document.body.addEventListener('Feedly.getSubscriptions.done', function(response){
my.log('CustomEvent : Feedly.getSubscriptions.done');
var _subscriptions = response.detail;
var _feed = '';
var _newFeeds = [];
for (var i = 0; i < _subscriptions.length; i++) {
_feed = {
'url': _subscriptions[i].id.substr(5, _subscriptions[i].id.length),
'pulsations': params['feeds']['defaultPulsations'],
'account': 'feedly',
'id': _subscriptions[i].id
};
_newFeeds.push(_feed);
}
addNewSubscriptions(_newFeeds);
sp.setFeedsSubscriptions(myFeedsSubscriptions);
if (liveValues['login']['inProgress']['feedly'] == true ) {
liveValues['login']['inProgress']['feedly'] = false;
loadFeeds();
}
my._save("subscriptions.feedly.json", "application/json", JSON.stringify(myFeedsSubscriptions.feedly)).then(function(results) {
my.log("Save file subscriptions.feedly.json");
}).catch(function(error) {
my.error("ERROR saving file subscriptions.feedly.json", error);
my.alert("ERROR saving file subscriptions.feedly.json");
});
my._save("cache/feedly/subscriptions.json", "application/json", JSON.stringify(_subscriptions)).then(function(results) {
my.log("Save file cache/feedly/subscriptions.json");
}).catch(function(error) {
my.error("ERROR saving file cache/feedly/subscriptions.json", error);
my.alert("ERROR saving file cache/feedly/subscriptions.json");
});
});
document.body.addEventListener('Feedly.getSubscriptions.error', function(response) {
my.log('CustomEvent : Feedly.getSubscriptions.error', arguments);
my.alert(document.webL10n.get('feedly-get-subscriptions-error') + JSON.stringify(response.detail.message));
});
}
/**
* Copyright 2016 Thierry BUGEAT
*
* This file is part of myFeeds.
*
* myFeeds is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* myFeeds is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with myFeeds. If not, see <http://www.gnu.org/licenses/>.
*/
/* ================================= */
/* --- Listeners SimplePie Class --- */
/* ================================= */
var MyListeners_SimplePie = function() {
document.body.addEventListener('SimplePie.load.done', function(event){
liveValues.sync.nbFeedsLoaded++;
my.log('SimplePie.load.done '+liveValues.sync.nbFeedsLoaded+'/'+liveValues.sync.nbFeedsToLoad);
// Save feed as file
if (liveValues.network.status == 'online') {
my._save('cache/simplepie/feeds/' + event.detail._myParams.account + "/" + btoa(event.detail.feedUrl) + ".json", "application/json", JSON.stringify(event.detail)).then(function(results) {
my.log('SimplePie.load.done > Saving feed in cache ok : ' + event.detail.feedUrl + ' (' + event.detail._myParams.account + "/" + btoa(event.detail.feedUrl) + ')');
}).catch(function(error) {
my.error("ERROR saving feed in cache : " + event.detail.feedUrl + ' (' + event.detail._myParams.account + "/" + btoa(event.detail.feedUrl) + ') ' + error);
my.alert("ERROR saving feed in cache :\n" + event.detail.feedUrl);
});
}
// Add feed entries to array "unsortedEntries"
sp.addFeed(event.detail);
// Check if all feeds were loaded
// Percentage of loading ?
ui._loading(Math.round((100 * liveValues.sync.nbFeedsLoaded) / liveValues.sync.nbFeedsToLoad));
// ---
if (liveValues.sync.nbFeedsLoaded == liveValues.sync.nbFeedsToLoad) {
if (params.entries.nbDaysAgo == 0) {
dspEntries();
}
dspFeeds(sp.getFeeds());
updateFeedsPulsations();
}
if (liveValues.sync.nbFeedsLoaded >= liveValues.sync.nbFeedsToLoad) {
liveValues.sync.nbFeedsToLoad = 0;
liveValues.sync.nbFeedsLoaded = 0;
ui._loading(100); ui.echo("loading", "", "");
if (liveValues.network.status == 'online') {
ui._onclick(sync, 'enable');
}
}
// ---
}, true);
document.body.addEventListener('SimplePie.load.error', function(event){
liveValues.sync.nbFeedsLoaded++;
my.error('SimplePie.load.error '+liveValues.sync.nbFeedsLoaded+'/'+liveValues.sync.nbFeedsToLoad);
// Check if all feeds were loaded
my.error(event);
// Percentage of loading ?
ui._loading(Math.round((100 * liveValues.sync.nbFeedsLoaded) / liveValues.sync.nbFeedsToLoad));
// ---
if (liveValues.sync.nbFeedsLoaded == liveValues.sync.nbFeedsToLoad) {
if (params.entries.nbDaysAgo == 0) {
dspEntries();
}
dspFeeds(sp.getFeeds());
updateFeedsPulsations();
}
if (liveValues.sync.nbFeedsLoaded >= liveValues.sync.nbFeedsToLoad) {
liveValues.sync.nbFeedsToLoad = 0;
liveValues.sync.nbFeedsLoaded = 0;
ui._loading(100); ui.echo("loading", "", "");
if (liveValues.network.status == 'online') {
ui._onclick(sync, 'enable');
}
}
// ---
}, true);
document.body.addEventListener('SimplePie.isValidUrl.done', findFeedsDisplayResults, true);
document.body.addEventListener('SimplePie.isValidUrl.error', function(){
ui.echo("find-feeds", "Invalid URL", "");
}, true);
}
/**
* Copyright 2016 Thierry BUGEAT
*
* This file is part of myFeeds.
*
* myFeeds is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* myFeeds is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with myFeeds. If not, see <http://www.gnu.org/licenses/>.
*/
/* ==================================== */
/* --- Listeners TheOldReader Class --- */
/* ==================================== */
var MyListeners_TheOldReader = function() {
document.body.addEventListener('TheOldReader.login.done', function(response){
liveValues['login']['inProgress']['theoldreader'] = true;
my.log('TheOldReader.getToken()', theoldreader.getToken());
params.accounts.theoldreader.logged = true;
_saveParams();
document.getElementById('theoldreaderCheckbox').checked = true; // Enable settings checkbox
document.getElementById('theoldreaderForm').style.cssText = 'display: none';
theoldreader.getSubscriptions(); // CustomEvent TheOldReader.getSubscriptions.done, TheOldReader.getSubscriptions.error
});
document.body.addEventListener('TheOldReader.login.error', function(response){
my.log('CustomEvent : TheOldReader.login.error', arguments);
my.message('The Old Reader login error');
});
document.body.addEventListener('TheOldReader.getSubscriptions.done', function(response){
my.log('CustomEvent : TheOldReader.getSubscriptions.done', response);
var _subscriptions = response.detail.subscriptions;
var _feed = '';
var _newFeeds = [];
for (var i = 0; i < _subscriptions.length; i++) {
_feed = {
'url': _subscriptions[i].url,
'pulsations': params['feeds']['defaultPulsations'],
'account': 'theoldreader',
'id': _subscriptions[i].id
};
_newFeeds.push(_feed);
}
addNewSubscriptions(_newFeeds);
sp.setFeedsSubscriptions(myFeedsSubscriptions);
if (liveValues['login']['inProgress']['theoldreader'] == true ) {
liveValues['login']['inProgress']['theoldreader'] = false;
loadFeeds();
}
my._save("subscriptions.theoldreader.json", "application/json", JSON.stringify(myFeedsSubscriptions.theoldreader)).then(function(results) {
my.log("Save file subscriptions.theoldreader.json");
}).catch(function(error) {
my.error("ERROR saving file subscriptions.theoldreader.json", error);
my.alert("ERROR saving file subscriptions.theoldreader.json");
});
my._save("cache/theoldreader/subscriptions.json", "application/json", JSON.stringify(_subscriptions)).then(function(results) {
my.log("Save file cache/theoldreader/subscriptions.json");
}).catch(function(error) {
my.error("ERROR saving file cache/theoldreader/subscriptions.json", error);
my.alert("ERROR saving file cache/theoldreader/subscriptions.json");
});
});
document.body.addEventListener('TheOldReader.getSubscriptions.error', function(response) {
my.log('CustomEvent : TheOldReader.getSubscriptions.error', arguments);
my.alert(document.webL10n.get('theoldreader-get-subscriptions-error') + JSON.stringify(response.detail.message));
});
}
/**
* Copyright 2016 Thierry BUGEAT
*
* This file is part of myFeeds.
*
* myFeeds is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* myFeeds is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with myFeeds. If not, see <http://www.gnu.org/licenses/>.
*/
/* =================================== */
/* --- Listeners TinyTinyRss Class --- */
/* =================================== */
var MyListeners_TinyTinyRss = function() {
document.body.addEventListener('TinyTinyRss.login.done', function(response){
liveValues['login']['inProgress']['tinytinyrss'] = true;
my.log('TinyTinyRss.getToken()', tinytinyrss.getToken());
params.accounts.tinytinyrss.logged = true;
_saveParams();
document.getElementById('tinytinyrssCheckbox').checked = true; // Enable settings checkbox
document.getElementById('tinytinyrssForm').style.cssText = 'display: none';
tinytinyrss.getSubscriptions(); // CustomEvent TinyTinyRss.getSubscriptions.done, TinyTinyRss.getSubscriptions.error
});
document.body.addEventListener('TinyTinyRss.login.error', function(response){
my.log('CustomEvent : TinyTinyRss.login.error', arguments);
my.message('Tiny Tiny Rss login error');
});
document.body.addEventListener('TinyTinyRss.getSubscriptions.done', function(response){
my.log('CustomEvent : TinyTinyRss.getSubscriptions.done', response);
var _subscriptions = response.detail.content;
var _feed = '';
var _newFeeds = [];
for (var i = 0; i < _subscriptions.length; i++) {
_feed = {
'url': _subscriptions[i].feed_url,
'pulsations': params['feeds']['defaultPulsations'],
'account': 'tinytinyrss',
'id': _subscriptions[i].id
};
_newFeeds.push(_feed);
}
addNewSubscriptions(_newFeeds);
sp.setFeedsSubscriptions(myFeedsSubscriptions);
if (liveValues['login']['inProgress']['tinytinyrss'] == true ) {
liveValues['login']['inProgress']['tinytinyrss'] = false;
loadFeeds();
}
my._save("subscriptions.tinytinyrss.json", "application/json", JSON.stringify(myFeedsSubscriptions.tinytinyrss)).then(function(results) {
my.log("Save file subscriptions.tinytinyrss.json");
}).catch(function(error) {
my.error("ERROR saving file subscriptions.tinytinyrss.json", error);
my.alert("ERROR saving file subscriptions.tinytinyrss.json");
});
my._save("cache/tinytinyrss/subscriptions.json", "application/json", JSON.stringify(_subscriptions)).then(function(results) {
my.log("Save file cache/tinytinyrss/subscriptions.json");
}).catch(function(error) {
my.error("ERROR saving file cache/tinytinyrss/subscriptions.json", error);
my.alert("ERROR saving file cache/tinytinyrss/subscriptions.json");
});
});
document.body.addEventListener('TinyTinyRss.getSubscriptions.error', function(response) {
my.log('CustomEvent : TinyTinyRss.getSubscriptions.error', arguments);
my.alert(document.webL10n.get('tinytinyrss-get-subscriptions-error') + JSON.stringify(response.detail.message));
});
}
This diff is collapsed.
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