From edd00380cf3de8b13ff9fe76c0893c34b69b5859 Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Thu, 1 Nov 2012 20:22:19 -0400 Subject: [PATCH] Some more view events.... --- index.html | 6 +++-- resources/css/app.css | 6 ++++- resources/js/models/client.js | 44 ++++++++++++++++++++++++++++------- resources/js/views/sidebar.js | 37 ++++++++++++++++++++++++++++- 4 files changed, 81 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index e9bb0a2..094b25c 100644 --- a/index.html +++ b/index.html @@ -102,8 +102,10 @@
-
- +
+
+ +
diff --git a/resources/css/app.css b/resources/css/app.css index a982413..42c0742 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -382,10 +382,14 @@ div#wrapperPlayer { div#wrapperFooter, table.dataTable tr td, -table.dataTable tr th { +table.dataTable tr th, +div#wrapperSideBar, +div#wrapperPlayer { -webkit-user-select: none; + -ms-user-select: none; -moz-user-select: none; -khtml-user-select: none; + user-select: none; cursor: default; } diff --git a/resources/js/models/client.js b/resources/js/models/client.js index 2ba820d..3a8bf88 100644 --- a/resources/js/models/client.js +++ b/resources/js/models/client.js @@ -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: { diff --git a/resources/js/views/sidebar.js b/resources/js/views/sidebar.js index 73ed53c..1e5640a 100644 --- a/resources/js/views/sidebar.js +++ b/resources/js/views/sidebar.js @@ -159,6 +159,10 @@ _ } }); + item.on("client:state", function __fnSideBarViewEventClientState(event) { + that.changeServerItemState($item.find("span > i:first-child"), event); + }); + item.client.init(); $item.find("a.sidebar-list-action").on("click", function (model) { @@ -177,9 +181,40 @@ _ $item.on("dblclick", function (model) { return function __fnSideBarViewEventDblClickItem(event) { - + }; }(item)); } + + , changeServerItemState: function ($glyph, event) { + var newClass = "icon-folder-closed" + , client = event.shift() + , state = event.shift() + ; + + switch (state) { + case 2: + case 5: + newClass = "icon-loading"; + break; + case 3: + newClass = "icon-exclamation-sign"; + break; + case 4: + newClass = "icon-ok-sign"; + break; + case 6: + newClass = "icon-folder-open"; + break; + default: + case 0: + case 1: + newClass = "icon-folder-closed"; + break; + } + + $glyph.removeClass(); + $glyph.addClass(newClass); + } }); }); \ No newline at end of file