2014-03-09 21:22:37 +00:00
|
|
|
var irc = require("irc");
|
2014-03-07 21:24:02 +00:00
|
|
|
var Backbone = require("backbone");
|
2014-03-06 23:17:08 +00:00
|
|
|
var moment = require("moment");
|
2014-03-06 18:02:43 +00:00
|
|
|
|
2014-03-07 21:24:02 +00:00
|
|
|
var models =
|
|
|
|
module.exports =
|
|
|
|
{};
|
|
|
|
|
2014-03-07 03:18:53 +00:00
|
|
|
var id = 1;
|
2014-03-06 15:11:25 +00:00
|
|
|
|
2014-03-07 21:24:02 +00:00
|
|
|
models.User = Backbone.Model.extend({
|
|
|
|
defaults: {
|
|
|
|
mode: "",
|
|
|
|
name: "user"
|
|
|
|
}
|
|
|
|
});
|
2014-03-06 15:11:25 +00:00
|
|
|
|
2014-03-09 21:22:37 +00:00
|
|
|
models.UserCollection = Backbone.Collection.extend({
|
|
|
|
model: models.User
|
|
|
|
});
|
|
|
|
|
2014-03-07 21:24:02 +00:00
|
|
|
models.Message = Backbone.Model.extend({
|
|
|
|
defaults: {
|
|
|
|
time: moment().format("HH:mm"),
|
2014-03-09 21:22:37 +00:00
|
|
|
user: "",
|
|
|
|
text: ""
|
2014-03-07 21:24:02 +00:00
|
|
|
}
|
|
|
|
});
|
2014-03-06 18:02:43 +00:00
|
|
|
|
2014-03-09 21:22:37 +00:00
|
|
|
models.MessageCollection = Backbone.Collection.extend({
|
|
|
|
model: models.Message
|
|
|
|
});
|
|
|
|
|
2014-03-07 21:24:02 +00:00
|
|
|
models.Channel = Backbone.Model.extend({
|
|
|
|
defaults: {
|
2014-03-06 22:36:56 +00:00
|
|
|
type: "channel",
|
2014-03-07 21:24:02 +00:00
|
|
|
name: "",
|
2014-03-09 21:22:37 +00:00
|
|
|
topic: ""
|
2014-03-07 21:24:02 +00:00
|
|
|
},
|
|
|
|
initialize: function() {
|
|
|
|
this.set({
|
2014-03-09 21:22:37 +00:00
|
|
|
id: id++,
|
|
|
|
users: new models.UserCollection(),
|
|
|
|
messages: new models.MessageCollection()
|
2014-03-07 21:24:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-03-06 15:11:25 +00:00
|
|
|
|
2014-03-07 21:24:02 +00:00
|
|
|
models.ChannelCollection = Backbone.Collection.extend({
|
|
|
|
model: models.Channel
|
|
|
|
});
|
2014-03-06 15:11:25 +00:00
|
|
|
|
2014-03-07 21:24:02 +00:00
|
|
|
models.Network = Backbone.Model.extend({
|
|
|
|
defaults: {
|
|
|
|
host: "",
|
2014-03-09 21:22:37 +00:00
|
|
|
nick: "default_username",
|
|
|
|
connect: false
|
2014-03-07 21:24:02 +00:00
|
|
|
},
|
|
|
|
initialize: function() {
|
|
|
|
this.set({
|
|
|
|
id: id++,
|
|
|
|
channels: new models.ChannelCollection()
|
|
|
|
});
|
2014-03-09 21:22:37 +00:00
|
|
|
if (this.get("connect")) {
|
|
|
|
this.conn = new irc.Client(
|
|
|
|
this.get("host"),
|
|
|
|
this.get("nick"), {
|
|
|
|
channels: ["#testchan"]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2014-03-07 21:24:02 +00:00
|
|
|
this.get("channels").add(new models.Channel({
|
|
|
|
type: "network",
|
|
|
|
name: this.get("host")
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
2014-03-07 03:18:53 +00:00
|
|
|
|
2014-03-07 21:24:02 +00:00
|
|
|
models.NetworkCollection = Backbone.Collection.extend({
|
|
|
|
model: models.Network,
|
|
|
|
initialize: function() {
|
|
|
|
this.add(new models.Network({
|
|
|
|
host: "Lobby"
|
|
|
|
}));
|
2014-03-09 19:27:44 +00:00
|
|
|
},
|
2014-03-09 21:22:37 +00:00
|
|
|
find: function(id) {
|
2014-03-09 19:27:44 +00:00
|
|
|
var networks = this.models;
|
|
|
|
for (var i = 0; i < networks.length; i++) {
|
|
|
|
var find = networks[i].get("channels").findWhere({id: id});
|
|
|
|
if (find) {
|
2014-03-09 21:22:37 +00:00
|
|
|
return {
|
|
|
|
network: networks[i],
|
|
|
|
channel: find
|
|
|
|
};
|
2014-03-09 19:27:44 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-07 21:24:02 +00:00
|
|
|
}
|
|
|
|
});
|