summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-07-18 17:42:30 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-07-21 15:02:20 +0200
commit0a7e34f6c8c6e74bddfae7b6b3fd918a96c90695 (patch)
tree67431dfc89a92831f709815b0906d634d2b7b2fc /core/js
parentfa44300016424d5f2994bd37d13184fe13b700e2 (diff)
downloadnextcloud-server-0a7e34f6c8c6e74bddfae7b6b3fd918a96c90695.tar.gz
nextcloud-server-0a7e34f6c8c6e74bddfae7b6b3fd918a96c90695.zip
Popovermenu migration
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'core/js')
-rw-r--r--core/js/core.json1
-rw-r--r--core/js/merged-share-backend.json1
-rw-r--r--core/js/sharedialognoteview.js149
-rw-r--r--core/js/sharedialogshareelistview.js90
-rw-r--r--core/js/sharedialogview.js10
-rw-r--r--core/js/shareitemmodel.js13
6 files changed, 101 insertions, 163 deletions
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æ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @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/>.
- *
- */
-
-/* global moment, Handlebars */
-
-(function() {
- if (!OC.Share) {
- OC.Share = {};
- }
-
- var TEMPLATE =
- ' <form id="newNoteForm" data-shareId="{{shareId}}">' +
- ' <textarea class="message" placeholder="{{placeholder}}">{{note}}</textarea>' +
- ' <input class="submit icon-confirm has-tooltip" type="submit" value="" title="{{submitText}}"/>' +
- ' </form>' +
- ' <div class="error hidden">{{error}}</div>'
- ;
-
- /**
- * @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 @@
'</span>' +
'</li>' +
'<li>' +
- '<a href="#" class="addnote"><span class="icon-loading-small hidden"></span><span class="icon icon-edit"></span><span>{{addNoteLabel}}</span></a>' +
+ '<a href="#" class="share-add"><span class="icon-loading-small hidden"></span>' +
+ ' <span class="icon icon-edit"></span>' +
+ ' <span>{{addNoteLabel}}</span>' +
+ ' <input type="button" class="share-note-delete icon-delete">' +
+ '</a>' +
+ '</li>' +
+ '<li class="share-note-form hidden">' +
+ '<span class="menuitem icon-note">' +
+ ' <textarea class="share-note">{{shareNote}}</textarea>' +
+ ' <input type="submit" class="icon-confirm share-note-submit" value="" id="add-note-{{shareId}}" />' +
+ '</span>' +
'</li>' +
'<li>' +
'<a href="#" class="unshare"><span class="icon-loading-small hidden"></span><span class="icon icon-delete"></span><span>{{unshareLabel}}</span></a>' +
@@ -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 @@
'<div class="shareeListView subView"></div>' +
'<div class="linkShareView subView"></div>' +
'<div class="expirationView subView"></div>' +
- '<div class="noteView subView"></div>' +
'<div class="loading hidden" style="height: 50px"></div>';
/**
@@ -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}
*/