|
|
|
@ -51,9 +51,22 @@ _
|
|
|
|
|
) {
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
init: function() {
|
|
|
|
|
var App = Backbone.Router.extend({
|
|
|
|
|
routes: {
|
|
|
|
|
"playlist": "_routerActionPlaylist"
|
|
|
|
|
, "servers/:server": "_routerActionClient"
|
|
|
|
|
, "playlist/:item": "_routerActionPlaylistItem"
|
|
|
|
|
, ":server/items/:item": "_routerActionServerItem"
|
|
|
|
|
//"*actions": "defaultRoute" // matches http://example.com/#anything-here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, initialize: function() {
|
|
|
|
|
_.bindAll(this
|
|
|
|
|
, "_routerActionPlaylist"
|
|
|
|
|
, "_routerActionClient"
|
|
|
|
|
, "_routerActionItem"
|
|
|
|
|
, "_routerActionServerItem"
|
|
|
|
|
|
|
|
|
|
, "_serverInit"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -65,39 +78,12 @@ _
|
|
|
|
|
// Setup underscore templates with mustache styles
|
|
|
|
|
_.templateSettings.interpolate = /\{\{(.+?)\}\}/g;
|
|
|
|
|
|
|
|
|
|
var Router = Backbone.Router.extend({
|
|
|
|
|
routes: {
|
|
|
|
|
"playlist": "_routerActionPlaylist"
|
|
|
|
|
, "servers": "_routerActionClient"
|
|
|
|
|
, "items/:id": "_routerActionItem"
|
|
|
|
|
, ":server/items/:id": "_routerActionServerItem"
|
|
|
|
|
//"*actions": "defaultRoute" // matches http://example.com/#anything-here
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.Router = new Router();
|
|
|
|
|
|
|
|
|
|
Backbone.history.start({
|
|
|
|
|
pushState: true
|
|
|
|
|
, root: "/"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.servers = new ServerCollection();
|
|
|
|
|
|
|
|
|
|
this.servers.on("add", function (server) {
|
|
|
|
|
server.save();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.servers.on("client:unauthorized", function __fnAppEventClientUnauthorized(event) {
|
|
|
|
|
var client = event.shift()
|
|
|
|
|
;
|
|
|
|
|
console.log(arguments);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.loadingStates = 0;
|
|
|
|
|
this.loadingModal = $(tmplModalLoading);
|
|
|
|
|
this.loadingTimeout = null;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function __asyncAppFetchServerCollection(callback) {
|
|
|
|
|
that.servers.fetch({
|
|
|
|
@ -143,6 +129,15 @@ _
|
|
|
|
|
$(event.target).remove();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Backbone.history.start({
|
|
|
|
|
pushState: true
|
|
|
|
|
, root: "/"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// For now let's reset the state when we start up
|
|
|
|
|
that.navigate("", false);
|
|
|
|
|
|
|
|
|
|
App.__super__.initialize.apply(that, that.routes);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
@ -153,10 +148,24 @@ _
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, _routerActionClient: function (hostname) {
|
|
|
|
|
var server = this.servers.get(hostname)
|
|
|
|
|
, client = server.client
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
if (client) {
|
|
|
|
|
if (client.sate < 4) {
|
|
|
|
|
client.on("inited", function __fnAppEventClientInitited(_client) {
|
|
|
|
|
_client.fetchDatabases(_client.fetchDatabase);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
client.init();
|
|
|
|
|
} else if (client.state === 4) {
|
|
|
|
|
client.fetchDatabases(client.fetchDatabase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, _routerActionItem: function (item) {
|
|
|
|
|
, _routerActionPlaylistItem: function (item) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -168,10 +177,14 @@ _
|
|
|
|
|
var that = this
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
that.loadingStates = 0;
|
|
|
|
|
that.loadingModal = $(tmplModalLoading);
|
|
|
|
|
that.loadingTimeout = null;
|
|
|
|
|
|
|
|
|
|
server.client.off("all");
|
|
|
|
|
|
|
|
|
|
server.client.on("state", function __fnAppEventClientStateChange(client, state) {
|
|
|
|
|
console.log(state);
|
|
|
|
|
if (state === ClientModel.defaults._states.loading) {
|
|
|
|
|
|
|
|
|
|
if (that.loadingStates === 0) {
|
|
|
|
|
that.loadingTimeout = setTimeout(function __fnAppTimeoutLoadingStat() {
|
|
|
|
|
that.loadingModal.modal();
|
|
|
|
@ -193,13 +206,49 @@ _
|
|
|
|
|
server.client.on("unauthorized", function __fnAppEventClientUnauthorized(client, xhr) {
|
|
|
|
|
var tmplHtml = _.template(tmplModalLogin)({ dmap_itemname: client.url() })
|
|
|
|
|
, $tmpl = $(tmplHtml)
|
|
|
|
|
, serverModel = that.servers.get(client.attributes.hostname)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
$tmpl.modal();
|
|
|
|
|
|
|
|
|
|
$tmpl.find("form").on("submit", function __fnAppEventModalLogin(event) {
|
|
|
|
|
var username = $(event.target).find("input[type='text']").val()
|
|
|
|
|
, password = $(event.target).find("input[type='password']").val()
|
|
|
|
|
, saveCredentials = $(event.target).find("input[type='checkbox']").is(':checked')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
client.setAuth(username, password);
|
|
|
|
|
|
|
|
|
|
if (saveCredentials) {
|
|
|
|
|
var newModel = (_.clone({}, serverModel.attributes, {username: username, password: password}));
|
|
|
|
|
console.log(newModel);
|
|
|
|
|
|
|
|
|
|
serverModel.set("username", username, {silent: true});
|
|
|
|
|
serverModel.set("password", password, {silent: true});
|
|
|
|
|
|
|
|
|
|
serverModel.save(newModel, {silence: true});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tmpl.modal("hide");
|
|
|
|
|
|
|
|
|
|
setTimeout(client.init, 250);
|
|
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$tmpl.delegate("input[type='checkbox']", "click", function __fnEventModalRemember(event) {
|
|
|
|
|
if (event.target.checked === true) {
|
|
|
|
|
if (!confirm("Using this feature will save the login and password locally in clear text, are you sure?")) {
|
|
|
|
|
event.target.checked = false;
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
server.client.init();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return App;
|
|
|
|
|
});
|
|
|
|
|