Created
April 14, 2011 20:01
-
-
Save 0x46616c6b/920351 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var badesk = { | |
register: false, | |
password: false, | |
username: false, | |
news: [], | |
schedule: false, | |
documents1: [], | |
documents2: [], | |
marks: false, | |
lastSynchronized: 0, | |
init: function() { | |
/* Load basic objects from storage, if available */ | |
if (store.get('register')) badesk.register = store.get('register'); | |
if (store.get('password')) badesk.password = store.get('password'); | |
if (store.get('username')) badesk.username = store.get('username'); | |
if (store.get('news')) badesk.news = store.get('news'); | |
if (store.get('schedule')) badesk.schedule = store.get('schedule'); | |
if (store.get('documents1')) badesk.documents1 = store.get('documents1'); | |
if (store.get('documents2')) badesk.documents1 = store.get('documents2'); | |
if (store.get('marks')) badesk.marks = store.get('marks'); | |
if (store.get('lastSynchronized')) badesk.lastSynchronized = store.get('lastSynchronized'); | |
if ( badesk.register && badesk.password ) { | |
console.log("You're logged in!"); | |
if ( badesk.news == false ) badesk.fetchContent("news"); | |
if ( badesk.username == false ) badesk.fetchContent("username"); | |
if ( badesk.marks == false ) badesk.fetchContent("marks"); | |
if ( badesk.schedule == false ) badesk.fetchContent("schedule"); | |
if ( badesk.documents1 == false ) badesk.fetchContent("documents1"); | |
if ( badesk.documents2 == false ) badesk.fetchContent("documents2"); | |
} | |
}, | |
fetchContent: function(type) { | |
console.log("Try to fetch the " + type); | |
if (type == "news") | |
fetchUrl = "http://www.badesk.semmelicious.de/badesk/contentgrabber.php?matrikel=" + badesk.register + "&password=" + badesk.password + "&c=news"; | |
else if (type == "schedule") | |
fetchUrl = "http://www.badesk.semmelicious.de/badesk/contentgrabber.php?matrikel=" + badesk.register + "&password=" + badesk.password + "&c=schedule"; | |
else if (type == "marks") | |
fetchUrl = "http://www.badesk.semmelicious.de/badesk/contentgrabber.php?matrikel=" + badesk.register + "&password=" + badesk.password + "&c=marks"; | |
else if (type == "username") | |
fetchUrl = "http://www.badesk.semmelicious.de/badesk/contentgrabber.php?matrikel=" + badesk.register + "&password=" + badesk.password + "&c=name"; | |
else if (type == "documents1") | |
fetchUrl = "http://www.badesk.semmelicious.de/badesk/contentgrabber.php?matrikel=" + badesk.register + "&password=" + badesk.password + "&c=documents1"; | |
else if (type == "documents2") | |
fetchUrl = "http://www.badesk.semmelicious.de/badesk/contentgrabber.php?matrikel=" + badesk.register + "&password=" + badesk.password + "&c=documents2"; | |
if ( fetchUrl ) { | |
jQuery.ajax({ | |
url: fetchUrl, | |
timeout: 10000, | |
error: function(jqXHR, textStatus, errorThrown) { | |
console.log("Error while trying fetch the " + type + " - " + errorThrown); | |
}, | |
success: function(data, textStatus, jqXHR) { | |
console.log("Successfully fetched the " + type); | |
//console.log("Result: " + data); | |
if (type == "news") { | |
news = jQuery.parseJSON(data); | |
jQuery(news).each(function(key, value) { | |
if (value != null) | |
badesk.news.push(value); | |
}); | |
store.set(type, badesk.news); | |
} else if (type == "schedule") { | |
badesk.schedule = data; | |
store.set(type, badesk.schedule); | |
} else if (type == "marks") { | |
badesk.marks = data; | |
store.set(type, badesk.marks); | |
} else if (type == "username") { | |
badesk.username = data; | |
store.set(type, badesk.username); | |
} else if (type == "documents1") { | |
documents = jQuery.parseJSON(data); | |
jQuery(documents).each(function(key, value) { | |
if (value != null) | |
badesk.documents1.push(value); | |
}); | |
store.set(type, badesk.documents1); | |
} else if (type == "documents2") { | |
documents = jQuery.parseJSON(data); | |
jQuery(documents).each(function(key, value) { | |
if (value != null) | |
badesk.documents2.push(value); | |
}); | |
store.set(type, badesk.documents2); | |
} | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment