|
|
|
@ -21,6 +21,8 @@ define([
|
|
|
|
|
constructor: function(attributes, options) {
|
|
|
|
|
_.bindAll(this
|
|
|
|
|
, "setAuth"
|
|
|
|
|
, "setState"
|
|
|
|
|
, "getState"
|
|
|
|
|
, "init"
|
|
|
|
|
, "deinit"
|
|
|
|
|
, "logout"
|
|
|
|
@ -69,10 +71,30 @@ define([
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, init: function () {
|
|
|
|
|
, setState: function (state) {
|
|
|
|
|
if (_.isNumber(state)) {
|
|
|
|
|
this.trigger("state", this, state);
|
|
|
|
|
|
|
|
|
|
return this.state = state;
|
|
|
|
|
} else if (_.isString(state) && !_.isUndefined(this._states[state])) {
|
|
|
|
|
this.trigger("state", this, this._states[state]);
|
|
|
|
|
|
|
|
|
|
return this.state = this._states[state];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, getState: function () {
|
|
|
|
|
return this.state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, init: function () {
|
|
|
|
|
var that = this
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
this.setState("connecting");
|
|
|
|
|
|
|
|
|
|
console.debug("Fetching content types");
|
|
|
|
|
that.fetchContentTypes(function __fnClientCbFetchContentTypes(contentTypes) {
|
|
|
|
|
console.debug("Fetching server info");
|
|
|
|
@ -94,6 +116,7 @@ define([
|
|
|
|
|
//that.fetchArtists(function () {
|
|
|
|
|
//console.debug("Fetching albums of db 1");
|
|
|
|
|
//that.fetchAlbums(function () {
|
|
|
|
|
that.setState("connected");
|
|
|
|
|
that.trigger("inited", serverInfo);
|
|
|
|
|
//});
|
|
|
|
|
//});
|
|
|
|
@ -157,7 +180,7 @@ define([
|
|
|
|
|
|
|
|
|
|
uri += prefix + "session-id=" + this.collections.session.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.attributes.protocol + "://" + this.urlHost() + uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -195,11 +218,15 @@ define([
|
|
|
|
|
try {
|
|
|
|
|
xhr.onerror = function () {console.log("Error", arguments, this);};
|
|
|
|
|
xhr.onabort = function () {console.log("Abort", arguments, this);};
|
|
|
|
|
xhr.ontimeout = function () {console.log("Timeout", arguments, this);};
|
|
|
|
|
xhr.ontimeout = function () {
|
|
|
|
|
that.setState("timedout");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
xhr.onload = function (e) {
|
|
|
|
|
if (this.status === 200) {
|
|
|
|
|
callback(null, this.response);
|
|
|
|
|
} else if (this.status === 401) {
|
|
|
|
|
that.setState("unauthorized");
|
|
|
|
|
that.trigger("unauthorized", [this, e]);
|
|
|
|
|
} else {
|
|
|
|
|
callback(e.status);
|
|
|
|
@ -428,15 +455,16 @@ define([
|
|
|
|
|
, password: ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, status: 0
|
|
|
|
|
, state: 0
|
|
|
|
|
|
|
|
|
|
, statusCodes: {
|
|
|
|
|
, _states: {
|
|
|
|
|
disconnected: 0
|
|
|
|
|
, connecting: 1
|
|
|
|
|
, timedout: 2
|
|
|
|
|
, timedout: 1
|
|
|
|
|
, connecting: 2
|
|
|
|
|
, unauthorized: 3
|
|
|
|
|
, connected: 4
|
|
|
|
|
, loaded: 5
|
|
|
|
|
, loading: 5
|
|
|
|
|
, loaded: 6
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, collections: {
|
|
|
|
|