2014-02-19 11:44:18 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014, Raghu Nayyar <beingminimal@gmail.com>
|
2014-03-06 11:05:44 +04:00
|
|
|
* Copyright (c) 2014, Arthur Schiwon <blizzz@owncloud.com>
|
2014-02-19 11:44:18 +04:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var GroupList = {
|
2014-02-25 18:22:20 +04:00
|
|
|
addGroup: function(gid) {
|
|
|
|
var li = $('li[data-gid]').last().clone();
|
|
|
|
var ul = $('li[data-gid]').first().parent();
|
|
|
|
li.attr('data-gid', gid);
|
|
|
|
li.attr('data-usercount', 0);
|
|
|
|
li.find('a span').first().text(gid);
|
|
|
|
li.find('span[class=usercount]').first().text('');
|
|
|
|
|
|
|
|
$(li).appendTo(ul);
|
|
|
|
|
|
|
|
GroupList.sortGroups(0);
|
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
GroupList.toggleAddGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
2014-02-19 11:44:18 +04:00
|
|
|
|
2014-02-25 18:41:03 +04:00
|
|
|
elementBelongsToAddGroup: function(el) {
|
|
|
|
return !(el !== $('#newgroup-form').get(0)
|
|
|
|
&& $('#newgroup-form').find($(el)).length === 0);
|
|
|
|
},
|
|
|
|
|
2014-02-25 19:11:20 +04:00
|
|
|
hasAddGroupNameText: function() {
|
|
|
|
name = $('#newgroupname').val();
|
|
|
|
if($.trim(name) === '') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2014-02-19 14:40:07 +04:00
|
|
|
showGroup: function (gid) {
|
|
|
|
UserList.empty();
|
|
|
|
UserList.update(gid);
|
2014-02-20 22:11:52 +04: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 14:40:07 +04:00
|
|
|
},
|
|
|
|
|
2014-02-25 18:41:03 +04:00
|
|
|
isAddGroupButtonVisible: function() {
|
|
|
|
return $('#newgroup-init').is(":visible");
|
|
|
|
},
|
|
|
|
|
2014-02-25 17:26:35 +04:00
|
|
|
toggleAddGroup: function(event) {
|
2014-02-25 18:41:03 +04:00
|
|
|
if(GroupList.isAddGroupButtonVisible()) {
|
2014-02-25 17:26:35 +04:00
|
|
|
event.stopPropagation();
|
|
|
|
$('#newgroup-form').show();
|
|
|
|
$('#newgroup-init').hide();
|
|
|
|
$('#newgroupname').focus();
|
|
|
|
} else {
|
|
|
|
$('#newgroup-form').hide();
|
|
|
|
$('#newgroup-init').show();
|
|
|
|
$('#newgroupname').val('');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-25 18:22:20 +04: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 21:04:55 +04: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();
|
|
|
|
},
|
|
|
|
initDeleteHandling: function() {
|
|
|
|
//set up handler
|
|
|
|
GroupDeleteHandler = new DeleteHandler('removegroup.php', 'groupname',
|
|
|
|
GroupList.hide, GroupList.remove);
|
|
|
|
|
|
|
|
//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 11:44:18 +04:00
|
|
|
|
2014-02-26 21:04:55 +04:00
|
|
|
console.log('init del groups');
|
|
|
|
//delete a marked user when leaving the page
|
|
|
|
$(window).on('beforeunload', function () {
|
|
|
|
GroupDeleteHandler.delete();
|
|
|
|
});
|
2014-02-19 11:44:18 +04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready( function () {
|
2014-02-26 21:04:55 +04:00
|
|
|
GroupList.initDeleteHandling();
|
2014-02-25 14:09:01 +04:00
|
|
|
|
|
|
|
// Display or hide of Create Group List Element
|
|
|
|
$('#newgroup-form').hide();
|
|
|
|
$('#newgroup-init').on('click', function (e) {
|
2014-02-25 17:26:35 +04:00
|
|
|
GroupList.toggleAddGroup(e);
|
2014-02-25 14:09:01 +04:00
|
|
|
});
|
|
|
|
|
2014-02-25 18:41:03 +04:00
|
|
|
$(document).on('click keydown keyup', function(event) {
|
|
|
|
if(!GroupList.isAddGroupButtonVisible()
|
2014-02-25 19:11:20 +04:00
|
|
|
&& !GroupList.elementBelongsToAddGroup(event.target)
|
|
|
|
&& !GroupList.hasAddGroupNameText()) {
|
2014-02-25 18:41:03 +04:00
|
|
|
GroupList.toggleAddGroup();
|
|
|
|
}
|
|
|
|
// Escape
|
|
|
|
if(!GroupList.isAddGroupButtonVisible() && event.keyCode && event.keyCode === 27) {
|
|
|
|
GroupList.toggleAddGroup();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-02-25 14:09:01 +04:00
|
|
|
// Responsible for Creating Groups.
|
|
|
|
$('#newgroup-form form').submit(function (event) {
|
2014-02-19 11:44:18 +04:00
|
|
|
event.preventDefault();
|
2014-02-25 18:22:20 +04:00
|
|
|
if(GroupList.isGroupNameValid($('#newgroupname').val())) {
|
|
|
|
GroupList.createGroup($('#newgroupname').val());
|
2014-02-19 11:44:18 +04:00
|
|
|
}
|
|
|
|
});
|
2014-02-25 17:05:48 +04: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 11:44:18 +04:00
|
|
|
// Implements Groupname editing.
|
2014-02-23 01:28:44 +04:00
|
|
|
$('#app-navigation').on('click', 'img.rename', function (event) {
|
2014-02-19 11:44:18 +04: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-23 01:28:44 +04:00
|
|
|
img.parent().children('span').replaceWith(input);
|
2014-02-19 11:44:18 +04: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-23 01:28:44 +04:00
|
|
|
input.replaceWith('<span>' + escapeHTML(groupname) + '</span>');
|
2014-02-19 11:44:18 +04:00
|
|
|
img.css('display', '');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-19 13:10:49 +04:00
|
|
|
// Implements Quota Settings Toggle.
|
2014-03-06 11:14:42 +04: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-27 00:31:50 +04:00
|
|
|
}
|
2014-03-06 11:14:42 +04: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 13:10:49 +04:00
|
|
|
});
|
2014-03-06 11:14:42 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
var wrongKey = function(event) {
|
|
|
|
return ((event.type === 'keydown' || event.type === 'keypress')
|
|
|
|
&& (event.keyCode !== 32 && event.keyCode !== 13));
|
|
|
|
};
|