Started adding implementation of client-side functionality.
- Changed ts_api:dispatch_user/3 to return information for the user currently, authenticated if a valid session id is presented and no username is presented. - Moved the generic styling of form > * elements to be specific to .bar > form. - Added jQuery U 1.8.0. - Created login dialog that will automatically load upon page load if the user is not logged in. - Added styling for jQuery UI login dialog. - Implemented login functionality on the client page. - Implemented functionality to load user and timeline records on the client side.
This commit is contained in:
82
www/js/ts.js
82
www/js/ts.js
@ -1,5 +1,48 @@
|
||||
function login(event) {
|
||||
$(document).ready(function(){
|
||||
|
||||
$("#login-dialog").dialog({
|
||||
autoOpen: false,
|
||||
height: 300,
|
||||
width: 300,
|
||||
modal: true,
|
||||
buttons: {
|
||||
Login: function(){login()}
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: "/ts_api/users/",
|
||||
type: "GET",
|
||||
error: function(jqXHR, textStatus, error) {
|
||||
$("#login-dialog").dialog("open"); },
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
loadUser(data.user.username); }});
|
||||
|
||||
})
|
||||
|
||||
var user = []
|
||||
var timelines = []
|
||||
var activeTimeline = []
|
||||
|
||||
function login() {
|
||||
var name = $("#login-name");
|
||||
var pwd = $("#login-password");
|
||||
|
||||
$.ajax({
|
||||
url: "/ts_api/login",
|
||||
processData: false,
|
||||
data: JSON.stringify({username: name.val(), password: pwd.val()}),
|
||||
type: "POST",
|
||||
error: function(jqXHR, textStatus, error) {
|
||||
var tips = $(".validate-tips");
|
||||
tips.text("Incorrect username/password combination.");
|
||||
tips.addClass("ui-state-error");
|
||||
tips.slideDown();
|
||||
},
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
loadUser(name.val());
|
||||
$("#login-dialog").dialog("close");
|
||||
}});
|
||||
}
|
||||
|
||||
function logout(event) {
|
||||
@ -7,6 +50,43 @@ function logout(event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function loadUser(username) {
|
||||
$.ajax({
|
||||
url: "/ts_api/app/user_summary/" + username,
|
||||
type: "GET",
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
user = data.user;
|
||||
timelines = data.timelines;
|
||||
$("#fullname").text(user.name);
|
||||
$("#username").text("- " + user.username);
|
||||
|
||||
// TODO: not working
|
||||
$("#fullname-input").text(user.name);
|
||||
$("#email-input").text(user.email);
|
||||
|
||||
activeTimeline = timelines[0];
|
||||
|
||||
$("#timeline-name").text(activeTimeline.timeline_id + " |");
|
||||
$("#timeline-desc").text(activeTimeline.description);
|
||||
|
||||
loadTimeline(user, activeTimeline)
|
||||
},
|
||||
error: function(jqXHR, textStatus, error) {
|
||||
alert("TODO: handle error for user load.")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadTimeline(user, timeline) {
|
||||
$.ajax({
|
||||
url: "/ts_api/entries/" + user.username + "/" + timeline.timeline_id,
|
||||
type: "GET",
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function toggleUserInfo(event) {
|
||||
$("#user-info").slideToggle("slow");
|
||||
event.preventDefault();
|
||||
|
Reference in New Issue
Block a user