Permalink
Browse files

Implement room list

  • Loading branch information...
1 parent 24962d0 commit 6bd57447108099af08b5b5fd46b8d6ded8c3aa94 @remichaignon remichaignon committed Apr 20, 2012
View
152 js/gitchat.js
@@ -8,11 +8,13 @@
function Gitchat() {
- this.lang = "en";
- this.tplExtension = ".html";
- this.strExtension = ".strings";
+ this.lang = "en"
+ this.tplExtension = ".html"
+ this.strExtension = ".strings"
- this.doc = $(document);
+ this.isFirstVisit = true
+
+ this.doc = $(document)
this.staticData = {
"home/splash": {
@@ -21,42 +23,43 @@ function Gitchat() {
"home/room_list": {
"orgs": [
{
- "remichaignon": {
- "repos": [
- {
- "name":"remi.github.com"
- },
- {
- "name":"croissant"
- }
- ]
- },
- "baguetteapps": {
- "repos": [
- {
- "name":"partystream"
- },
- {
- "name":"gitchat"
- },
- {
- "name":"sendme"
- }
- ]
- },
- "simpleenergy": {
- "repos": [
- {
- "name":"web-app"
- },
- {
- "name":"iphone-app"
- },
- {
- "name":"android-app"
- }
- ]
- }
+ "name": "remichaignon",
+ "repos": [
+ {
+ "name":"remi.github.com"
+ },
+ {
+ "name":"croissant"
+ }
+ ]
+ },
+ {
+ "name": "baguetteapps",
+ "repos": [
+ {
+ "name":"partystream"
+ },
+ {
+ "name":"gitchat"
+ },
+ {
+ "name":"sendme"
+ }
+ ]
+ },
+ {
+ "name": "simpleenergy",
+ "repos": [
+ {
+ "name":"web-app"
+ },
+ {
+ "name":"iphone-app"
+ },
+ {
+ "name":"android-app"
+ }
+ ]
}
]
},
@@ -66,45 +69,55 @@ function Gitchat() {
"home/people_list": {},
"home/profile": {},
"home/search": {}
- };
+ }
- var that = this;
+ var that = this
this._init = function() {
- console.log("gitchat");
+ console.log("gitchat")
- that.loadAllTemplates();
- that.isSplash();
+ that.isSplash()
};
this.isSplash = function() {
- $(".gitchat").addClass("hidden");
- $(".splash").removeClass("hidden");
+ $(".gitchat").addClass("hidden")
+ $(".splash").removeClass("hidden")
+
+ that.loadAllTemplates(".splash")
that.doc.on(
"submit",
"#login-form",
function(element) {
- element.preventDefault();
- that.isGitchat();
- $(element).unbind();
+ element.preventDefault()
+ that.isGitchat()
+ $(element).unbind()
}
- );
+ )
};
this.isGitchat = function() {
- $(".gitchat").removeClass("hidden");
- $(".splash").addClass("hidden");
+ $(".gitchat").removeClass("hidden")
+ $(".splash").addClass("hidden")
+
+ that.loadAllTemplates(".gitchat ")
+
+ $(".gitchat .main").addClass("hidden")
+
+ if (that.isFirstVisit)
+ $(".gitchat .main.settings").removeClass("hidden")
+ else
+ $(".gitchat .main.chat").removeClass("hidden")
};
this.loadTemplate = function(element) {
if ("undefined" === typeof element)
- throw "Element not valid.";
+ throw "Element not valid."
- var zelement = $(element);
- var data = zelement.data();
+ var zelement = $(element)
+ var data = zelement.data()
if ("undefined" !== typeof data.tpl) {
- console.log("Template named: \"" + data.tpl + "\"");
+ console.log("Template named: \"" + data.tpl + "\"")
// Get template
$.get(
@@ -116,28 +129,31 @@ function Gitchat() {
"../../templates/" + data.tpl + "." + that.lang + that.strExtension,
function(strings) {
if (("undefined" !== typeof strings) && (strings !== "")) {
- console.log("Strings for \"" + data.tpl + "\" in \"" + that.lang + "\": " + strings);
- var page = Handlebars.compile(template);
+ console.log("Strings for \"" + data.tpl + "\" in \"" + that.lang + "\": " + strings)
+ var page = Handlebars.compile(template)
// DEBUG
- data = $.extend(data, that.staticData[data.tpl]);
+ data = $.extend(data, that.staticData[data.tpl])
+ console.log(data);
// DEBUG
- zelement.html(page($.extend(data, JSON.parse(strings))));
+ zelement.html(page($.extend(data, JSON.parse(strings))))
}
}
- );
+ )
}
}
- );
+ )
}
};
- this.loadAllTemplates = function() {
- $(".tpl").each(
+ this.loadAllTemplates = function(prefix) {
+ prefix = ("undefined" !== typeof prefix) ? prefix : ""
+
+ $(prefix + ".tpl").each(
function(index, element) {
- console.log("Template found in \"" + $(element).attr("class") + "\"");
- that.loadTemplate(element);
+ console.log("Template found in \"" + $(element).attr("class") + "\"")
+ that.loadTemplate(element)
}
);
};
- this._init();
+ this._init()
}
View
26 pages/home/index.html
@@ -13,27 +13,17 @@
<div class="tpl room_list" data-tpl="home/room_list"></div>
<div class="tpl search_input" data-tpl="home/search_input"></div>
</div>
- <div class="main">
- <div class="chat">
- <div class="tpl chat_header" data-tpl="home/chat_header"></div>
- <div class="tpl chat_log" data-tpl="home/chat_log"></div>
- <div class="tpl chat_input" data-tpl="home/chat_input"></div>
- </div>
- <div class="profile hidden"></div>
- <div class="settings hidden"></div>
- <div class="search hidden"></div>
+ <div class="chat main">
+ <div class="tpl chat_header" data-tpl="home/chat_header"></div>
+ <div class="tpl chat_log" data-tpl="home/chat_log"></div>
+ <div class="tpl chat_input" data-tpl="home/chat_input"></div>
</div>
+ <div class="profile main hidden"></div>
+ <div class="settings main hidden"></div>
+ <div class="search main hidden"></div>
<div class="tpl people_list side_menu" data-tpl="home/people_list"></div>
</div>
</div>
</body>
-<script>
-
-$(document).ready(
- function() {
- var gitchat = new Gitchat();
- }
-);
-
-</script>
+<script> $(document).ready( function() { var gitchat = new Gitchat() } ) </script>
</html>
View
2 styles/master.css
@@ -1 +1 @@
-.left{float:left}.right{float:right}.hidden{display:none}body{margin:0}.page{background-color:#eee}.page .gitchat .side_menu{width:33%}.page .gitchat .room_list{overflow-x:hidden;overflow-y:scroll}.page .gitchat .search{height:50px}.page .gitchat .people_list{overflow-x:hidden;overflow-y:scroll}.page .gitchat .chat .chat_header{height:80px}.page .gitchat .chat .chat_input{height:150px}
+.left{float:left}.right{float:right}.hidden{display:none}body{margin:0}.page{background-color:#eee}.page .gitchat .side_menu{width:33%}.page .gitchat .room_list{overflow-x:hidden;overflow-y:scroll}.page .gitchat .search_input{height:50px}.page .gitchat .people_list{overflow-x:hidden;overflow-y:scroll}.page .gitchat .chat .chat_header{height:80px}.page .gitchat .chat .chat_input{height:150px}
View
13 styles/master.less
@@ -26,7 +26,6 @@ body {
background-color:#eee;
.splash {
-
}
.gitchat {
@@ -38,7 +37,7 @@ body {
overflow-x:hidden;
overflow-y:scroll;
}
- .search {
+ .search_input {
height:50px;
}
@@ -47,16 +46,24 @@ body {
overflow-y:scroll;
}
+ .main {
+ }
+
.chat {
.chat_header {
height:80px;
}
.chat_log {
-
}
.chat_input {
height:150px;
}
}
+ .profile {
+ }
+ .settings {
+ }
+ .search {
+ }
}
}
View
4 templates/home/room_list.en.strings
@@ -1,4 +1,8 @@
{
"strings": {
+ "user":"User",
+ "settings":"Settings",
+ "unnamed_org":"unnamed organization",
+ "unnamed_repo":"unnamed repository"
}
}
View
13 templates/home/room_list.html
@@ -0,0 +1,13 @@
+<h2>{{#if user}}{{user}}{{else}}{{strings.user}}{{/if}} <em>{{strings.settings}}</em></h2>
+{{#if orgs}}
+ {{#each orgs}}
+ /{{#if name}}{{name}}{{else}}{{../../strings.unnamed_org}}{{/if}}
+ {{#if repos}}
+ {{#each repos}}
+ :{{#if name}}{{name}}{{else}}{{../../../../strings.unnamed_repo}}{{/if}}
+ {{/each}}
+ {{/if}}
+ {{/each}}
+{{else}}
+ Empty state
+{{/if}}
View
4 templates/home/splash.en.strings
@@ -1,8 +1,8 @@
{
"strings": {
"title":"Welcome to Gitchat!",
- "username-placeholder":"github username",
- "password-placeholder":"github password",
+ "username_placeholder":"github username",
+ "password_placeholder":"github password",
"button":"Let's chat!"
}
}
View
8 templates/home/splash.html
@@ -1,6 +1,6 @@
-<h1>{{#if strings.title}}{{strings.title}}{{else}}Welcome to Gitchat!{{/if}}</h1>
+<h1>{{strings.title}}</h1>
<form id="login-form">
- <input type="text" placeholder="{{#if strings.username-placeholder}}{{strings.username-placeholder}}{{else}}github username{{/if}}" name="username">
- <input type="password" placeholder="{{#if strings.password-placeholder}}{{strings.password-placeholder}}{{else}}github password{{/if}}" name="password">
- <button type="submit">{{#if strings.button}}{{strings.button}}{{else}}Let's chat!{{/if}}</button>
+ <input type="text" placeholder="{{strings.username_placeholder}}" name="username">
+ <input type="password" placeholder="{{strings.password_placeholder}}" name="password">
+ <button type="submit">{{strings.button}}</button>
</form>

0 comments on commit 6bd5744

Please sign in to comment.