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>
<div id="bufferlines" ng-class="{'withnicklist': nonicklist==false}"> <div id="bufferlines" ng-class="{'withnicklist': nonicklist==false}">
<div id="nicklist" ng-hide="nonicklist" class="vertical-line-left"> <div id="nicklist" ng-hide="nonicklist" class="vertical-line-left">
<ul class="nicklistgroup list-unstyled" ng-repeat="group in activeBuffer().nicklist | toArray"> <ul class="nicklistgroup list-unstyled" ng-repeat="group in activeBuffer().nicklist">
<li class="" ng-repeat="nick in group.nicks"> <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> <a ng-click="nickAction(nick)"><span ng-class="nick.prefix_color">{{nick.prefix}}</span><span ng-class="color">{{nick.name}}</span></a>
</li> </li>
</ul> </ul>

View file

@ -42,8 +42,37 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
/* /*
* Adds a nick to nicklist * 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 { return {
id: pointer, id: pointer,
@ -58,7 +87,10 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
notification: notification, notification: notification,
localvars: local_variables, localvars: local_variables,
notify: notify, 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 buffer = models.getBuffer(n.pointers[0]);
var d = n['_diff']; var d = n['_diff'];
if(n.group == 1) { if(n.group == 1) {
group = buffer.nicklist[n.name]; group = n.name;
if(group==undefined) { if(group==undefined) {
var g = new models.NickGroup(n); var g = new models.NickGroup(n);
buffer.nicklist[group] = g; buffer.nicklist[group] = g;
group = buffer.nicklist[g.name]; group = g.name;
} }
} }
else {
var nick = new models.Nick(n);
if(d == 43) { // + if(d == 43) { // +
var nick = new models.Nick(n); buffer.addNick(group, nick);
group.nicks.push(nick);
}else if (d == 45) { // - }else if (d == 45) { // -
for(i in group.nicks) { buffer.delNick(group, nick);
if(group.nicks[i].name == n.name) {
delete group.nicks[i];
break;
}
}
}else if (d == 42) { // * }else if (d == 42) { // *
var nick = new models.Nick(n); buffer.updateNick(group, nick);
for(i in group.nicks) {
if(group.nicks[i].name == n.name) {
group.nicks[i] = n;
break;
}
} }
} }
}); });