2014-02-19 07:44:18 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014, Raghu Nayyar <beingminimal@gmail.com>
|
2014-03-06 07:05:44 +00:00
|
|
|
* Copyright (c) 2014, Arthur Schiwon <blizzz@owncloud.com>
|
2014-02-19 07:44:18 +00:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var GroupList = {
|
2014-04-14 22:13:23 +00:00
|
|
|
addGroup: function(gid, usercount) {
|
|
|
|
if(usercount === undefined || usercount === 0) {
|
|
|
|
usercount = '';
|
|
|
|
}
|
2014-02-25 14:22:20 +00:00
|
|
|
var li = $('li[data-gid]').last().clone();
|
|
|
|
var ul = $('li[data-gid]').first().parent();
|
|
|
|
li.attr('data-gid', gid);
|
2014-04-14 22:13:23 +00:00
|
|
|
li.attr('data-usercount', usercount);
|
2014-02-25 14:22:20 +00:00
|
|
|
li.find('a span').first().text(gid);
|
2014-04-14 22:13:23 +00:00
|
|
|
li.find('span[class=usercount]').first().text(usercount);
|
2014-02-25 14:22:20 +00:00
|
|
|
|
|
|
|
$(li).appendTo(ul);
|
|
|
|
|
|
|
|
GroupList.sortGroups(0);
|
2014-04-14 22:13:23 +00:00
|
|
|
|
|
|
|
return li;
|
2014-02-25 14:22:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortGroups: function(usercount) {
|
|
|
|
var lis = $('li[data-gid]').filterAttr('data-usercount', usercount.toString()).get();
|
|
|
|
var ul = $(lis).first().parent();
|
|
|
|
|
|
|
|
lis.sort(function(a, b) {
|
|
|
|
return UserList.alphanum($(a).find('a span').text(), $(b).find('a span').text());
|
|
|
|
});
|
|
|
|
|
|
|
|
var items = [];
|
|
|
|
$.each(lis, function(index, li) {
|
|
|
|
items.push(li);
|
|
|
|
if(items.length === 100) {
|
|
|
|
$(ul).append(items);
|
|
|
|
items = [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(items.length > 0) {
|
|
|
|
$(ul).append(items);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
createGroup: function(groupname) {
|
|
|
|
$.post(
|
|
|
|
OC.filePath('settings', 'ajax', 'creategroup.php'),
|
|
|
|
{
|
|
|
|
groupname : groupname
|
|
|
|
},
|
|
|
|
function (result) {
|
|
|
|
if (result.status !== 'success') {
|
|
|
|
OC.dialogs.alert(result.data.message,
|
|
|
|
t('settings', 'Error creating group'));
|
|
|
|
} else {
|
|
|
|
if (result.data.groupname) {
|
|
|
|
var addedGroups = result.data.groupname;
|
|
|
|
UserList.availableGroups = $.unique($.merge(UserList.availableGroups, addedGroups));
|
|
|
|
GroupList.addGroup(result.data.groupname);
|
2014-03-06 07:57:29 +00:00
|
|
|
|
|
|
|
$('#newusergroups').children().first().attr('value', result.data.groupname);
|
|
|
|
$('#newusergroups').children().first().text(result.data.groupname);
|
|
|
|
|
|
|
|
$('.groupsselect').each( function (index, element) {
|
|
|
|
$(element).children().first().attr('value', result.data.groupname);
|
|
|
|
$(element).children().first().text(result.data.groupname);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.subadminsselect').each( function (index, element) {
|
|
|
|
$(element).children().first().attr('value', result.data.groupname);
|
|
|
|
$(element).children().first().text(result.data.groupname);
|
|
|
|
});
|
2014-02-25 14:22:20 +00:00
|
|
|
}
|
|
|
|
GroupList.toggleAddGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
2014-02-19 07:44:18 +00:00
|
|
|
|
2014-04-14 22:13:23 +00:00
|
|
|
update: function() {
|
|
|
|
if (GroupList.updating) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GroupList.updating = true;
|
|
|
|
pattern = filter.getPattern();
|
|
|
|
var query = $.param({ pattern: pattern });
|
|
|
|
$.get(OC.generateUrl('/settings/ajax/grouplist') + '?' + query, function (result) {
|
|
|
|
var lis = [];
|
|
|
|
if (result.status === 'success') {
|
|
|
|
$.each(result.data, function (i, subset) {
|
|
|
|
$.each(subset, function (index, group) {
|
|
|
|
if($('li[data-gid="' + group.name + '"]').length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
var li = GroupList.addGroup(group.name, group.usercount);
|
|
|
|
li.addClass('appear transparent');
|
|
|
|
lis.push(li);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (result.data.length > 0) {
|
|
|
|
GroupList.doSort();
|
|
|
|
} else {
|
|
|
|
GroupList.noMoreEntries = true;
|
|
|
|
}
|
|
|
|
setTimeout(function() {
|
|
|
|
for (var i = 0; i < lis.length; i++) {
|
|
|
|
lis[i].removeClass('transparent');
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
GroupList.updating = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-02-25 14:41:03 +00:00
|
|
|
elementBelongsToAddGroup: function(el) {
|
|
|
|
return !(el !== $('#newgroup-form').get(0)
|
|
|
|
&& $('#newgroup-form').find($(el)).length === 0);
|
|
|
|
},
|
|
|
|
|
2014-02-25 15:11:20 +00:00
|
|
|
hasAddGroupNameText: function() {
|
|
|
|
name = $('#newgroupname').val();
|
|
|
|
if($.trim(name) === '') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2014-02-19 10:40:07 +00:00
|
|
|
showGroup: function (gid) {
|
|
|
|
UserList.empty();
|
|
|
|
UserList.update(gid);
|
2014-02-20 18:11:52 +00:00
|
|
|
$('#app-navigation li').removeClass('active');
|
|
|
|
if(gid !== undefined) {
|
|
|
|
//TODO: treat Everyone properly
|
|
|
|
$('#app-navigation li').filterAttr('data-gid', gid).addClass('active');
|
|
|
|
}
|
2014-02-19 10:40:07 +00:00
|
|
|
},
|
|
|
|
|
2014-02-25 14:41:03 +00:00
|
|
|
isAddGroupButtonVisible: function() {
|
|
|
|
return $('#newgroup-init').is(":visible");
|
|
|
|
},
|
|
|
|
|
2014-02-25 13:26:35 +00:00
|
|
|
toggleAddGroup: function(event) {
|
2014-02-25 14:41:03 +00:00
|
|
|
if(GroupList.isAddGroupButtonVisible()) {
|
2014-02-25 13:26:35 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
$('#newgroup-form').show();
|
|
|
|
$('#newgroup-init').hide();
|
|
|
|
$('#newgroupname').focus();
|
|
|
|
} else {
|
|
|
|
$('#newgroup-form').hide();
|
|
|
|
$('#newgroup-init').show();
|
|
|
|
$('#newgroupname').val('');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-25 14:22:20 +00:00
|
|
|
isGroupNameValid: function(groupname) {
|
|
|
|
if ($.trim(groupname) === '') {
|
|
|
|
OC.dialogs.alert(
|
|
|
|
t('settings', 'A valid groupname must be provided'),
|
|
|
|
t('settings', 'Error creating group'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2014-02-26 17:04:55 +00:00
|
|
|
hide: function(gid) {
|
|
|
|
$('li[data-gid="' + gid + '"]').hide();
|
|
|
|
},
|
|
|
|
show: function(gid) {
|
|
|
|
$('li[data-gid="' + gid + '"]').show();
|
|
|
|
},
|
|
|
|
remove: function(gid) {
|
|
|
|
$('li').filterAttr('data-gid', gid).remove();
|
|
|
|
},
|
2014-04-14 22:13:23 +00:00
|
|
|
empty: function() {
|
|
|
|
$('li:not([data-gid=""])').remove();
|
|
|
|
},
|
2014-02-26 17:04:55 +00:00
|
|
|
initDeleteHandling: function() {
|
|
|
|
//set up handler
|
|
|
|
GroupDeleteHandler = new DeleteHandler('removegroup.php', 'groupname',
|
2014-03-06 07:57:29 +00:00
|
|
|
GroupList.hide, GroupList.remove);
|
2014-02-26 17:04:55 +00:00
|
|
|
|
|
|
|
//configure undo
|
|
|
|
OC.Notification.hide();
|
|
|
|
msg = t('settings', 'deleted') + ' %oid <span class="undo">' +
|
|
|
|
t('settings', 'undo') + '</span>';
|
|
|
|
GroupDeleteHandler.setNotification(OC.Notification, 'deletegroup', msg,
|
|
|
|
GroupList.show);
|
|
|
|
|
|
|
|
//when to mark user for delete
|
|
|
|
$('ul').on('click', 'span.utils>a', function (event) {
|
|
|
|
// Call function for handling delete/undo
|
|
|
|
gid = $(this).parent().parent().attr('data-gid');
|
|
|
|
GroupDeleteHandler.mark(gid);
|
|
|
|
});
|
2014-02-19 07:44:18 +00:00
|
|
|
|
2014-02-26 17:04:55 +00:00
|
|
|
console.log('init del groups');
|
|
|
|
//delete a marked user when leaving the page
|
|
|
|
$(window).on('beforeunload', function () {
|
|
|
|
GroupDeleteHandler.delete();
|
|
|
|
});
|
2014-02-19 07:44:18 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready( function () {
|
2014-02-26 17:04:55 +00:00
|
|
|
GroupList.initDeleteHandling();
|
2014-02-25 10:09:01 +00:00
|
|
|
|
|
|
|
// Display or hide of Create Group List Element
|
|
|
|
$('#newgroup-form').hide();
|
|
|
|
$('#newgroup-init').on('click', function (e) {
|
2014-02-25 13:26:35 +00:00
|
|
|
GroupList.toggleAddGroup(e);
|
2014-02-25 10:09:01 +00:00
|
|
|
});
|
|
|
|
|
2014-02-25 14:41:03 +00:00
|
|
|
$(document).on('click keydown keyup', function(event) {
|
|
|
|
if(!GroupList.isAddGroupButtonVisible()
|
2014-02-25 15:11:20 +00:00
|
|
|
&& !GroupList.elementBelongsToAddGroup(event.target)
|
|
|
|
&& !GroupList.hasAddGroupNameText()) {
|
2014-02-25 14:41:03 +00:00
|
|
|
GroupList.toggleAddGroup();
|
|
|
|
}
|
|
|
|
// Escape
|
|
|
|
if(!GroupList.isAddGroupButtonVisible() && event.keyCode && event.keyCode === 27) {
|
|
|
|
GroupList.toggleAddGroup();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-02-25 10:09:01 +00:00
|
|
|
// Responsible for Creating Groups.
|
|
|
|
$('#newgroup-form form').submit(function (event) {
|
2014-02-19 07:44:18 +00:00
|
|
|
event.preventDefault();
|
2014-02-25 14:22:20 +00:00
|
|
|
if(GroupList.isGroupNameValid($('#newgroupname').val())) {
|
|
|
|
GroupList.createGroup($('#newgroupname').val());
|
2014-02-19 07:44:18 +00:00
|
|
|
}
|
|
|
|
});
|
2014-02-25 13:05:48 +00:00
|
|
|
|
|
|
|
// click on group name
|
|
|
|
// FIXME: also triggered when clicking on "remove"
|
|
|
|
$('ul').on('click', 'li[data-gid]', function (event) {
|
|
|
|
var li = $(this);
|
|
|
|
var gid = $(li).attr('data-gid');
|
|
|
|
GroupList.showGroup(gid);
|
|
|
|
});
|
|
|
|
|
2014-02-19 07:44:18 +00:00
|
|
|
// Implements Groupname editing.
|
2014-02-22 21:28:44 +00:00
|
|
|
$('#app-navigation').on('click', 'img.rename', function (event) {
|
2014-02-19 07:44:18 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
var img = $(this);
|
|
|
|
var gid = img.parent().parent().attr('data-gid');
|
|
|
|
var groupname = escapeHTML(img.parent().parent().attr('data-gid'));
|
|
|
|
var input = $('<input type="text" value="' + groupname + '">');
|
|
|
|
img.css('display', 'none');
|
2014-02-22 21:28:44 +00:00
|
|
|
img.parent().children('span').replaceWith(input);
|
2014-02-19 07:44:18 +00:00
|
|
|
input.focus();
|
|
|
|
input.keypress(function (event) {
|
|
|
|
if (event.keyCode === 13) {
|
|
|
|
if ($(this).val().length > 0) {
|
|
|
|
$.post(
|
|
|
|
OC.filePath('settings', 'ajax', 'changegroupname.php'),
|
|
|
|
{ groupname: gid,
|
|
|
|
groupname: $(this).val()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
input.blur();
|
|
|
|
} else {
|
|
|
|
input.blur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
input.blur(function () {
|
|
|
|
var input = $(this), groupname = input.val();
|
|
|
|
input.closest('li').attr('data-gid', groupname);
|
2014-02-22 21:28:44 +00:00
|
|
|
input.replaceWith('<span>' + escapeHTML(groupname) + '</span>');
|
2014-02-19 07:44:18 +00:00
|
|
|
img.css('display', '');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-19 09:10:49 +00:00
|
|
|
// Implements Quota Settings Toggle.
|
2014-03-06 07:14:42 +00:00
|
|
|
$('#app-settings-header').on('click keydown',function(event) {
|
|
|
|
if(wrongKey(event)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var bodyListener = function(e) {
|
|
|
|
if($('#app-settings').find($(e.target)).length === 0) {
|
|
|
|
$('#app-settings').switchClass('open', '');
|
2014-02-26 20:31:50 +00:00
|
|
|
}
|
2014-03-06 07:14:42 +00:00
|
|
|
};
|
|
|
|
if($('#app-settings').hasClass('open')) {
|
|
|
|
$('#app-settings').switchClass('open', '');
|
|
|
|
$('body').unbind('click', bodyListener);
|
|
|
|
} else {
|
|
|
|
$('#app-settings').switchClass('', 'open');
|
|
|
|
$('body').bind('click', bodyListener);
|
|
|
|
}
|
2014-02-19 09:10:49 +00:00
|
|
|
});
|
2014-03-06 07:14:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var wrongKey = function(event) {
|
|
|
|
return ((event.type === 'keydown' || event.type === 'keypress')
|
|
|
|
&& (event.keyCode !== 32 && event.keyCode !== 13));
|
|
|
|
};
|