[DE mobile] Refactoring Edit Users

This commit is contained in:
Julia Svinareva 2019-05-31 15:42:36 +03:00
parent 0983f77969
commit 8abb5fde97

View file

@ -576,48 +576,43 @@ define([
}, },
initEditUsers: function() { initEditUsers: function() {
var templateUserItem = _.template([ var usersArray = [];
'<% _.each(users, function(item) { %>',
'<li id="<%= item.id %>" class="<% if (item.view) {%> viewmode <% } %> item-content">' +
'<div class="user-name item-inner">' +
'<div class="color" style="background-color: <%= item.color %>;"><%= item.initial %></div>'+
'<label><%= item.name %></label>' +
'<% if (item.len>1) { %><label class="length"> (<%= item.len %>)</label><% } %>' +
'</div>'+
'</li>',
'<% }); %>'
].join(''));
var users = [],
usersSort = [],
len;
_.each(editUsers, function(item){ _.each(editUsers, function(item){
var fio = item.userName.split(' '); var fio = item.asc_getUserName().split(' ');
var initials = fio[0].substring(0, 1).toUpperCase(); var initials = fio[0].substring(0, 1).toUpperCase();
if (fio.length > 1) { if (fio.length > 1) {
initials += fio[fio.length - 1].substring(0, 1).toUpperCase(); initials += fio[fio.length - 1].substring(0, 1).toUpperCase();
} }
users.push({color: item.asc_getColor(), id: item.id, idOriginal: item.idOriginal, name: item.userName, view: item.view, initial: initials}) if(!item.asc_getView()) {
}); usersArray.push({
_.each(users.filter(function (itm) {return !itm.view;}), function(item){ color: item.asc_getColor(),
if (usersSort.filter(function (itemFil) {return item.idOriginal === itemFil.idOriginal;}).length === 0) { id: item.asc_getId(),
len = users.filter(function (itemFil) { idOriginal: item.asc_getIdOriginal(),
return (item.idOriginal === itemFil.idOriginal && !itemFil.view); name: item.asc_getUserName(),
}).length; view: item.asc_getView(),
usersSort.push({color: item.color, id: item.id, idOriginal: item.idOriginal, name: item.name, view: item.view, len: len, initial: item.initial}) initial: initials
})
} }
}); });
var userSort = _.chain(usersArray).groupBy('idOriginal').value();
var templateUserItem = _.template([
'<% _.each(users, function (user) { %>',
'<li id="<%= user[0].id %>" class="<% if (user[0].view) {%> viewmode <% } %> item-content">' +
'<div class="user-name item-inner">' +
'<div class="color" style="background-color: <%= user[0].color %>;"><%= user[0].initial %></div>'+
'<label><%= user[0].name %></label>' +
'<% if (user.length>1) { %><label class="length"> (<%= user.length %>)</label><% } %>' +
'</div>'+
'</li>',
'<% }); %>'].join(''));
var templateUserList = _.template( var templateUserList = _.template(
'<div class="item-content"><div class="item-inner">' + '<div class="item-content"><div class="item-inner">' +
this.textEditUser + this.textEditUser +
'</div></div>' + '</div></div>' +
'<ul>' + '<ul>' +
templateUserItem(({users: usersSort})) + templateUserItem({users: userSort}) +
'</ul>'); '</ul>');
$('#user-list').html(templateUserList({ $('#user-list').html(templateUserList());
users: usersSort.filter(function (item) {
return !item.view;
}),
}));
}, },