diff options
Diffstat (limited to 'js/admin.js')
-rw-r--r-- | js/admin.js | 178 |
1 files changed, 0 insertions, 178 deletions
diff --git a/js/admin.js b/js/admin.js deleted file mode 100644 index 48c851e..0000000 --- a/js/admin.js +++ /dev/null @@ -1,178 +0,0 @@ -/** - * @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -(function() { - if (!OCA.File_Retention) { - /** - * @namespace - */ - OCA.File_Retention = {}; - } - - OCA.File_Retention.Admin = { - - tagCollection: null, - - collection: null, - view: null, - - currentTagId: null, - - notifyCheckbox: null, - - init: function() { - var self = this; - - this.tagCollection = OC.SystemTags.collection; - var loadingTags = this.tagCollection.fetch({ - success: function() { - $('#retention_tag').select2(_.extend(self.select2)); - } - }); - - this.collection = new OCA.File_Retention.RetentionCollection(); - var loadingRetentions = this.collection.fetch(); - - $.when(loadingTags, loadingRetentions).done(function () { - self.view = new OCA.File_Retention.RetentionView({ - collection: self.collection, - tagCollection: self.tagCollection - }); - - self.view.render(); - }); - - $('#retention_submit').on('click', _.bind(this._onClickSubmit, this)); - - this.notifyCheckbox = $('#retention_notify'); - this.notifyCheckbox.prop('checked', OCP.InitialState.loadState('files_retention', 'notify_before')); - this.notifyCheckbox.change(function() { - OCP.AppConfig.setValue('files_retention', 'notify_before', $(this).is(":checked") ? 'yes' : 'no') - }); - }, - - /** - * Selecting a systemtag in select2 - * - * @param {OC.SystemTags.SystemTagModel} tag - */ - onSelectTag: function (tag) { - this.currentTagId = parseInt(tag.id, 10); - - $('#retention_submit').prop('disabled', false); - }, - - /** - * Clicking the Create button - */ - _onClickSubmit: function () { - var $el = $('#retention_amount'); - var amount = $el.val(); - if (!/^\d+$/.test(amount)) { - $el.tooltip({ - title: t('files_retention', 'Not a number'), - placement: 'bottom', - trigger: 'manual' - }) - .tooltip('show'); - return; - } - $el.tooltip('hide'); - - var after = parseInt($('#retention_after').val(), 10); - var unit = parseInt($('#retention_unit').val(), 10); - amount = parseInt(amount, 10); - - if (isNaN(amount)) { - amount = 10; - } - - this.collection.create({ - tagid: this.currentTagId, - timeunit: unit, - timeamount: amount, - timeafter: after, - }, { - success: function () { - OC.Notification.showTemporary(t('files_retention', 'Retention rule saved'), {type: 'success'}); - }, - error: function (_, xhr) { - OC.Notification.showTemporary(t('files_retention', 'An error occurred while trying to save the retention rule'), {type: 'error'}); - console.error(xhr) - } - }); - - $('#retention_submit').prop('disabled', true); - $('#retention_tag').select2('val', ''); - this.view.render(); - }, - - /** - * Select2 options for the SystemTag dropdown - */ - select2: { - allowClear: false, - multiple: false, - placeholder: t('files_retention', 'Select tag…'), - query: _.debounce(function(query) { - // Filter tag list by search - var tags = OCA.File_Retention.Admin.tagCollection.filterByName(query.term); - - // Get all the tags already in used for retention rules - var usedTagIds = OCA.File_Retention.Admin.collection.map(function(retention) { - return retention.attributes.tagid; - }); - - // Filter tag list by tags already in use - tags = tags.filter(function(tag) { - return $.inArray(parseInt(tag.id, 10), usedTagIds) === -1; - }); - - query.callback({ - results: tags - }); - }, 100, true), - id: function(element) { - return element; - }, - initSelection: function(element, callback) { - var selection = ($(element).val() || []).split('|').sort(); - callback(selection); - }, - formatResult: function (tag) { - return OC.SystemTags.getDescriptiveTag(tag); - }, - formatSelection: function (tag) { - OCA.File_Retention.Admin.onSelectTag(tag); - return OC.SystemTags.getDescriptiveTag(tag); - }, - escapeMarkup: function(m) { - return m; - } - } - }; -})(); - -$(document).ready(function() { - OCA.File_Retention.Admin.init(); -}); - |