1
0
Fork 0

Ooooohh so silly :\

master
Matthieu Lalonde 12 years ago committed by xSmurf
parent f3146522fc
commit 6f0c2fada8

@ -1,3 +1,7 @@
<!--
- - Copyleft Matthieu Lalonde 2012 LGPL, no guarantee given.
- - This software includes other similarly licensed software in /resources/vendors, see there for licenses
-->
<!DOCTYPE html>
<html>
<head>

@ -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,35 +129,62 @@ _
$(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;
}
, _routerActionPlaylist: function () {
, _routerActionPlaylist: function () {
}
, _routerActionClient: function (hostname) {
, _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) {
}
, _routerActionServerItem: function (server, item) {
, _routerActionServerItem: function (server, item) {
}
, _serverInit: function(server) {
, _serverInit: function(server) {
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;
});

@ -88,7 +88,7 @@ require(
$.curCSS = $.css;
$("body").ready(function __fnAppRequireLoader(){
App.init();
window.App = new App();
});
}
);

@ -95,11 +95,11 @@ define([
this.setState("connecting");
console.debug("Fetching content types");
//console.debug("Fetching content types");
that.fetchContentTypes(function __fnClientCbFetchContentTypes(contentTypes) {
console.debug("Fetching server info");
//console.debug("Fetching server info");
that.fetchServerInfo(function __fnClientCbFetchServerInfo(serverInfo) {
console.debug("Fetching login");
//console.debug("Fetching login");
that.fetchLogin(function __fnClientCbFetchLogin(sessionInfo) {
// TODO: Here we need to request /update for the database version
//console.debug("Fetching databases info");

@ -186,7 +186,7 @@ _
console.log(item.client.collections);
}
*/
Backbone.Router.prototype.navigate("servers/" + item.id, false);
Backbone.Router.prototype.navigate("servers/" + item.id, true);
});
}

@ -1,22 +1,22 @@
<div class="modal" data-show="true" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-body" style="font-size: 1.2em">
<form>
<fieldset>
<legend>{{dmap_itemname}} login</legend>
<p>
<input type="text" class="input-large" placeholder="Login">
</p>
<p>
<input type="password" class="input-large" placeholder="Password">
</p>
<!--label class="checkbox">
<input type="checkbox"> Remember me
</label-->
</fieldset>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-mini" data-dismiss="modal" aria-hidden="true"><i class="icon-remove"></i>&nbsp;Cancel</button>
<button class="btn btn-mini btn-primary" data-dismiss="modal" aria-hidden="true"><i class="icon-ok"></i>&nbsp;Login</button>
</div>
<form action="javascript:void(0);">
<div class="modal-body" style="font-size: 1.2em">
<fieldset>
<legend>{{dmap_itemname}} login</legend>
<p>
<input type="text" class="input-large" placeholder="Login">
</p>
<p>
<input type="password" class="input-large" placeholder="Password">
</p>
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
</fieldset>
</div>
<div class="modal-footer">
<a class="btn btn-mini" data-dismiss="modal" aria-hidden="true"><i class="icon-remove"></i>&nbsp;Cancel</a>
<button class="btn btn-mini btn-primary" data-dismiss="action" aria-hidden="true"><i class="icon-ok"></i>&nbsp;Login</button>
</div>
</form>
</div>
Loading…
Cancel
Save