diff options
Diffstat (limited to 'settings/js/users')
-rw-r--r-- | settings/js/users/deleteHandler.js | 47 | ||||
-rw-r--r-- | settings/js/users/groups.js | 35 | ||||
-rw-r--r-- | settings/js/users/users.js | 110 |
3 files changed, 131 insertions, 61 deletions
diff --git a/settings/js/users/deleteHandler.js b/settings/js/users/deleteHandler.js index d4736d88701..c89a844044e 100644 --- a/settings/js/users/deleteHandler.js +++ b/settings/js/users/deleteHandler.js @@ -35,6 +35,16 @@ function DeleteHandler(endpoint, paramID, markCallback, removeCallback) { } /** + * Number of milliseconds after which the operation is performed. + */ +DeleteHandler.TIMEOUT_MS = 7000; + +/** + * Timer after which the action will be performed anyway. + */ +DeleteHandler.prototype._timeout = null; + +/** * The function to be called after successfully marking the object for deletion * @callback markCallback * @param {string} oid the ID of the specific user or group @@ -72,7 +82,9 @@ DeleteHandler.prototype.setNotification = function(notifier, dataID, message, un var dh = this; - $('#notification').on('click', '.undo', function () { + $('#notification') + .off('click.deleteHandler_' + dataID) + .on('click.deleteHandler_' + dataID, '.undo', function () { if ($('#notification').data(dh.notificationDataID)) { var oid = dh.oidToDelete; dh.cancel(); @@ -116,18 +128,36 @@ DeleteHandler.prototype.hideNotification = function() { */ DeleteHandler.prototype.mark = function(oid) { if(this.oidToDelete !== false) { - this.deleteEntry(); + // passing true to avoid hiding the notification + // twice and causing the second notification + // to disappear immediately + this.deleteEntry(true); } this.oidToDelete = oid; this.canceled = false; this.markCallback(oid); this.showNotification(); + if (this._timeout) { + clearTimeout(this._timeout); + this._timeout = null; + } + if (DeleteHandler.TIMEOUT_MS > 0) { + this._timeout = window.setTimeout( + _.bind(this.deleteEntry, this), + DeleteHandler.TIMEOUT_MS + ); + } }; /** * cancels a delete operation */ DeleteHandler.prototype.cancel = function() { + if (this._timeout) { + clearTimeout(this._timeout); + this._timeout = null; + } + this.canceled = true; this.oidToDelete = false; }; @@ -137,22 +167,31 @@ DeleteHandler.prototype.cancel = function() { * initialized by mark(). On error, it will show a message via * OC.dialogs.alert. On success, a callback is fired so that the client can * update the web interface accordingly. + * + * @param {boolean} [keepNotification] true to keep the notification, false to hide + * it, defaults to false */ -DeleteHandler.prototype.deleteEntry = function() { +DeleteHandler.prototype.deleteEntry = function(keepNotification) { if(this.canceled || this.oidToDelete === false) { return false; } var dh = this; - if($('#notification').data(this.notificationDataID) === true) { + if(!keepNotification && $('#notification').data(this.notificationDataID) === true) { dh.hideNotification(); } + if (this._timeout) { + clearTimeout(this._timeout); + this._timeout = null; + } + var payload = {}; payload[dh.ajaxParamID] = dh.oidToDelete; $.ajax({ type: 'POST', url: OC.filePath('settings', 'ajax', dh.ajaxEndpoint), + // FIXME: do not use synchronous ajax calls as they block the browser ! async: false, data: payload, success: function (result) { diff --git a/settings/js/users/groups.js b/settings/js/users/groups.js index fe06edff34d..081842734f0 100644 --- a/settings/js/users/groups.js +++ b/settings/js/users/groups.js @@ -251,12 +251,23 @@ GroupList = { getElementGID: function (element) { return ($(element).closest('li').data('gid') || '').toString(); + }, + getEveryoneCount: function () { + $.ajax({ + type: "GET", + dataType: "json", + url: OC.generateUrl('/settings/ajax/geteveryonecount') + }).success(function (data) { + $('#everyonegroup').data('usercount', data.count); + $('#everyonecount').text(data.count); + }); } }; $(document).ready( function () { $userGroupList = $('#usergrouplist'); GroupList.initDeleteHandling(); + GroupList.getEveryoneCount(); // Display or hide of Create Group List Element $('#newgroup-form').hide(); @@ -289,28 +300,4 @@ $(document).ready( function () { $userGroupList.on('click', '.isgroup', function () { GroupList.showGroup(GroupList.getElementGID(this)); }); - - // Implements Quota Settings Toggle. - var $appSettings = $('#app-settings'); - $('#app-settings-header').on('click keydown',function(event) { - if(wrongKey(event)) { - return; - } - if($appSettings.hasClass('open')) { - $appSettings.switchClass('open', ''); - } else { - $appSettings.switchClass('', 'open'); - } - }); - $('body').on('click', function(event){ - if($appSettings.find(event.target).length === 0) { - $appSettings.switchClass('open', ''); - } - }); - }); - -var wrongKey = function(event) { - return ((event.type === 'keydown' || event.type === 'keypress') && - (event.keyCode !== 32 && event.keyCode !== 13)); -}; diff --git a/settings/js/users/users.js b/settings/js/users/users.js index a94352e8e18..f39f8c2c064 100644 --- a/settings/js/users/users.js +++ b/settings/js/users/users.js @@ -18,6 +18,18 @@ var UserList = { usersToLoad: 10, //So many users will be loaded when user scrolls down currentGid: '', + /** + * Initializes the user list + * @param $el user list table element + */ + initialize: function($el) { + this.$el = $el; + + // initially the list might already contain user entries (not fully ajaxified yet) + // initialize these entries + this.$el.find('.quota-user').singleSelect().on('change', this.onQuotaSelect); + }, + add: function (username, displayname, groups, subadmin, quota, storageLocation, lastLogin, sort) { var $tr = $userListBody.find('tr:first-child').clone(); var subAdminsEl; @@ -84,9 +96,8 @@ var UserList = { var lastLoginRel = t('settings', 'never'); var lastLoginAbs = lastLoginRel; if(lastLogin !== 0) { - lastLogin = new Date(lastLogin * 1000); - lastLoginRel = relative_modified_date(lastLogin.getTime() / 1000); - lastLoginAbs = formatDate(lastLogin.getTime()); + lastLoginRel = OC.Util.relativeModifiedDate(lastLogin); + lastLoginAbs = OC.Util.formatDate(lastLogin); } var $tdLastLogin = $tr.find('td.lastLogin'); $tdLastLogin.text(lastLoginRel); @@ -109,15 +120,7 @@ var UserList = { UserList.doSort(); } - $quotaSelect.on('change', function () { - var uid = UserList.getUID(this); - var quota = $(this).val(); - setQuota(uid, quota, function(returnedQuota){ - if (quota !== returnedQuota) { - $($quotaSelect).find(':selected').text(returnedQuota); - } - }); - }); + $quotaSelect.on('change', UserList.onQuotaSelect); // defer init so the user first sees the list appear more quickly window.setTimeout(function(){ @@ -498,20 +501,41 @@ var UserList = { if (UserList.scrollArea.scrollTop() + UserList.scrollArea.height() > UserList.scrollArea.get(0).scrollHeight - 500) { UserList.update(UserList.currentGid, true); } - } -}; + }, -function setQuota (uid, quota, ready) { - $.post( - OC.filePath('settings', 'ajax', 'setquota.php'), - {username: uid, quota: quota}, - function (result) { - if (ready) { - ready(result.data.quota); + /** + * Event handler for when a quota has been changed through a single select. + * This will save the value. + */ + onQuotaSelect: function(ev) { + var $select = $(ev.target); + var uid = UserList.getUID($select); + var quota = $select.val(); + UserList._updateQuota(uid, quota, function(returnedQuota){ + if (quota !== returnedQuota) { + $select.find(':selected').text(returnedQuota); } - } - ); -} + }); + }, + + /** + * Saves the quota for the given user + * @param {String} [uid] optional user id, sets default quota if empty + * @param {String} quota quota value + * @param {Function} ready callback after save + */ + _updateQuota: function(uid, quota, ready) { + $.post( + OC.filePath('settings', 'ajax', 'setquota.php'), + {username: uid, quota: quota}, + function (result) { + if (ready) { + ready(result.data.quota); + } + } + ); + } +}; $(document).ready(function () { $userList = $('#userlist'); @@ -530,6 +554,9 @@ $(document).ready(function () { $userList.after($('<div class="loading" style="height: 200px; visibility: hidden;"></div>')); + // TODO: move other init calls inside of initialize + UserList.initialize($('#userlist')); + $('.groupsselect').each(function (index, element) { UserList.applyGroupSelect(element); }); @@ -613,15 +640,9 @@ $(document).ready(function () { }); }); - $('#default_quota, .quota-user').singleSelect().on('change', function () { - var $select = $(this); - var uid = UserList.getUID($select); - var quota = $select.val(); - setQuota(uid, quota, function(returnedQuota){ - if (quota !== returnedQuota) { - $select.find(':selected').text(returnedQuota); - } - }); + // init the quota field select box after it is shown the first time + $('#app-settings').one('show', function() { + $(this).find('#default_quota').singleSelect().on('change', UserList.onQuotaSelect); }); $('#newuser').submit(function (event) { @@ -688,4 +709,27 @@ $(document).ready(function () { ); }); + // Option to display/hide the "Storage location" column + $('#CheckboxStorageLocation').click(function() { + if ($('#CheckboxStorageLocation').is(':checked')) { + $("#headerStorageLocation").show(); + $("#userlist td.storageLocation").show(); + } else { + $("#headerStorageLocation").hide(); + $("#userlist td.storageLocation").hide(); + } + }); + // Option to display/hide the "Last Login" column + $('#CheckboxLastLogin').click(function() { + if ($('#CheckboxLastLogin').is(':checked')) { + $("#headerLastLogin").show(); + $("#userlist td.lastLogin").show(); + } else { + $("#headerLastLogin").hide(); + $("#userlist td.lastLogin").hide(); + } + }); + + + }); |