This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($session): #784 - ajax requester, session module, more options
- Loading branch information
Ray Nicholus
committed
Dec 19, 2013
1 parent
2fe4b4f
commit 85585f3
Showing
8 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
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
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,62 @@ | ||
/*globals qq, XMLHttpRequest*/ | ||
/** | ||
* Thin module used to send GET requests to the server, expecting information about session | ||
* data used to initialize an uploader instance. | ||
* | ||
* @param spec Various options used to influence the associated request. | ||
* @constructor | ||
*/ | ||
qq.SessionAjaxRequester = function(spec) { | ||
"use strict"; | ||
|
||
var requester, | ||
options = { | ||
endpoint: null, | ||
customHeaders: {}, | ||
params: {}, | ||
cors: { | ||
expected: false, | ||
sendCredentials: false | ||
}, | ||
onComplete: function(response, success, xhrOrXdr) {}, | ||
log: function(str, level) {} | ||
}; | ||
|
||
qq.extend(options, spec); | ||
|
||
function onComplete(id, xhrOrXdr, isError) { | ||
var response = null; | ||
|
||
/* jshint eqnull:true */ | ||
if (xhrOrXdr.responseText != null) { | ||
response = qq.parseJson(xhrOrXdr.responseText); | ||
} | ||
|
||
options.onComplete(response, !isError, xhrOrXdr); | ||
} | ||
|
||
requester = new qq.AjaxRequester({ | ||
validMethods: ["GET"], | ||
method: "GET", | ||
endpointStore: { | ||
getEndpoint: function() { | ||
return options.endpoint; | ||
} | ||
}, | ||
customHeaders: options.customHeaders, | ||
log: options.log, | ||
onComplete: onComplete, | ||
cors: options.cors | ||
}); | ||
|
||
|
||
qq.extend(this, { | ||
queryServer: function() { | ||
options.log("Session query request."); | ||
|
||
requester.initTransport("sessionRefresh") | ||
.withParams(options.params) | ||
.send(); | ||
} | ||
}); | ||
}; |
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,62 @@ | ||
/* globals qq */ | ||
/** | ||
* Module used to control populating the initial list of files. | ||
* | ||
* @constructor | ||
*/ | ||
qq.Session = function(spec) { | ||
"use strict"; | ||
|
||
var options = { | ||
endpoint: null, | ||
params: {}, | ||
customHeaders: {}, | ||
cors: {}, | ||
log: function(message, level) {} | ||
}; | ||
|
||
qq.extend(options, spec, true); | ||
|
||
|
||
function isJsonResponseValid(response) { | ||
if (qq.isArray(response)) { | ||
return true; | ||
} | ||
|
||
options.log("Session response is not an array.", "error"); | ||
} | ||
|
||
function handleFileItems(fileItems, success, xhrOrXdr, promise) { | ||
success = isJsonResponseValid(fileItems); | ||
|
||
if (success) { | ||
qq.each(fileItems, function(idx, fileItem) { | ||
// TODO Create ID for the file item (need to abstract this out of the handlers) | ||
// TODO Need to delegate UUID, size, name retrieval out of handlers to uploadData module | ||
// TODO Populate UUID, size, name, delete endpoint, thumbnail url, delete params | ||
// TODO Add file item to uploadData module | ||
// TODO Ensure file item is rendered in UI mode w/ size, name, delete button, success indicator, preview | ||
}); | ||
} | ||
|
||
promise[success ? "success" : "failure"](fileItems, xhrOrXdr); | ||
} | ||
|
||
// Initiate a call to the server that will be used to populate the initial file list. | ||
// Returns a `qq.Promise`. | ||
this.refresh = function() { | ||
/*jshint indent:false */ | ||
var refreshEffort = new qq.Promise(), | ||
refreshCompleteCallback = function(response, success, xhrOrXdr) { | ||
handleFileItems(response, success, xhrOrXdr, refreshEffort); | ||
}, | ||
requsterOptions = qq.extend({}, options), | ||
requester = new qq.SessionAjaxRequester( | ||
qq.extend(requsterOptions, {onComplete: refreshCompleteCallback}) | ||
); | ||
|
||
requester.queryServer(); | ||
|
||
return refreshEffort; | ||
}; | ||
}; |
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
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
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
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
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