From 0a7e34f6c8c6e74bddfae7b6b3fd918a96c90695 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Wed, 18 Jul 2018 17:42:30 +0200 Subject: Popovermenu migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/js/core.json | 1 - core/js/merged-share-backend.json | 1 - core/js/sharedialognoteview.js | 149 ----------------------------------- core/js/sharedialogshareelistview.js | 90 ++++++++++++++++++++- core/js/sharedialogview.js | 10 +-- core/js/shareitemmodel.js | 13 +++ 6 files changed, 101 insertions(+), 163 deletions(-) delete mode 100644 core/js/sharedialognoteview.js (limited to 'core/js') diff --git a/core/js/core.json b/core/js/core.json index 6a6249c294b..502e3a57976 100644 --- a/core/js/core.json +++ b/core/js/core.json @@ -38,7 +38,6 @@ "shareitemmodel.js", "sharedialogview.js", "sharedialogexpirationview.js", - "sharedialognoteview.js", "sharedialoglinkshareview.js", "sharedialogresharerinfoview.js", "sharedialogshareelistview.js", diff --git a/core/js/merged-share-backend.json b/core/js/merged-share-backend.json index 48ad5d5340c..d39945b8f79 100644 --- a/core/js/merged-share-backend.json +++ b/core/js/merged-share-backend.json @@ -5,7 +5,6 @@ "sharedialogresharerinfoview.js", "sharedialoglinkshareview.js", "sharedialogexpirationview.js", - "sharedialognoteview.js", "sharedialogshareelistview.js", "sharedialogview.js", "share.js" diff --git a/core/js/sharedialognoteview.js b/core/js/sharedialognoteview.js deleted file mode 100644 index 429d9cd942b..00000000000 --- a/core/js/sharedialognoteview.js +++ /dev/null @@ -1,149 +0,0 @@ -/* - * @copyright Copyright (c) 2018 John Molakvoæ - * - * @author John Molakvoæ - * - * @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 . - * - */ - -/* global moment, Handlebars */ - -(function() { - if (!OC.Share) { - OC.Share = {}; - } - - var TEMPLATE = - '
' + - ' ' + - ' ' + - '
' + - ' ' - ; - - /** - * @class OCA.Share.ShareDialogNoteView - * @member {OC.Share.ShareItemModel} model - * @member {jQuery} $el - * @memberof OCA.Sharing - * @classdesc - * - * Represents the expiration part in the GUI of the share dialogue - * - */ - var ShareDialogNoteView = OC.Backbone.View.extend({ - - id: 'shareNote', - - className: 'hidden', - - shareId: undefined, - - events: { - 'submit #newNoteForm': '_onSubmitComment' - }, - - _onSubmitComment: function(e) { - var self = this; - var $form = $(e.target); - var $submit = $form.find('.submit'); - var $commentField = $form.find('.message'); - var $error = $form.siblings('.error'); - var message = $commentField.val().trim(); - e.preventDefault(); - - if (message.length < 1) { - return; - } - - $submit.prop('disabled', true); - $form.addClass('icon-loading').prop('disabled', true); - - // send data - $.ajax({ - method: 'PUT', - url: OC.generateUrl('/ocs/v2.php/apps/files_sharing/api/v1/shares/' + self.shareId), - data: { note: message }, - complete : function() { - $submit.prop('disabled', false); - $form.removeClass('icon-loading').prop('disabled', false); - }, - error: function() { - $error.show(); - setTimeout(function() { - $error.hide(); - }, 3000); - } - }); - - // update local js object - var shares = this.model.get('shares'); - var share = shares.filter(function (share) { - return share.id === self.shareId; - }); - share[0].note = message; - - return message; - }, - - render: function(shareId) { - this.shareId = shareId; - var shares = this.model.get('shares'); - if (!shares) { - return; - } - var share = shares.filter(function (share) { - return share.id === shareId; - }); - if (share.length !== 1) { - // should not happend - return; - } - this.$el.show(); - this.$el.html(this.template({ - note: share[0].note, - submitText: t('core', 'Submit the note'), - placeholder: t('core', 'Add a note…'), - error: t('core', 'An error has occured. Unable to save the note.'), - shareId: shareId - })); - - this.delegateEvents(); - - return this; - }, - - hide() { - this.$el.hide(); - }, - - /** - * @returns {Function} from Handlebars - * @private - */ - template: function (data) { - if (!this._template) { - this._template = Handlebars.compile(TEMPLATE); - } - return this._template(data); - } - - }); - - OC.Share.ShareDialogNoteView = ShareDialogNoteView; - -})(); diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js index af4abce17b6..2f561aa66ee 100644 --- a/core/js/sharedialogshareelistview.js +++ b/core/js/sharedialogshareelistview.js @@ -121,7 +121,17 @@ '' + '' + '
  • ' + - '{{addNoteLabel}}' + + '' + + '
  • ' + + '' + '
  • ' + '{{unshareLabel}}' + @@ -161,7 +171,9 @@ events: { 'click .unshare': 'onUnshare', - 'click .addnote': 'showNoteForm', + 'click .share-add': 'showNoteForm', + 'click .share-note-delete': 'deleteNote', + 'click .share-note-submit': 'updateNote', 'click .icon-more': 'onToggleMenu', 'click .permissions': 'onPermissionChange', 'click .expireDate' : 'onExpireDateChange', @@ -269,6 +281,7 @@ isPasswordSet: hasPassword, secureDropMode: !this.model.hasReadPermission(shareIndex), hasExpireDate: this.model.getExpireDate(shareIndex) !== null, + shareNote: this.model.getNote(shareIndex), expireDate: moment(this.model.getExpireDate(shareIndex), 'YYYY-MM-DD').format('DD-MM-YYYY'), passwordPlaceholder: hasPassword ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE, }); @@ -486,7 +499,78 @@ var $element = $(event.target); var $li = $element.closest('li[data-share-id]'); var shareId = $li.data('share-id'); - this._noteView.render(shareId); + var $menu = $element.closest('li'); + var $form = $menu.next('li.share-note-form'); + + // show elements + $menu.find('.share-note-delete').toggle(); + $form.toggleClass('hidden'); + }, + + deleteNote(event) { + event.preventDefault(); + event.stopPropagation(); + var self = this; + var $element = $(event.target); + var $li = $element.closest('li[data-share-id]'); + var shareId = $li.data('share-id'); + var $menu = $element.closest('li'); + var $form = $menu.next('li.share-note-form'); + + console.log($form.find('.share-note')); + $form.find('.share-note').val(''); + + self.sendNote('', shareId, $menu); + }, + + updateNote(event) { + event.preventDefault(); + event.stopPropagation(); + var self = this; + var $element = $(event.target); + var $li = $element.closest('li[data-share-id]'); + var shareId = $li.data('share-id'); + var $form = $element.closest('li.share-note-form'); + var $menu = $form.prev('li'); + var message = $form.find('.share-note').val().trim(); + + if (message.length < 1) { + return; + } + + self.sendNote(message, shareId, $menu); + + }, + + sendNote(note, shareId, $menu) { + var $form = $menu.next('li.share-note-form'); + var $submit = $form.find('input.share-note-submit'); + var $error = $form.find('input.share-note-error'); + + $submit.prop('disabled', true); + $menu.find('.icon-loading-small').removeClass('hidden'); + $menu.find('.icon-edit').hide(); + + var complete = function() { + $submit.prop('disabled', false); + $menu.find('.icon-loading-small').addClass('hidden'); + $menu.find('.icon-edit').show(); + }; + var error = function() { + $error.show(); + setTimeout(function() { + $error.hide(); + }, 3000); + }; + + // send data + $.ajax({ + method: 'PUT', + url: OC.generateUrl('/ocs/v2.php/apps/files_sharing/api/v1/shares/' + shareId), + data: { note: note }, + complete : complete, + error: error + }); }, onUnshare: function(event) { diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 4b5dc80e945..b69bc5026c3 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -28,7 +28,6 @@ '
    ' + '
    ' + '
    ' + - '
    ' + ''; /** @@ -62,10 +61,7 @@ /** @type {object} **/ expirationView: undefined, - - /** @type {object} **/ - noteView: undefined, - + /** @type {object} **/ shareeListView: undefined, @@ -117,7 +113,6 @@ resharerInfoView: 'ShareDialogResharerInfoView', linkShareView: 'ShareDialogLinkShareView', expirationView: 'ShareDialogExpirationView', - noteView: 'ShareDialogNoteView', shareeListView: 'ShareDialogShareeListView' }; @@ -680,9 +675,6 @@ this.expirationView.$el = this.$el.find('.expirationView'); this.expirationView.render(); - this.noteView.$el = this.$el.find('.noteView'); - this.noteView.render(); - this.shareeListView.$el = this.$el.find('.shareeListView'); this.shareeListView.render(); diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 93feba9c889..68e55443dd2 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -366,6 +366,10 @@ return this._shareExpireDate(shareIndex); }, + getNote: function(shareIndex) { + return this._shareNote(shareIndex); + }, + /** * Returns all share entries that only apply to the current item * (file/folder) @@ -502,6 +506,15 @@ return date2; }, + + _shareNote: function(shareIndex) { + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } + return share.note; + }, + /** * @return {int} */ -- cgit v1.2.3