WIP javascript client

This commit is contained in:
John Woodlock
2012-06-26 22:31:30 +10:00
parent ca8b7b0abe
commit b91bbf1e01
+38 -5
View File
@@ -1,4 +1,4 @@
/*
queryParam = (function(){ queryParam = (function(){
var query = {}, pair, search = location.search.substring(1).split("&"), i = search.length; var query = {}, pair, search = location.search.substring(1).split("&"), i = search.length;
while (i--) { while (i--) {
@@ -7,6 +7,24 @@ queryParam = (function(){
} }
return query; return query;
})(); })();
*/
function executeAjaxRequest(url, verbType, jsonData, basicAuthKey, successFunction, errorFunction) {
var jqxhr = $.ajax({
url : url,
type : verbType, //POST, GET, PUT or DELETE
contentType : "application/json; charset=utf-8",
dataType : 'json',
data : jsonData,
cache : false,
beforeSend : function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + basicAuthKey);
},
success : successFunction,
error : errorFunction
});
}
function showILLogon(apiUrl, logonDivName) { function showILLogon(apiUrl, logonDivName) {
@@ -372,7 +390,7 @@ setClientListingContent("content");
//HOME list clients functionality //HOME list clients functionality
$("#tabs").tabs({ $("#tabs").tabs({
"ajaxOptions": { /* "ajaxOptions": {
type: 'GET', type: 'GET',
dataType: 'json', dataType: 'json',
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8',
@@ -386,7 +404,7 @@ setClientListingContent("content");
error: function(xhr, status, index, anchor) { error: function(xhr, status, index, anchor) {
$(anchor.hash).html("error occured while ajax loading."); $(anchor.hash).html("error occured while ajax loading.");
} }
}, },*/
select: function(event, ui) { select: function(event, ui) {
console.log("selected.."); console.log("selected..");
}, },
@@ -396,6 +414,22 @@ setClientListingContent("content");
show: function(event, ui) { show: function(event, ui) {
console.log("show.."); console.log("show..");
var successFunction = function(data) {
var clientObject = new Object();
clientObject.clients = data;
console.log(clientObject);
var tableHtml = $("#clientSearchTabTemplate").render(clientObject);
$("#searchtab").html(tableHtml);
};
var errorFunction = function(jqXHR, textStatus, errorThrown) {
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
};
executeAjaxRequest(baseApiUrl + 'clients', 'GET', "", base64, successFunction, errorFunction);
/*
var jqxhr = $.ajax({ var jqxhr = $.ajax({
url: baseApiUrl + 'clients', url: baseApiUrl + 'clients',
type: 'GET', type: 'GET',
@@ -412,13 +446,12 @@ setClientListingContent("content");
var tableHtml = $("#clientSearchTabTemplate").render(clientObject); var tableHtml = $("#clientSearchTabTemplate").render(clientObject);
$("#searchtab").html(tableHtml); $("#searchtab").html(tableHtml);
});
}, },
error: function(jqXHR, textStatus, errorThrown) { error: function(jqXHR, textStatus, errorThrown) {
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors"); handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
} }
}); });
*/
} }
}); });