diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2017-03-02 14:12:13 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-03-03 10:19:41 +0100 |
commit | a85327fe87ce471b04a14839e7b7b7dae4298753 (patch) | |
tree | 63ea7084a532b88ae7bdaf716acf1346c65dbc54 | |
parent | 8e9b119c5f5fdb574f2e2e2284fd506ed2257629 (diff) | |
download | nextcloud-server-a85327fe87ce471b04a14839e7b7b7dae4298753.tar.gz nextcloud-server-a85327fe87ce471b04a14839e7b7b7dae4298753.zip |
Add social sharing
* Add socialshare manager
* Add social share field under link share
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r-- | core/js/sharedialoglinksocialview.js | 132 | ||||
-rw-r--r-- | core/js/sharedialogview.js | 10 | ||||
-rw-r--r-- | core/js/sharesocialmanager.js | 53 | ||||
-rw-r--r-- | lib/private/Share/Share.php | 2 |
4 files changed, 196 insertions, 1 deletions
diff --git a/core/js/sharedialoglinksocialview.js b/core/js/sharedialoglinksocialview.js new file mode 100644 index 00000000000..1cd8d91bc7a --- /dev/null +++ b/core/js/sharedialoglinksocialview.js @@ -0,0 +1,132 @@ +/** + * @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 (!OC.Share) { + OC.Share = {}; + } + + var TEMPLATE = + '<button class="icon {{iconClass}} pop-up hasTooltip"' + + ' title="{{shareToolTip}}"' + + ' data-url="{{url}}"></button>' + ; + + /** + * @class OCA.Share.ShareDialogLinkSocialView + * @member {OC.Share.ShareItemModel} model + * @member {jQuery} $el + * @memberof OCA.Sharing + * @classdesc + * + * Represents the GUI of the share dialogue + * + */ + var ShareDialogLinkSocialView = OC.Backbone.View.extend({ + /** @type {string} **/ + id: 'shareDialogLinkSocialView', + + /** @type {OC.Share.ShareConfigModel} **/ + configModel: undefined, + + /** @type {Function} **/ + _template: undefined, + + /** @type {boolean} **/ + showLink: true, + + events: { + 'click .pop-up': 'onPopUpClick' + }, + + initialize: function(options) { + var view = this; + + this.model.on('change:linkShare', function() { + view.render(); + }); + + if(!_.isUndefined(options.configModel)) { + this.configModel = options.configModel; + } else { + throw 'missing OC.Share.ShareConfigModel'; + } + }, + + onPopUpClick: function(event) { + var url = $(event.target).data('url'); + $(event.target).tooltip('hide'); + if (url) { + var width = 600; + var height = 400; + var left = (screen.width/2)-(width/2); + var top = (screen.height/2)-(height/2); + + window.open(url, 'name', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left); + } + }, + + render: function() { + var isLinkShare = this.model.get('linkShare').isLinkShare; + if (isLinkShare && OC.Share.Social.Collection.size() > 0) { + var linkShareTemplate = this.template(); + var link = this.model.get('linkShare').link; + + var html = ''; + + OC.Share.Social.Collection.each(function(model) { + var url = model.get('url'); + url = url.replace('{{reference}}', link); + + html += linkShareTemplate({ + url: url, + shareToolTip: t('core', 'Share to {name}', {name: model.get('name')}), + iconClass: model.get('iconClass') + }); + }); + + this.$el.html(html); + this.$el.show(); + } else { + this.$el.hide(); + } + + this.delegateEvents(); + + return this; + }, + + /** + * @returns {Function} from Handlebars + * @private + */ + template: function () { + if (!this._template) { + this._template = Handlebars.compile(TEMPLATE); + } + return this._template; + } + + }); + + OC.Share.ShareDialogLinkSocialView = ShareDialogLinkSocialView; +})(); diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index a63960da2b8..ed887dfb716 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -28,6 +28,7 @@ '<div class="shareeListView subView"></div>' + '<div class="linkShareView subView"></div>' + '<div class="expirationView subView"></div>' + + '<div class="socialView subView"></div>' + '<div class="loading hidden" style="height: 50px"></div>'; var TEMPLATE_REMOTE_SHARE_INFO = @@ -69,6 +70,9 @@ /** @type {object} **/ shareeListView: undefined, + /** @type OC.Share.ShareDialogLinkSocialView **/ + socalView: undefined, + events: { 'input .shareWithField': 'onShareWithFieldChanged' }, @@ -105,7 +109,8 @@ resharerInfoView: 'ShareDialogResharerInfoView', linkShareView: 'ShareDialogLinkShareView', expirationView: 'ShareDialogExpirationView', - shareeListView: 'ShareDialogShareeListView' + shareeListView: 'ShareDialogShareeListView', + socialView: 'ShareDialogLinkSocialView' }; for(var name in subViews) { @@ -421,6 +426,9 @@ this.shareeListView.$el = this.$el.find('.shareeListView'); this.shareeListView.render(); + this.socialView.$el = this.$('.socialView'); + this.socialView.render(); + this.$el.find('.hasTooltip').tooltip(); return this; diff --git a/core/js/sharesocialmanager.js b/core/js/sharesocialmanager.js new file mode 100644 index 00000000000..c1db48dda62 --- /dev/null +++ b/core/js/sharesocialmanager.js @@ -0,0 +1,53 @@ +/** + * @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 (!OC.Share) { + OC.Share = {}; + } + + OC.Share.Social = {}; + + var SocialModel = OC.Backbone.Model.extend({ + defaults: { + /** used for sorting social buttons */ + key: null, + /** url to open, {{reference}} will be replaced with the link */ + url: null, + /** Name to show in the tooltip */ + name: null, + /** Icon class to display */ + iconClass: null + } + }); + + OC.Share.Social.Model = SocialModel; + + var SocialCollection = OC.Backbone.Collection.extend({ + model: OC.Share.Social.Model, + + comparator: 'key' + }); + + + OC.Share.Social.Collection = new SocialCollection; +})(); diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 6abaa7dd413..c693af02a50 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -94,8 +94,10 @@ class Share extends Constants { if(count(self::$backendTypes) === 1) { \OC_Util::addScript('core', 'shareconfigmodel'); \OC_Util::addScript('core', 'shareitemmodel'); + \OC_Util::addScript('core', 'sharesocialmanager'); \OC_Util::addScript('core', 'sharedialogresharerinfoview'); \OC_Util::addScript('core', 'sharedialoglinkshareview'); + \OC_Util::addScript('core', 'sharedialoglinksocialview'); \OC_Util::addScript('core', 'sharedialogexpirationview'); \OC_Util::addScript('core', 'sharedialogshareelistview'); \OC_Util::addScript('core', 'sharedialogview'); |