move logic into models, attempt at sorting

This commit is contained in:
Tor Hveem 2013-10-27 00:26:17 +02:00
parent 57b8a7a146
commit 902f344d25
3 changed files with 45 additions and 22 deletions

View file

@ -225,8 +225,8 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
</div>
<div id="bufferlines" ng-class="{'withnicklist': nonicklist==false}">
<div id="nicklist" ng-hide="nonicklist" class="vertical-line-left">
<ul class="nicklistgroup list-unstyled" ng-repeat="group in activeBuffer().nicklist | toArray">
<li class="" ng-repeat="nick in group.nicks">
<ul class="nicklistgroup list-unstyled" ng-repeat="group in activeBuffer().nicklist">
<li class="" ng-repeat="nick in group.nicks|orderBy:'nick.name'">
<a ng-click="nickAction(nick)"><span ng-class="nick.prefix_color">{{nick.prefix}}</span><span ng-class="color">{{nick.name}}</span></a>
</li>
</ul>

View file

@ -42,8 +42,37 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
/*
* Adds a nick to nicklist
*/
var addNick = function(nick) {
var addNick = function(group, nick) {
nicklist[group].nicks.push(nick);
}
/*
* Deletes a nick from nicklist
*/
var delNick = function(group, nick) {
var group = nicklist[group];
group.nicks = _.filter(group.nicks, function(n) { return n.name != nick.name});
/*
for(i in group.nicks) {
if(group.nicks[i].name == nick.name) {
delete group.nicks[i];
break;
}
}
*/
}
/*
* Updates a nick in nicklist
*/
var updateNick = function(group, nick) {
var group = nicklist[group];
for(i in group.nicks) {
if(group.nicks[i].name == nick.name) {
group.nicks[i] = nick;
break;
}
}
}
return {
id: pointer,
@ -58,7 +87,10 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
notification: notification,
localvars: local_variables,
notify: notify,
nicklist: nicklist
nicklist: nicklist,
addNick: addNick,
delNick: delNick,
updateNick: updateNick
}
}

View file

@ -142,30 +142,21 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
var buffer = models.getBuffer(n.pointers[0]);
var d = n['_diff'];
if(n.group == 1) {
group = buffer.nicklist[n.name];
group = n.name;
if(group==undefined) {
var g = new models.NickGroup(n);
buffer.nicklist[group] = g;
group = buffer.nicklist[g.name];
group = g.name;
}
}
if(d == 43) { // +
else {
var nick = new models.Nick(n);
group.nicks.push(nick);
}else if (d == 45) { // -
for(i in group.nicks) {
if(group.nicks[i].name == n.name) {
delete group.nicks[i];
break;
}
}
}else if (d == 42) { // *
var nick = new models.Nick(n);
for(i in group.nicks) {
if(group.nicks[i].name == n.name) {
group.nicks[i] = n;
break;
}
if(d == 43) { // +
buffer.addNick(group, nick);
}else if (d == 45) { // -
buffer.delNick(group, nick);
}else if (d == 42) { // *
buffer.updateNick(group, nick);
}
}
});